diff options
author | Leif Johansson <leifj@sunet.se> | 2011-05-13 11:15:32 +0200 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2011-05-13 11:15:32 +0200 |
commit | 3bb6c880d2d0476245cfe7bf8afa579e4ee5ba11 (patch) | |
tree | b890373234e94c3630660b84a7bbdf961c2ec7c9 /src | |
parent | 3b80bf37445404bed158f45daf240aaa5599453e (diff) |
replace hand-drawn feeds with the django syndication framework
Diffstat (limited to 'src')
-rw-r--r-- | src/meetingtools/apps/room/feeds.py | 76 | ||||
-rw-r--r-- | src/meetingtools/apps/room/views.py | 16 | ||||
-rw-r--r-- | src/meetingtools/urls.py | 5 | ||||
-rw-r--r-- | src/templates/apps/room/atom.xml | 20 | ||||
-rw-r--r-- | src/templates/apps/room/list.html | 1 | ||||
-rw-r--r-- | src/templates/apps/room/rss2.xml | 26 |
6 files changed, 85 insertions, 59 deletions
diff --git a/src/meetingtools/apps/room/feeds.py b/src/meetingtools/apps/room/feeds.py new file mode 100644 index 0000000..0254339 --- /dev/null +++ b/src/meetingtools/apps/room/feeds.py @@ -0,0 +1,76 @@ +''' +Created on May 13, 2011 + +@author: leifj +''' + +from django.contrib.syndication.views import Feed +from meetingtools.apps.room.models import Room +from tagging.models import TaggedItem +from meetingtools.settings import BASE_URL +from django.utils.feedgenerator import Atom1Feed, Rss201rev2Feed + +class TagsWrapper(object): + + def __init__(self,tn): + self.tags = tn.split('+') + self.rooms = TaggedItem.objects.get_by_model(Room, tn.split('+')) + + def title(self): + return "Rooms tagged with %s" % " and ".join(self.tags) + + def description(self): + return self.title() + + def link(self,ext): + return "%s/room/+%s.%s" % (BASE_URL,"+".join(self.tags),ext) + +class RoomTagFeed(Feed): + + item_author_name = 'SUNET e-meeting tools' + + def ext(self): + if self.feed_type == Atom1Feed: + return "atom" + + if self.feed_type == Rss201rev2Feed: + return "rss" + + return "rss" + + def get_object(self,request,tn): + return TagsWrapper(tn) + + def title(self,t): + return t.title() + + def link(self,t): + return t.link(self.ext()) + + def description(self,t): + return t.description() + + def items(self,t): + return t.rooms + + def item_title(self,room): + return room.name + + def item_description(self,room): + return room.description + + def item_link(self,room): + return room.go_url() + + def item_guid(self,room): + return room.permalink() + + def item_pubdate(self,room): + return room.lastupdated + + +class RoomAtomTagFeed(RoomTagFeed): + feed_type = Atom1Feed + +class RoomRSSTagField(RoomTagFeed): + feed_type = Rss201rev2Feed
\ No newline at end of file diff --git a/src/meetingtools/apps/room/views.py b/src/meetingtools/apps/room/views.py index d0c5f37..3bbc74a 100644 --- a/src/meetingtools/apps/room/views.py +++ b/src/meetingtools/apps/room/views.py @@ -395,26 +395,18 @@ def widget(request,tn): title = 'Rooms tagged with %s' % " and ".join(tags) now = timeAsrfc822( datetime.now() ) return respond_to(request, - {'text/html':'apps/room/widget-test.html', - 'application/json': json_response([_room2dict(room) for room in rooms]), - 'application/rss+xml': 'apps/room/rss2.xml', - 'text/rss': 'apps/room/rss2.xml'}, - {'title':title,'description':title ,'edit':False,'date': now,'tags': tn,'rooms': [_room2dict(room) for room in rooms.all()]}) + {'text/html':'apps/room/widget-test.html'}, + {'title':title,'description':title ,'edit':False,'date': now,'tags': tn,'rooms':rooms.all()}) # should not require login def list_by_tag(request,tn): tags = tn.split('+') rooms = TaggedItem.objects.get_by_model(Room, tags) title = 'Rooms tagged with %s' % " and ".join(tags) - now = rfc3339_date(datetime.now()) - now822 = timeAsrfc822( datetime.now() ) return respond_to(request, {'text/html':'apps/room/list.html', - 'application/json': json_response([_room2dict(room) for room in rooms]), - 'application/atom+xml': 'apps/room/atom.xml', - 'application/rss+xml': 'apps/room/rss2.xml', - 'text/rss': 'apps/room/rss2.xml'}, - {'title':title,'description':title ,'edit':False,'baseurl': BASE_URL,'rfc3339_date': now,'rfc822_date': now822,'tags': tn,'rooms':[_room2dict(room) for room in rooms.all()]}) + 'application/json': json_response([_room2dict(room) for room in rooms])}, + {'title':title,'description':title ,'edit':False,'baseurl': BASE_URL,'tags': tn,'rooms':rooms.all()}) def _can_tag(request,tag): if tag in ('selfcleaning','public','private'): diff --git a/src/meetingtools/urls.py b/src/meetingtools/urls.py index c6913d7..d927409 100644 --- a/src/meetingtools/urls.py +++ b/src/meetingtools/urls.py @@ -4,6 +4,7 @@ from django.conf.urls.defaults import patterns,include from django.contrib import admin from meetingtools.settings import ADMIN_MEDIA_ROOT, MEDIA_ROOT from meetingtools.multiresponse import redirect_to +from meetingtools.apps.room.feeds import RoomAtomTagFeed,RoomRSSTagField admin.autodiscover() def welcome(request): @@ -29,7 +30,9 @@ urlpatterns = patterns('', (r'^room/(\d+)/tag$','meetingtools.apps.room.views.tag'), (r'^room/(\d+)/untag/(.+)$','meetingtools.apps.room.views.untag'), (r'^widget/\+(.+)$','meetingtools.apps.room.views.widget'), - (r'^room/\+(.+)\.(?:json|xml|html|htm|atom|rss)$','meetingtools.apps.room.views.list_by_tag'), + (r'^room/\+(.+)\.(?:json|html|htm)$','meetingtools.apps.room.views.list_by_tag'), + (r'^room/\+(.+)\.(?:atom)$',RoomAtomTagFeed()), + (r'^room/\+(.+)\.(?:rss)$',RoomRSSTagField()), (r'^room/\+(.+)$','meetingtools.apps.room.views.list_by_tag'), # Uncomment the admin/doc line below to enable admin documentation: # (r'^admin/doc/', include('django.contrib.admindocs.urls')), diff --git a/src/templates/apps/room/atom.xml b/src/templates/apps/room/atom.xml deleted file mode 100644 index 17b36dd..0000000 --- a/src/templates/apps/room/atom.xml +++ /dev/null @@ -1,20 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -{% load prefix %} -<feed xmlns="http://www.w3.org/2005/Atom"> - <title>{{title}}</title> - <updated>{{rfc3339_date}}</updated> - <link rel="self" type="application/atom+xml" href="{{baseurl}}/room/+{{tags}}.atom"/> - <link href="{{baseurl}}/room/+{{tags}}"/> - {% if rooms %} - {% for room in rooms %} - <entry> - <title>{{room.name}}</title> - {% if room.description %} - <summary>{{room.description}}</summary> - {% endif %} - <link href="{{room.url}}"/> - <updated>{{room.updated}}</updated> - </entry> - {% endfor %} - {% endif %} -</feed>
\ No newline at end of file diff --git a/src/templates/apps/room/list.html b/src/templates/apps/room/list.html index 6900a6d..f529650 100644 --- a/src/templates/apps/room/list.html +++ b/src/templates/apps/room/list.html @@ -17,6 +17,7 @@ {% block meta %} {% if tags %} <link rel="alternate" type="application/rss+xml" title="{{title}} (RSS 2.0)" href="{% prefix %}/room/+{{tags}}.rss" /> +<link rel="alternate" type="application/atom+xml" title="{{title}} (ATOM 1.0)" href="{% prefix %}/room/+{{tags}}.atom" /> {% endif %} {% endblock %} {% block content %} diff --git a/src/templates/apps/room/rss2.xml b/src/templates/apps/room/rss2.xml deleted file mode 100644 index 24a3189..0000000 --- a/src/templates/apps/room/rss2.xml +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -{% load prefix %} -<rss version="2.0" - xmlns:atom="http://www.w3.org/2005/Atom" - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:content="http://purl.org/rss/1.0/modules/content/"> - <channel> - <title>{{title}}</title> - <description>{{description}}</description> - <!-- {{tags}} --> - <lastBuildDate>{{rfc822_date}}</lastBuildDate> - <link>{{baseurl}}/room/+{{tags}}</link> - <atom:link rel="self" type="application/rss+xml" href="{{baseurl}}/room/+{{tags}}.rss"/> - {% if rooms %} - {% for room in rooms %} - <item> - <title>{{room.name}}</title> - {% if room.description %} - <description>{{room.description}}</description> - {% endif %} - <link>{{room.url}}</link> - </item> - {% endfor %} - {% endif %} - </channel> -</rss>
\ No newline at end of file |