Files
tripwithbonus/ArticlesApp/funcs.py
SDE c781453055 0.7.53
articles page
2023-10-05 19:27:57 +03:00

36 lines
813 B
Python

from .models import *
def get_articles(art_kwargs, request_Data=None, from_el=None, to_el=None):
if request_Data:
if not from_el and 'from_el' in request_Data:
from_el = request_Data['from_el']
if not to_el and 'to_el' in request_Data:
to_el = request_Data['to_el']
arts = ArticleModel.objects.filter(**art_kwargs).order_by('-createDT')
el_count = arts.count()
if from_el and to_el:
arts = arts[from_el:to_el]
elif from_el:
arts = arts[from_el:]
elif to_el:
arts = arts[:to_el]
else:
to_el = 3
arts = arts[:to_el]
last_block = False
if not to_el or to_el >= el_count:
last_block = True
Dict = {
'articles': arts,
'last_block': last_block
}
return Dict