More work on feeds. Next up is activity streams data

This commit is contained in:
Paul Osman 2010-12-29 19:22:06 -05:00
Родитель d959d1f354
Коммит 4bc0175daf
3 изменённых файлов: 28 добавлений и 10 удалений

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

@ -16,6 +16,9 @@ class UserActivityFeed(Feed):
def author_name(self, user): def author_name(self, user):
return user.name return user.name
def author_link(self, user):
return self._request.build_absolute_uri(user.get_absolute_url())
def title(self, user): def title(self, user):
return user.name return user.name
@ -27,16 +30,14 @@ class UserActivityFeed(Feed):
kwargs={'username': user.username}) kwargs={'username': user.username})
def get_object(self, request, username): def get_object(self, request, username):
self._request = request
return get_object_or_404(UserProfile, username=username) return get_object_or_404(UserProfile, username=username)
def items(self, user): def items(self, user):
return Activity.objects.filter(actor=user)[:25] return Activity.objects.filter(actor=user).order_by('-created_on')[:25]
def item_title(self, item): def item_title(self, item):
return item.verb return item
def item_description(self, item):
return u"%s activity performed by %s" % (item.verb, item.actor.name)
def item_link(self, item): def item_link(self, item):
return u'http://blah.com' return self._request.build_absolute_uri(item.get_absolute_url())

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

@ -1,5 +1,8 @@
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _
from drumbeat.models import ModelBase from drumbeat.models import ModelBase
from activity import schema
class RemoteObject(models.Model): class RemoteObject(models.Model):
@ -22,3 +25,20 @@ class Activity(ModelBase):
remote_object = models.ForeignKey(RemoteObject, null=True) remote_object = models.ForeignKey(RemoteObject, null=True)
parent = models.ForeignKey('self', null=True) parent = models.ForeignKey('self', null=True)
created_on = models.DateTimeField(auto_now_add=True) created_on = models.DateTimeField(auto_now_add=True)
@models.permalink
def get_absolute_url(self):
return ('activity_index', (), {
'activity_id': self.pk,
})
def __unicode__(self):
if self.target_user and self.verb == schema.verbs['follow']:
return "%s %s %s" % (
self.actor.name, schema.past_tense['follow'],
self.target_user.name)
if self.status:
return self.status.status
elif self.remote_object:
return self.remote_object.title
return _("%s activity performed by %s") % (self.verb, self.actor.name)

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

@ -4,10 +4,7 @@
{% block title %}{{ profile.name }}{% endblock %} {% block title %}{{ profile.name }}{% endblock %}
{% block links %} {% block links %}
{% comment %} <link rel="alternate" type="application/atom+xml" href="{% locale_url activity_user_feed username=profile.username %}">
Temporarily comment out atom feed link while refactoring activity application.
<link rel="alternate" type="application/atom+xml" href="{% locale_url activity_feed_user username=profile_user.username %}">
{% endcomment %}
<link rel="profile" href="http://microformats.org/profile/hcard" /> <link rel="profile" href="http://microformats.org/profile/hcard" />
{% endblock %} {% endblock %}