4df10b999a18

Added project and comment feeds.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 14 Jan 2009 18:46:33 -0500
parents 796ae675fd37
children cc77ca937643
branches/tags (none)
files feeds.py projects/models.py templates/feeds/comments_description.html templates/feeds/comments_title.html templates/feeds/projects_description.html templates/feeds/projects_title.html templates/projects/project.html urls.py

Changes

--- a/feeds.py	Wed Jan 14 18:20:56 2009 -0500
+++ b/feeds.py	Wed Jan 14 18:46:33 2009 -0500
@@ -1,5 +1,7 @@
 from django.contrib.syndication.feeds import Feed
 from stevelosh.blog.models import Entry, Comment as BlogComment
+from stevelosh.projects.models import Project, Comment as ProjectComment
+import operator
 
 class LatestEntries(Feed):
     title = "stevelosh.com blog entries"
@@ -15,3 +17,37 @@
     
     def item_pubdate(self, item):
         return item.pub_date
+
+class LatestComments(Feed):
+    title = "stevelosh.com blog comments"
+    link = "http://stevelosh.com/blog/"
+    description = "Latest comments on blog entries from stevelosh.com"
+    
+    item_author_name = 'Steve Losh'
+    item_author_email = 'steve@stevelosh.com'
+    item_author_link = 'http://stevelosh.com/'
+    
+    def items(self):
+        comments = list(BlogComment.objects.order_by('-submitted')[:50])
+        comments += list(ProjectComment.objects.order_by('-submitted')[:50])
+        comments.sort(key=operator.attrgetter('submitted'))
+        return comments[:50]
+    
+    def item_pubdate(self, item):
+        return item.submitted
+
+class LatestProjects(Feed):
+    title = "stevelosh.com projects"
+    link = "http://stevelosh.com/projects/"
+    description = "Latest projects on stevelosh.com"
+    
+    item_author_name = 'Steve Losh'
+    item_author_email = 'steve@stevelosh.com'
+    item_author_link = 'http://stevelosh.com/'
+    
+    def items(self):
+        return Project.objects.order_by('-posted')[:15]
+    
+    def item_pubdate(self, item):
+        return item.posted
+    
--- a/projects/models.py	Wed Jan 14 18:20:56 2009 -0500
+++ b/projects/models.py	Wed Jan 14 18:46:33 2009 -0500
@@ -12,6 +12,10 @@
     posted = models.DateTimeField(blank=False, default=datetime.datetime.now)
     slug = models.SlugField()
     
+    @models.permalink
+    def get_absolute_url(self):
+        return ('project-view', (self.slug,),)
+    
     def __unicode__(self):
         return u"%s" % (self.name,)
 
@@ -50,6 +54,9 @@
     submitted = models.DateTimeField(default=datetime.datetime.now)
     project = models.ForeignKey(Project)
     
+    def get_absolute_url(self):
+        return self.project.get_absolute_url() + "#comment-" + str(self.id)
+    
     def __unicode__(self):
         return u'%s on %s' % (self.name, self.entry.title)
     
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/feeds/comments_description.html	Wed Jan 14 18:46:33 2009 -0500
@@ -0,0 +1,1 @@
+{% load markup %}{{ obj.body|markdown:"safe" }}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/feeds/comments_title.html	Wed Jan 14 18:46:33 2009 -0500
@@ -0,0 +1,1 @@
+Comment on {% if obj.entry.title %}{{ obj.entry.title }}{% else %}{{ obj.project.name }}{% endif %} by {{ obj.name }}.
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/feeds/projects_description.html	Wed Jan 14 18:46:33 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/projects_title.html	Wed Jan 14 18:46:33 2009 -0500
@@ -0,0 +1,1 @@
+{{ obj.name }}
\ No newline at end of file
--- a/templates/projects/project.html	Wed Jan 14 18:20:56 2009 -0500
+++ b/templates/projects/project.html	Wed Jan 14 18:46:33 2009 -0500
@@ -36,6 +36,7 @@
 			<h1>Comments</h1>
 			{% for comment in project.comment_set.all|dictsort:"submitted" %}
 				<div class="projects-project-comment">
+					<a name="comment-{{ comment.id }}"></a>
 					<h2>{{ comment.name }} said:</h2>
 					<div class="projects-project-comment-body">
 						{{ comment.body|markdown:"safe" }}
--- a/urls.py	Wed Jan 14 18:20:56 2009 -0500
+++ b/urls.py	Wed Jan 14 18:46:33 2009 -0500
@@ -1,27 +1,29 @@
 from django.conf.urls.defaults import *
 from django.contrib import admin
 from django.conf import settings
-from stevelosh.feeds import LatestEntries
+from stevelosh.feeds import LatestEntries, LatestComments, LatestProjects
 
 
 admin.autodiscover()
-feeds = { 'blog': LatestEntries, }
+feeds = { 'blog': LatestEntries, 
+          'comments': LatestComments,
+          'projects': LatestProjects, }
 
 urlpatterns = patterns('',
     (r'^admin/(.*)', admin.site.root),
-    url(r'^blog/$',                'stevelosh.blog.views.list',      name='blog-list-newest'),
-    url(r'^blog/page/(\d+)/$',     'stevelosh.blog.views.list',      name='blog-list-page'),
-    url(r'^blog/comment/$',        'stevelosh.blog.views.comment'),
+    url(r'^blog/$',                'stevelosh.blog.views.list',        name='blog-list-newest'),
+    url(r'^blog/page/(\d+)/$',     'stevelosh.blog.views.list',        name='blog-list-page'),
+    url(r'^blog/comment/$',        'stevelosh.blog.views.comment',     name='blog-post-comment'),
     url(r'^blog/entry/(\d+)/(\d+)/(\d+)/(.*)/$',
-                                   'stevelosh.blog.views.entry',     name='blog-entry'),
+                                   'stevelosh.blog.views.entry',       name='blog-entry'),
     url(r'^blog/(\d+)/(\d+)/(\d+)/(.*).html/$',
-                                   'stevelosh.blog.views.old_entry', name='blog-old-entry'),
-    url(r'^projects/$',            'stevelosh.projects.views.list',  name='project-list'),
-    url(r'^projects/comment/$',    'stevelosh.projects.views.comment'),
-    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}),
+                                   'stevelosh.blog.views.old_entry',   name='blog-old-entry'),
+    url(r'^projects/$',            'stevelosh.projects.views.list',    name='project-list'),
+    url(r'^projects/comment/$',    'stevelosh.projects.views.comment', name='project-post-comment'),
+    url(r'^projects/(.*)/$',       'stevelosh.projects.views.project', name='project-view'),
+    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}),
 )