fixes #2360: allow empty slugs for non-published entries
[prawokultury.git] / migdal / feeds.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 django.contrib.syndication.views import Feed
6 from django.core.urlresolvers import reverse
7 from django.shortcuts import get_object_or_404
8 from django.utils.translation import ugettext as _
9 from migdal import api
10 from migdal.models import Category
11 from migdal.settings import TYPES_DICT
12
13
14 class EntriesFeed(Feed):
15     def get_object(self, request, type_db=None, category_slug=None):
16         lang = request.LANGUAGE_CODE
17         if category_slug:
18             category = get_object_or_404(Category, **{'slug_%s' % lang: category_slug})
19         else:
20             category = None
21         if type_db:
22             entry_type = TYPES_DICT[type_db]
23         else:
24             entry_type = None
25         return {'entry_type': entry_type, 'category': category}
26
27     def title(self, obj):
28         t = "Prawo kultury, " + _("latest") + " "
29         if obj['entry_type']:
30             t += unicode(obj['entry_type'].slug)
31         else:
32             t += _("entries")
33         if obj['category']:
34             t += " " + _("in category") + " " + obj['category'].title
35         return t
36
37     def link(self, obj):
38         if obj['category']:
39             return reverse('migdal_category', args=[obj['category'].slug])
40         if obj['entry_type']:
41             return reverse('migdal_entry_list_%s' % obj['entry_type'].db)
42         return reverse('migdal_main')
43
44     def items(self, obj):
45         return api.entry_list(**obj)
46
47     def item_title(self, item):
48         return item.title
49
50     def item_description(self, item):
51         return item.lead