# HG changeset patch # User Steve Losh # Date 1231976793 18000 # Node ID 4df10b999a18e6a4be730c4d6db0b3fc1ca3bbe7 # Parent 796ae675fd37573f28aec183fe41a37ea829a703 Added project and comment feeds. diff -r 796ae675fd37 -r 4df10b999a18 feeds.py --- 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 + diff -r 796ae675fd37 -r 4df10b999a18 projects/models.py --- 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) diff -r 796ae675fd37 -r 4df10b999a18 templates/feeds/comments_description.html --- /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 diff -r 796ae675fd37 -r 4df10b999a18 templates/feeds/comments_title.html --- /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 diff -r 796ae675fd37 -r 4df10b999a18 templates/feeds/projects_description.html --- /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 diff -r 796ae675fd37 -r 4df10b999a18 templates/feeds/projects_title.html --- /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 diff -r 796ae675fd37 -r 4df10b999a18 templates/projects/project.html --- 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 @@

Comments

{% for comment in project.comment_set.all|dictsort:"submitted" %}
+

{{ comment.name }} said:

{{ comment.body|markdown:"safe" }} diff -r 796ae675fd37 -r 4df10b999a18 urls.py --- 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.*)/$', '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.+)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}), )