Basic Atom feed for user activity

This commit is contained in:
Paul Osman 2010-12-29 17:28:22 -05:00
Родитель 0501285f84
Коммит 7966bef731
3 изменённых файлов: 49 добавлений и 3 удалений

42
apps/activity/feeds.py Normal file
Просмотреть файл

@ -0,0 +1,42 @@
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _
from django.utils.feedgenerator import Atom1Feed
from activity.models import Activity
from users.models import UserProfile
class UserActivityFeed(Feed):
"""Atom feed of user activities."""
feed_type = Atom1Feed
def author_name(self, user):
return user.name
def title(self, user):
return user.name
def subtitle(self, user):
return _('Activity feed for %s' % (user.name,))
def link(self, user):
return reverse('users_profile_view',
kwargs={'username': user.username})
def get_object(self, request, username):
return get_object_or_404(UserProfile, username=username)
def items(self, user):
return Activity.objects.filter(actor=user)[:25]
def item_title(self, item):
return item.verb
def item_description(self, item):
return u"%s activity performed by %s" % (item.verb, item.actor.name)
def item_link(self, item):
return u'http://blah.com'

Просмотреть файл

@ -1,9 +1,13 @@
from django.conf.urls.defaults import patterns, url
from activity.feeds import UserActivityFeed
urlpatterns = patterns('',
url(r'^(?P<activity_id>[\d]+)/', 'activity.views.index',
url(r'^activity/(?P<activity_id>[\d]+)/', 'activity.views.index',
name='activity_index'),
url(r'^delete/$', 'activity.views.delete',
url(r'^activity/delete/$', 'activity.views.delete',
name='activity_delete'),
url(r'^(?P<username>[\w-]+)/feed', UserActivityFeed(),
name='activity_user_feed'),
)

Просмотреть файл

@ -8,7 +8,7 @@ urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
(r'', include('dashboard.urls')),
(r'', include('wellknown.urls')),
(r'^activity/', include('activity.urls')),
(r'', include('activity.urls')),
(r'^statuses/', include('statuses.urls')),
(r'^projects/', include('projects.urls')),
(r'^events/', include('events.urls')),