796ae675fd37

Blog post RSS implemented.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 14 Jan 2009 18:20:56 -0500
parents 5d5a567385bb
children 4df10b999a18
branches/tags (none)
files blog/models.py feeds.py templates/blog/entry.html templates/feeds/blog_description.html templates/feeds/blog_title.html urls.py

Changes

--- a/blog/models.py	Tue Jan 13 19:37:21 2009 -0500
+++ b/blog/models.py	Wed Jan 14 18:20:56 2009 -0500
@@ -10,9 +10,10 @@
     body = models.TextField()
     published = models.BooleanField(default=False)
     
+    @models.permalink
     def get_absolute_url(self):
-        return "/blog/entry/%i/%i/%i/%s/" % (self.pub_date.year, 
-            self.pub_date.month, self.pub_date.day, self.slug)
+        return ('blog-entry', (self.pub_date.year, self.pub_date.month, 
+                               self.pub_date.day, self.slug),)
     
     def __unicode__(self):
         return u'%s' % (self.title,)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/feeds.py	Wed Jan 14 18:20:56 2009 -0500
@@ -0,0 +1,17 @@
+from django.contrib.syndication.feeds import Feed
+from stevelosh.blog.models import Entry, Comment as BlogComment
+
+class LatestEntries(Feed):
+    title = "stevelosh.com blog entries"
+    link = "http://stevelosh.com/blog/"
+    description = "Latest blog entries on stevelosh.com"
+    
+    item_author_name = 'Steve Losh'
+    item_author_email = 'steve@stevelosh.com'
+    item_author_link = 'http://stevelosh.com/'
+    
+    def items(self):
+        return Entry.objects.filter(published=True).order_by('-pub_date')[:15]
+    
+    def item_pubdate(self, item):
+        return item.pub_date
--- a/templates/blog/entry.html	Tue Jan 13 19:37:21 2009 -0500
+++ b/templates/blog/entry.html	Wed Jan 14 18:20:56 2009 -0500
@@ -36,6 +36,7 @@
 			<h1>Comments</h1>
 			{% for comment in entry.comment_set.all|dictsort:"submitted" %}
 				<div class="blog-entry-comment">
+					<a name="comment-{{ comment.id }}"></a>
 					<h2>{{ comment.name }} said:</h2>
 					<div class="blog-entry-comment-body">
 						{{ comment.body|markdown:"safe" }}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/feeds/blog_description.html	Wed Jan 14 18:20:56 2009 -0500
@@ -0,0 +1,1 @@
+{{ obj.snip }}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/feeds/blog_title.html	Wed Jan 14 18:20:56 2009 -0500
@@ -0,0 +1,1 @@
+{{ obj.title }}
\ No newline at end of file
--- a/urls.py	Tue Jan 13 19:37:21 2009 -0500
+++ b/urls.py	Wed Jan 14 18:20:56 2009 -0500
@@ -1,9 +1,11 @@
 from django.conf.urls.defaults import *
 from django.contrib import admin
 from django.conf import settings
+from stevelosh.feeds import LatestEntries
 
 
 admin.autodiscover()
+feeds = { 'blog': LatestEntries, }
 
 urlpatterns = patterns('',
     (r'^admin/(.*)', admin.site.root),
@@ -19,6 +21,7 @@
     url(r'^projects/(.*)/$',       'stevelosh.projects.views.project'),
     url(r'^thoughts/$',            'stevelosh.thoughts.views.list',  name='thoughts-list-newest'),
     url(r'^thoughts/page/(\d+)/$', 'stevelosh.thoughts.views.list',  name='thoughts-list-page'),
+    url(r'^rss/(?P<url>.*)/$',     'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
 )