sykora / djournal

A Blog App for Django.

This URL has Read+Write access

djournal / feeds.py
100644 55 lines (39 sloc) 1.592 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from django.core.urlresolvers import reverse
from django.contrib.syndication.feeds import Feed
from djournal.models import Entry
from djournal.settings import DJOURNAL_BLOG_TITLE
from django.core.exceptions import ObjectDoesNotExist
from tagging.models import Tag
from tagging.utils import get_tag
 
class EntryFeed(Feed) :
    title = DJOURNAL_BLOG_TITLE
    link = "/"
    description = u"All about everything."
 
    title_template = 'feeds/title.html'
    description_template = 'feeds/description.html'
 
    def items(self) :
        return Entry.live.order_by('-creation_timestamp')
 
class EntryRstFeed(EntryFeed) :
    description_template = 'feeds/description_rst.html'
 
class TagEntryFeed(Feed) :
    def get_object(self, bits) :
        print bits
        if len(bits) != 1 :
            raise ObjectDoesNotExist
 
        TagObject = get_tag(bits[0])
 
        if not TagObject :
            raise ObjectDoesNotExist
 
        print TagObject.name
        return TagObject
 
    def title(self, tag) :
        return u"%s : Entries tagged with %s" % (DJOURNAL_BLOG_TITLE, tag.name)
 
    def description(self, tag) :
        return "Entries tagged with %s" % tag.name
 
    def items(self, tag) :
        return Entry.tagged.with_all([tag]).filter(status = 'live').order_by('-creation_timestamp')
 
    def link(self, tag) :
        return reverse('djournal_tag_listing', kwargs = {'tag' : tag.name})
 
    title_template = 'feeds/title.html'
    description_template = 'feeds/description.html'
 
class TagEntryRstFeed(TagEntryFeed) :
    description_template = 'feeds/description_rst.html'