# HG changeset patch # User Steve Losh # Date 1231980834 18000 # Node ID cc77ca9376437e93b510cb6016873fa6a0913db7 # Parent 4df10b999a18e6a4be730c4d6db0b3fc1ca3bbe7 Finished implementing all the feeds. diff -r 4df10b999a18 -r cc77ca937643 feeds.py --- a/feeds.py Wed Jan 14 18:46:33 2009 -0500 +++ b/feeds.py Wed Jan 14 19:53:54 2009 -0500 @@ -1,6 +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 +from stevelosh.thoughts.models import TextThought, LinkThought import operator class LatestEntries(Feed): @@ -13,7 +14,7 @@ item_author_link = 'http://stevelosh.com/' def items(self): - return Entry.objects.filter(published=True).order_by('-pub_date')[:15] + return Entry.objects.filter(published=True).order_by('-pub_date')[:10] def item_pubdate(self, item): return item.pub_date @@ -28,9 +29,10 @@ item_author_link = 'http://stevelosh.com/' def items(self): - comments = list(BlogComment.objects.order_by('-submitted')[:50]) + comments = list(BlogComment.objects.order_by('-submitted')[:50]) comments += list(ProjectComment.objects.order_by('-submitted')[:50]) comments.sort(key=operator.attrgetter('submitted')) + comments.reverse() return comments[:50] def item_pubdate(self, item): @@ -46,8 +48,69 @@ item_author_link = 'http://stevelosh.com/' def items(self): - return Project.objects.order_by('-posted')[:15] + return Project.objects.order_by('-posted')[:10] def item_pubdate(self, item): return item.posted + +class LatestThoughts(Feed): + title = "stevelosh.com thoughts" + link = "http://stevelosh.com/thoughts/" + description = "Latest thoughts from stevelosh.com" + + item_author_name = 'Steve Losh' + item_author_email = 'steve@stevelosh.com' + item_author_link = 'http://stevelosh.com/' + + def items(self): + thoughts = [] + thoughts += [{'type': 'thought-text', 'item': thought, 'date': thought.posted} + for thought in + TextThought.objects.order_by('-posted')[:10]] + thoughts += [{'type': 'thought-link', 'item': thought, 'date': thought.posted} + for thought in + LinkThought.objects.order_by('-posted')[:10]] + thoughts.sort(key=operator.itemgetter('date')) + thoughts.reverse() + return thoughts[:10] + + def item_pubdate(self, item): + return item['date'] + + def item_link(self, item): + return item['item'].get_absolute_url() + + +class LatestEverything(Feed): + title = "stevelosh.com" + link = "http://stevelosh.com/" + description = "Latest updates from stevelosh.com" + + item_author_name = 'Steve Losh' + item_author_email = 'steve@stevelosh.com' + item_author_link = 'http://stevelosh.com/' + + def items(self): + items = [] + items += [{'type': 'blog', 'item': entry, 'date': entry.pub_date} + for entry in + Entry.objects.filter(published=True).order_by('-pub_date')[:15]] + items += [{'type': 'thought-text', 'item': thought, 'date': thought.posted} + for thought in + TextThought.objects.order_by('-posted')[:10]] + items += [{'type': 'thought-link', 'item': thought, 'date': thought.posted} + for thought in + LinkThought.objects.order_by('-posted')[:10]] + items += [{'type': 'project', 'item': project, 'date': project.posted} + for project in + Project.objects.order_by('-posted')[:10]] + items.sort(key=operator.itemgetter('date')) + items.reverse() + return items[:10] + + def item_pubdate(self, item): + return item['date'] + + def item_link(self, item): + return item['item'].get_absolute_url() diff -r 4df10b999a18 -r cc77ca937643 templates/feeds/all_description.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/feeds/all_description.html Wed Jan 14 19:53:54 2009 -0500 @@ -0,0 +1,26 @@ +{% load markup %} + +{% ifequal obj.type 'blog' %} + {{ obj.item.body|markdown }} +{% endifequal %} + +{% ifequal obj.type 'project' %} + {{ obj.item.body|markdown }} +{% endifequal %} + +{% ifequal obj.type 'thought-text' %} + {{ obj.item.body|markdown }} +{% endifequal %} + +{% ifequal obj.type 'thought-link' %} + + {% if obj.item.name %} + {{ obj.item.name }} + {% else %} + {{ obj.item.url }} + {% endif %} + + {% if obj.item.description %} + {{ obj.item.description|markdown }} + {% endif %} +{% endifequal %} \ No newline at end of file diff -r 4df10b999a18 -r cc77ca937643 templates/feeds/all_title.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/feeds/all_title.html Wed Jan 14 19:53:54 2009 -0500 @@ -0,0 +1,23 @@ +{% ifequal obj.type 'blog' %} + {{ obj.item.title }} +{% endifequal %} + +{% ifequal obj.type 'project' %} + {{ obj.item.name }} +{% endifequal %} + +{% ifequal obj.type 'thought-text' %} + {% if obj.item.title %} + {{ obj.item.title }} + {% else %} + {{ obj.item.body|truncatewords:10 }} + {% endif %} +{% endifequal %} + +{% ifequal obj.type 'thought-link' %} + {% if obj.item.name %} + {{ obj.item.name }} + {% else %} + {{ obj.item.url }} + {% endif %} +{% endifequal %} \ No newline at end of file diff -r 4df10b999a18 -r cc77ca937643 templates/feeds/blog_description.html --- a/templates/feeds/blog_description.html Wed Jan 14 18:46:33 2009 -0500 +++ b/templates/feeds/blog_description.html Wed Jan 14 19:53:54 2009 -0500 @@ -1,1 +1,1 @@ -{{ obj.snip }} \ No newline at end of file +{% load markup %}{{ obj.body|markdown }} \ No newline at end of file diff -r 4df10b999a18 -r cc77ca937643 templates/feeds/thoughts_description.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/feeds/thoughts_description.html Wed Jan 14 19:53:54 2009 -0500 @@ -0,0 +1,18 @@ +{% load markup %} + +{% ifequal obj.type 'thought-text' %} + {{ obj.item.body|markdown }} +{% endifequal %} + +{% ifequal obj.type 'thought-link' %} + + {% if obj.item.name %} + {{ obj.item.name }} + {% else %} + {{ obj.item.url }} + {% endif %} + + {% if obj.item.description %} + {{ obj.item.description|markdown }} + {% endif %} +{% endifequal %} \ No newline at end of file diff -r 4df10b999a18 -r cc77ca937643 templates/feeds/thoughts_title.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/templates/feeds/thoughts_title.html Wed Jan 14 19:53:54 2009 -0500 @@ -0,0 +1,15 @@ +{% ifequal obj.type 'thought-text' %} + {% if obj.item.title %} + {{ obj.item.title }} + {% else %} + {{ obj.item.body|truncatewords:10 }} + {% endif %} +{% endifequal %} + +{% ifequal obj.type 'thought-link' %} + {% if obj.item.name %} + {{ obj.item.name }} + {% else %} + {{ obj.item.url }} + {% endif %} +{% endifequal %} \ No newline at end of file diff -r 4df10b999a18 -r cc77ca937643 templates/thoughts/list.html --- a/templates/thoughts/list.html Wed Jan 14 18:46:33 2009 -0500 +++ b/templates/thoughts/list.html Wed Jan 14 19:53:54 2009 -0500 @@ -15,6 +15,7 @@ {% for thought in thoughts %}
{% ifequal thought.type 'text' %} +

