0.7.52
articles page
This commit is contained in:
35
ArticlesApp/funcs.py
Normal file
35
ArticlesApp/funcs.py
Normal file
@@ -0,0 +1,35 @@
|
||||
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[:3]
|
||||
|
||||
last_block = False
|
||||
if not to_el or to_el >= el_count:
|
||||
last_block = True
|
||||
|
||||
Dict = {
|
||||
'articles': arts,
|
||||
'last_block': last_block
|
||||
}
|
||||
|
||||
return Dict
|
||||
Reference in New Issue
Block a user