Files
account_store/ArticlesApp/funcs.py
SDE 32f65de458 0.7.54
articles paging
2023-10-05 19:42:13 +03:00

37 lines
839 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,
'last_el': to_el
}
return Dict