text

@@ -26,6 +27,7 @@
{% endifequal %} {% ifequal thought.type 'link' %} +

link

diff -r 4df10b999a18 -r cc77ca937643 thoughts/models.py --- a/thoughts/models.py Wed Jan 14 18:46:33 2009 -0500 +++ b/thoughts/models.py Wed Jan 14 19:53:54 2009 -0500 @@ -8,6 +8,9 @@ tumblr_id = models.IntegerField(blank=False, null=False) type = models.CharField(default='text', max_length=100) + def get_absolute_url(self): + return u'/thoughts/#text-' + str(self.id) + def __unicode__(self): return u'%s' % (self.body[:20],) @@ -19,6 +22,9 @@ tumblr_id = models.IntegerField(blank=False, null=False) type = models.CharField(default='link', max_length=100) + def get_absolute_url(self): + return u'/thoughts/#text-' + str(self.id) + def __unicode__(self): return u'%s' % (self.url,) diff -r 4df10b999a18 -r cc77ca937643 urls.py --- a/urls.py Wed Jan 14 18:46:33 2009 -0500 +++ b/urls.py Wed Jan 14 19:53:54 2009 -0500 @@ -1,13 +1,15 @@ from django.conf.urls.defaults import * from django.contrib import admin from django.conf import settings -from stevelosh.feeds import LatestEntries, LatestComments, LatestProjects +from stevelosh.feeds import * admin.autodiscover() feeds = { 'blog': LatestEntries, 'comments': LatestComments, - 'projects': LatestProjects, } + 'projects': LatestProjects, + 'thoughts': LatestThoughts, + 'all': LatestEverything, } urlpatterns = patterns('', (r'^admin/(.*)', admin.site.root),