pep8
[django-migdal.git] / migdal / api.py
1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from migdal.models import Entry
6 from migdal import app_settings
7 from django.utils.translation import get_language
8
9
10 def entry_list(entry_type=None, category=None, promobox=False, for_feed=False):
11     lang = get_language()
12     object_list = Entry.objects.filter(**{"published_%s" % lang: True})
13
14     if for_feed:
15         object_list = object_list.order_by('-published_at_%s' % lang)
16     else:
17         object_list = object_list.order_by('-first_published_at')
18
19     if entry_type:
20         object_list = object_list.filter(type=entry_type.db)
21     else:
22         object_list = object_list.filter(
23             type__in=[t.db for t in app_settings.TYPES if t.on_main])
24     if category:
25         object_list = object_list.filter(categories=category)
26
27     object_list = object_list.filter(in_stream=True)
28
29     if promobox:
30         promo = list(object_list.filter(promo=True)[:promobox])
31         # object_list = object_list.exclude(pk__in=[p.pk for p in promo])
32         object_list.promobox = promo
33
34     return object_list