cc77ca937643

Finished implementing all the feeds.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 14 Jan 2009 19:53:54 -0500
parents 4df10b999a18
children 8ddcf2364ea7
branches/tags (none)
files feeds.py templates/feeds/all_description.html templates/feeds/all_title.html templates/feeds/blog_description.html templates/feeds/thoughts_description.html templates/feeds/thoughts_title.html templates/thoughts/list.html thoughts/models.py urls.py

Changes

--- 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()
--- /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' %}
+	<a href="{{ obj.item.url }}">
+		{% if obj.item.name %}
+			{{ obj.item.name }}
+		{% else %}
+			{{ obj.item.url }}
+		{% endif %}
+	</a>
+	{% if obj.item.description %}
+		{{ obj.item.description|markdown }}
+	{% endif %}
+{% endifequal %}
\ No newline at end of file
--- /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
--- 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
--- /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' %}
+	<a href="{{ obj.item.url }}">
+		{% if obj.item.name %}
+			{{ obj.item.name }}
+		{% else %}
+			{{ obj.item.url }}
+		{% endif %}
+	</a>
+	{% if obj.item.description %}
+		{{ obj.item.description|markdown }}
+	{% endif %}
+{% endifequal %}
\ No newline at end of file
--- /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
--- 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 %}
 			<div class="thought">
 				{% ifequal thought.type 'text' %}
+					<a name="text-{{ thought.id }}"></a>
 					<div class="thought-type span-2">
 						<h2>text</h2>
 					</div>
@@ -26,6 +27,7 @@
 					</div>
 				{% endifequal %}
 				{% ifequal thought.type 'link' %}
+					<a name="link-{{ thought.id }}"></a>
 					<div class="thought-type span-2">
 						<h2>link</h2>
 					</div>
--- 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,)
 
--- 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),