Switch to date-based URLs everywhere except the feed URLs of old posts, so I don't spam everyone's feedreader.
4 Not Django's - it's odd.
10 TODO: max() on an empty sequence in the lastBuildDate section causes
15 from django.http import HttpResponse, HttpResponseRedirect, Http404
16 from django.views.decorators.cache import cache_page
21 def _build_entry_item(entry):
22 "Build the RSSItem for a blog Entry"
25 entry_kwargs['title'] = entry.title
26 entry_kwargs['guid'] = guid = entry.urls.feed_url
27 entry_kwargs['link'] = "http://adam.gomaa.us%s" % guid
28 entry_kwargs['description'] = entry.rendered
29 entry_kwargs['pubDate'] = entry.pub_date
31 return PyRSS2Gen.RSSItem(**entry_kwargs)
34 def _build_comment_item(comment):
35 "Return the RSSItem for the blog Comment"
38 item_kwargs['title'] = "Comment on %s" % comment.entry.title
39 abs_url = comment.entry.feed_url
40 item_kwargs['link'] = "http://adam.gomaa.us%s" % abs_url
41 item_kwargs['guid'] = comment.entry.slug+str(comment.id)
42 item_kwargs['description'] = comment.rendered
43 item_kwargs['pubDate'] = comment.pub_date
45 return PyRSS2Gen.RSSItem(**item_kwargs)
50 "Show the latest blog Entries"
51 from agdj.blog.models import Entry
53 limit = request.GET.get("limit", None)
57 items = Entry.public_objects.order_by("-pub_date")[:limit]
60 feed_kwargs['title'] = "204 No Content Blog"
61 feed_kwargs['link'] = "http://adam.gomaa.us/blog/"
62 feed_kwargs['description'] = "Feed for 204 No Content, Adam Gomaa's blog."
63 feed_kwargs['lastBuildDate'] = max([item.pub_date for item in items])
64 feed_kwargs['items'] = [_build_entry_item(item) for item in items]
66 rss = PyRSS2Gen.RSS2(**feed_kwargs)
67 res = HttpResponse(rss.to_xml())
68 res['content-type'] = "application/rss+xml"
72 def per_tag(request, tag):
73 "Feed for the latest Entries for a tag"
74 from agdj.blog.models import Entry
75 from tagging.models import TaggedItem
77 items = Entry.objects.filter(public=True).order_by("-pub_date")
78 items = TaggedItem.objects.get_by_model(items, tag)[:5]
84 feed_kwargs['title'] = "204 No Content Blog"
85 feed_kwargs['link'] = "http://adam.gomaa.us/blog/"
86 feed_kwargs['description'] = "Feed for '%s' tag in 204 No Content, Adam Gomaa's blog." % tag
87 feed_kwargs['lastBuildDate'] = max([item.pub_date for item in items])
88 feed_kwargs['items'] = [_build_entry_item(item) for item in items]
90 rss = PyRSS2Gen.RSS2(**feed_kwargs)
91 res = HttpResponse(rss.to_xml())
92 res['content-type'] = "application/rss+xml"
96 def comments(request):
97 "Feed of the latest comments"
98 from agdj.blog.models import Comment
100 items = Comment.objects.order_by("-pub_date")[:15]
103 feed_kwargs['title'] = "204 Blog Comments"
104 feed_kwargs['link'] = "http://adam.gomaa.us/blog/"
105 feed_kwargs['description'] = "Comment feed for 204 No Content."
106 feed_kwargs['lastBuildDate'] = max([item.pub_date for item in items])
107 feed_kwargs['items'] = [_build_comment_item(item) for item in items]
109 rss = PyRSS2Gen.RSS2(**feed_kwargs)
111 res = HttpResponse(rss.to_xml())
112 res['content-type'] = "application/rss+xml"