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
11 def absolute_url(url):
12 return "http://%s%s" % (Site.objects.get_current().domain, url)
15 class AudiobookFeed(Feed):
16 description = "Audiobooki ostatnio dodane do serwisu Wolne Lektury."
21 'daisy': 'application/zip',
25 'all': 'WolneLektury.pl - audiobooki we wszystkich formatach',
26 'mp3': 'WolneLektury.pl - audiobooki w formacie MP3',
27 'ogg': 'WolneLektury.pl - audiobooki w formacie Ogg Vorbis',
28 'daisy': 'WolneLektury.pl - audiobooki w formacie DAISY',
31 def get_object(self, request, type):
32 return {'type': type, 'all': 'all' in request.GET}
34 def title(self, args):
35 return self.titles[args['type']]
38 return reverse('audiobook_feed', args=(args['type'],))
40 def items(self, args):
41 objects = models.BookMedia.objects.order_by('-uploaded_at')
43 objects = objects.filter(type__in=('mp3', 'ogg', 'daisy'))
45 objects = objects.filter(type=args['type'])
47 objects = objects[:50]
50 def item_title(self, item):
53 def item_categories(self, item):
54 return sorted(set(author.name for author in
55 item.book.tags.filter(category='author').iterator()))
57 def item_description(self, item):
59 artist = item.extra_info.get('artist_name', None)
60 if artist is not None:
61 lines.append(u'Czyta: %s' % artist)
62 director = item.extra_info.get('artist_name', None)
63 if director is not None:
64 lines.append(u'Reżyseruje: %s' % director)
65 return u'<br/>\n'.join(lines)
67 def item_link(self, item):
68 return item.book.get_absolute_url()
70 def item_guid(self, item):
71 return absolute_url(item.file.url)
73 def item_enclosure_url(self, item):
74 return absolute_url(item.file.url)
76 def item_enclosure_length(self, item):
79 def item_enclosure_mime_type(self, item):
80 return self.mime_types[item.type]
82 def item_pubdate(self, item):
83 return item.uploaded_at