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
8 from django.db.models import Q
10 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):
56 for book in item.book_set.all():
57 for author in book.tags.filter(category='author'):
58 authors.add(author.name)
59 return sorted(authors)
61 def item_description(self, item):
63 artist = item.get_extra_info_value().get('artist_name', None)
64 if artist is not None:
65 lines.append(u'Czyta: %s' % artist)
66 director = item.get_extra_info_value().get('artist_name', None)
67 if director is not None:
68 lines.append(u'Reżyseruje: %s' % director)
69 return u'<br/>\n'.join(lines)
71 def item_link(self, item):
72 if item.book_set.exists():
73 return item.book_set.all()[0].get_absolute_url()
77 def item_guid(self, item):
78 return absolute_url(item.file.url)
80 def item_enclosure_url(self, item):
81 return absolute_url(item.file.url)
83 def item_enclosure_length(self, item):
86 def item_enclosure_mime_type(self, item):
87 return self.mime_types[item.type]
89 def item_pubdate(self, item):
90 return item.uploaded_at