Files
account_store/ArticlesApp/funcs.py
2023-11-29 20:06:33 +03:00

46 lines
1.1 KiB
Python

from .models import *
elements_on_page = 10
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 = elements_on_page
arts = arts[:to_el]
last_block = False
if not to_el or to_el >= el_count:
last_block = True
if el_count - to_el > elements_on_page:
next_page_els_count = elements_on_page
else:
next_page_els_count = el_count - to_el
Dict = {
'articles': arts,
'last_block': last_block,
'last_el': to_el,
'next_page_els_count': next_page_els_count,
'elements_on_page': elements_on_page
}
return Dict