1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.contrib.sites.models import Site
6 from django.contrib.syndication.views import Feed
7 from django.core.urlresolvers import reverse
9 from catalogue import models
12 def absolute_url(url):
13 return "http://%s%s" % (Site.objects.get_current().domain, url)
16 class AudiobookFeed(Feed):
17 description = "Audiobooki ostatnio dodane do serwisu Wolne Lektury."
22 'daisy': 'application/zip',
26 'all': 'WolneLektury.pl - audiobooki we wszystkich formatach',
27 'mp3': 'WolneLektury.pl - audiobooki w formacie MP3',
28 'ogg': 'WolneLektury.pl - audiobooki w formacie Ogg Vorbis',
29 'daisy': 'WolneLektury.pl - audiobooki w formacie DAISY',
32 def get_object(self, request, type):
33 return {'type': type, 'all': 'all' in request.GET}
35 def title(self, args):
36 return self.titles[args['type']]
39 return reverse('audiobook_feed', args=(args['type'],))
41 def items(self, args):
42 objects = models.BookMedia.objects.order_by('-uploaded_at')
44 objects = objects.filter(type__in=('mp3', 'ogg', 'daisy'))
46 objects = objects.filter(type=args['type'])
48 objects = objects[:50]
51 def item_title(self, item):
54 def item_categories(self, item):
55 return sorted(set(author.name for author in
56 item.book.tags.filter(category='author').iterator()))
58 def item_description(self, item):
60 artist = item.extra_info.get('artist_name', None)
61 if artist is not None:
62 lines.append(u'Czyta: %s' % artist)
63 director = item.extra_info.get('director_name', None)
64 if director is not None:
65 lines.append(u'Reżyseria: %s' % director)
66 return u'<br/>\n'.join(lines)
68 def item_link(self, item):
69 return item.book.get_absolute_url()
71 def item_guid(self, item):
72 return absolute_url(item.file.url)
74 def item_enclosure_url(self, item):
75 return absolute_url(item.file.url)
77 def item_enclosure_length(self, item):
80 def item_enclosure_mime_type(self, item):
81 return self.mime_types[item.type]
83 def item_pubdate(self, item):
84 return item.uploaded_at