X-Git-Url: https://git.mdrn.pl/django-migdal.git/blobdiff_plain/734cd58d3f12c5397b42c1ae122c947500386014..05d1be6e85dc92e7be6aebb8b62221480c10540e:/migdal/api.py?ds=inline diff --git a/migdal/api.py b/migdal/api.py index d4f031e..fd89352 100644 --- a/migdal/api.py +++ b/migdal/api.py @@ -2,16 +2,20 @@ # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # -from itertools import chain from migdal.models import Entry from migdal import app_settings from django.utils.translation import get_language -def entry_list(entry_type=None, category=None, promobox=False): +def entry_list(entry_type=None, category=None, promobox=False, for_feed=False): lang = get_language() - object_list = Entry.objects.filter(**{"published_%s" % lang: True} - ).order_by('-published_at_%s' % lang) + object_list = Entry.objects.filter(**{"published_%s" % lang: True}) + + if for_feed: + object_list = object_list.order_by('-published_at_%s' % lang) + else: + object_list = object_list.order_by('-first_published_at') + if entry_type: object_list = object_list.filter(type=entry_type.db) else: @@ -20,9 +24,11 @@ def entry_list(entry_type=None, category=None, promobox=False): if category: object_list = object_list.filter(categories=category) + object_list = object_list.filter(in_stream=True) + if promobox: promo = list(object_list.filter(promo=True)[:promobox]) - #object_list = object_list.exclude(pk__in=[p.pk for p in promo]) + # object_list = object_list.exclude(pk__in=[p.pk for p in promo]) object_list.promobox = promo return object_list