Permalink
Browse files

Now feeds are working!

  • Loading branch information...
dokterbob committed Oct 14, 2008
1 parent cf8ada5 commit d0fa053968f9816dda3c11888338e64c2ee831ee
View
@@ -0,0 +1,25 @@
+import logging
+
+from datetime import datetime, timedelta
+
+from django.contrib.syndication.feeds import Feed
+from django.contrib.sites.models import Site
+
+from django.utils.translation import ugettext as _
+from django.core.urlresolvers import reverse
+
+from models import Event
+
+class EventFeed(Feed):
+ title = _('%s agenda' % Site.objects.get_current())
+ description = _('Upcoming events in the agenda.')
+
+ def link(self):
+ return reverse('agenda-index')
+
+ def items(self):
+ return Event.published.filter(event_date__gte=datetime.now() - timedelta(days=1))
+
+ def item_pubdate(self, item):
+ return item.publish_date
+
View
@@ -4,6 +4,8 @@
from django.contrib.comments.models import Comment
+from django.conf import settings
+
class EventSitemap(Sitemap):
changefreq = "daily"
@@ -13,12 +15,14 @@ def items(self):
def lastmod(self, obj):
""" The Event 'changes' when there are newer comments, so check for that. """
- if obj.allow_comments:
- try:
- comment_date = Comment.objects.for_model(Event).filter(object_pk=obj.id).latest('submit_date').submit_date
- return comment_date > obj.mod_date and comment_date or obj.mod_date
- except Comment.DoesNotExist:
- pass
+ # Check for comments installation here, otherwise it all goes wrong.
+ if 'django.contrib.comments' in settings.INSTALLED_APPS:
+ if obj.allow_comments:
+ try:
+ comment_date = Comment.objects.for_model(Event).filter(object_pk=obj.id).latest('submit_date').submit_date
+ return comment_date > obj.mod_date and comment_date or obj.mod_date
+ except Comment.DoesNotExist:
+ pass
return obj.mod_date
@@ -0,0 +1 @@
+{{ obj.description }}
@@ -0,0 +1 @@
+{{ obj }}
View
@@ -107,6 +107,7 @@
'django.contrib.admin',
'django.contrib.comments',
'django.contrib.sitemaps',
+ 'django.contrib.syndication',
'agenda'
)
@@ -1,3 +1,8 @@
{% extends "base.html" %}
+{% block htmlheader %}
+ <link rel="alternate" type="application/rss+xml" title="Upcoming events" href="{% url django.contrib.syndication.views.feed "events" %}" />
+ <link rel="alternate" type="application/rss+xml" title="Latest comments" href="{% url django.contrib.syndication.views.feed "comments" %}" />
+
+{% endblock %}
{% block htmltitle %}Agenda application{% endblock %}
View
@@ -11,9 +11,15 @@
urlpatterns = patterns('')
from agenda.sitemaps import EventSitemap
+from agenda.feeds import EventFeed
+from django.contrib.comments.feeds import LatestCommentFeed
+
sitemaps = { 'events' : EventSitemap }
+feeds = { 'events' : EventFeed,
+ 'comments' : LatestCommentFeed }
+
urlpatterns += patterns('',
(r'^', include('agenda.urls')),
@@ -25,10 +31,8 @@
(r'^comments/', include('django.contrib.comments.urls')),
# Sitemaps
- (r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps})
+ (r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
# Feeds
- #(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps})
-
-
+ (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feeds}),
)

0 comments on commit d0fa053

Please sign in to comment.