6f81a4dd2f78597b47849bbef49d4568da22f2ce
[prawokultury.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 itertools import chain
6 from migdal.models import Entry
7 from migdal.settings import TYPES
8 from django.utils.translation import get_language
9
10
11 def entry_list(entry_type=None, category=None, promobox=False):
12     lang = get_language()
13     object_list = Entry.objects.filter(**{"published_%s" % lang: True}
14         ).order_by('-published_at_%s' % lang)
15     if entry_type:
16         object_list = object_list.filter(type=entry_type.db)
17     else:
18         object_list = object_list.filter(type__in=[t.db for t in TYPES if t.on_main])
19     if category:
20         object_list = object_list.filter(categories=category)
21
22     if promobox:
23         promo = list(object_list.filter(promo=True)[:promobox])
24         #object_list = object_list.exclude(pk__in=[p.pk for p in promo])
25         object_list.promobox = promo
26
27     return object_list