style
[redakcja.git] / apps / catalogue / feeds.py
1 # -*- coding: utf-8 -*-
2 from django.contrib.syndication.views import Feed
3 from django.shortcuts import get_object_or_404
4 from catalogue.models import Book, Chunk
5
6
7 class PublishTrackFeed(Feed):
8     title = u"Planowane publikacje"
9     link = "/"
10
11     def description(self, obj):
12         tag, published = obj
13         return u"Publikacje, które dotarły co najmniej do etapu: %s" % tag.name
14
15     def get_object(self, request, slug):
16         published = request.GET.get('published')
17         if published is not None:
18             published = published == 'true'
19         return get_object_or_404(Chunk.tag_model, slug=slug), published
20
21     def item_title(self, item):
22         return item.title
23
24     def items(self, obj):
25         tag, published = obj
26         books = Book.objects.filter(public=True, _on_track__gte=tag.ordering).order_by('-_on_track', 'title')
27         if published is not None:
28             books = books.filter(_published=published)
29         return books