public
Description: A full featured and opinionated blogging solution using Django
Homepage: http://lethain.com/projects/lifeflow/
Clone URL: git://github.com/lethain/lifeflow.git
lifeflow / feeds.py
100644 241 lines (137 sloc) 5.42 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
from django.contrib.syndication.feeds import Feed
from django.conf import settings
from lifeflow.models import *
 
 
 
class AllFeed(Feed):
    title = u"%s" % settings.LIFEFLOW_BLOG_NAME
    link = u"/"
    description = u"The full feed of all entries! Piping hot and ready for consumption."
    copyright = u'Creative Commons License'
 
 
    def items(self):
        return Entry.current.all().order_by('-pub_date')[:25]
    
    def item_pubdate(self, item):
        return item.pub_date
 
 
 
class FlowFeed(Feed):
    def get_object(self, bits):
        slug = bits[0]
        return Flow.objects.get(slug=slug)
 
 
    def title(self, obj):
        return u"%s: %s" % (settings.LIFEFLOW_BLOG_NAME,
                                              obj.title)
 
 
    def link(self, obj):
        return obj.get_absolute_url()
 
 
    def description(self, obj):
        return u"The piping hot feed for all entries in the %s flow." % obj.title
 
 
    def items(self, obj):
        return obj.latest(qty=25)
    
    def item_pubdate(self, item):
        return item.pub_date
 
 
 
class TagFeed(Feed):
    def get_object(self, bits):
        slug = bits[0]
        return Tag.objects.get(slug=slug)
 
    
    def title(self, obj):
        return u"%s: the %s tag" % (settings.LIFEFLOW_BLOG_NAME,
                                              obj.title)
 
 
    def link(self, obj):
        return obj.get_absolute_url()
 
 
    def description(self, obj):
        return u"All entries tagged with %s." % obj.title
 
    
    def items(self, obj):
        return obj.latest()
 
 
    def item_pubdate(self, item):
        return item.pub_date
 
 
class AuthorFeed(Feed):
    def get_object(self, bits):
        slug = bits[0]
        return Author.objects.get(slug=slug)
 
 
    def title(self, obj):
        return u"%s: %s" % (settings.LIFEFLOW_BLOG_NAME,
                                              obj.name)
    
    def title(self, obj):
        return u"Feed for stuff by %s." % obj.name
 
 
    def link(self, obj):
        return obj.get_absolute_url()
 
 
    def description(self, obj):
        return u"Recent entries written by %s." % obj.name
 
    
    def items(self, obj):
        return obj.latest()
 
 
    def item_pubdate(self, item):
        return item.pub_date
 
 
class LanguageFeed(Feed):
    def get_object(self, bits):
        slug = bits[0]
        return Language.objects.get(slug=slug)
 
 
    def title(self, obj):
        return u"%s: %s" % (settings.LIFEFLOW_BLOG_NAME,
                                              obj.title)
    
    def title(self, obj):
        return u"Feed for stuff translated into %s." % obj.title
 
 
    def link(self, obj):
        return obj.get_absolute_url()
 
 
    def description(self, obj):
        return u"Recent entries translated into %s." % obj.title
 
    
    def items(self, obj):
        return obj.latest()
    
    
    def item_pubdate(self, item):
        return item.pub_date
 
 
 
class SeriesFeed(Feed):
    def get_object(self, bits):
        slug = bits[0]
        return Series.objects.get(slug=slug)
 
    
    def title(self, obj):
        return u"%s: %s" % (settings.LIFEFLOW_BLOG_NAME,
                                              obj.title)
 
 
    def link(self, obj):
        return obj.get_absolute_url()
 
 
    def description(self, obj):
        return u"Entries in the %s series." % obj.title
 
    
    def items(self, obj):
        return obj.latest()
        
        
    def item_pubdate(self, item):
        return item.pub_date
 
 
 
class TranslationFeed(Feed):
    title = u"%s: Translations" % settings.LIFEFLOW_BLOG_NAME
    link = u"/"
    description = u"Recent translationed entries."
    copyright = u'Creative Commons License'
 
 
    def items(self):
        return Entry.objects.all().filter(**{'pub_date__lte': datetime.datetime.now()}).filter(**{'is_translation':True})
    
    
    def item_pubdate(self, item):
        return item.pub_date
 
 
 
class ProjectFeed(Feed):
    title = u"%s: Projects" % settings.LIFEFLOW_BLOG_NAME
    link = u"/"
    description = u"Latest projects on %s." % settings.LIFEFLOW_BLOG_NAME
    copyright = u'Creative Commons License'
 
 
    def items(self):
        return Project.objects.all().order_by('-id')
 
 
 
class CommentFeed(Feed):
    title = u"%s: Comments" % settings.LIFEFLOW_BLOG_NAME
    link = "/"
    description = u"Latest comments on %s." % settings.LIFEFLOW_BLOG_NAME
    copyright = u'Creative Commons License'
    
 
    def items(self):
        return Comment.objects.all().order_by('-date',)[:20]
        
    
    def item_pubdate(self, item):
        return item.date
 
 
 
class EntryCommentFeed(Feed):
    def get_object(self, bits):
        year = bits[0]
        month = bits[1]
        day = bits[2]
        slug = bits[3]
        return Entry.objects.get(pub_date__year=year,
                                 pub_date__month=month,
                                 pub_date__day=day,
                                 slug=slug)
 
    
    def title(self, obj):
        return u"%s: Comments for %s" % (settings.LIFEFLOW_BLOG_NAME,
                                              obj.title)
 
 
    def link(self, obj):
        return obj.get_absolute_url()
 
 
    def description(self, obj):
        return u"Comments for %s." % obj.title
 
    
    def items(self, obj):
        return obj.comment_set.all().order_by('-date')
        
    
    def item_pubdate(self, item):
        return item.date