Commits

Ratnadeep Debnath committed a2bb7a7

Added rss for user activities in user's public profile page.

Comments (0)

Files changed (5)

transifex/simpleauth/feeds.py

+from django.core.exceptions import ObjectDoesNotExist
+from django.conf import settings
+from django.contrib.syndication.feeds import Feed, FeedDoesNotExist
+from django.contrib.sites.models import Site
+from django.shortcuts import get_object_or_404
+from django.utils.translation import ugettext_lazy as _
+from django.contrib.auth.models import User
+from django.core.urlresolvers import reverse
+
+from transifex.actionlog.models import LogEntry
+import re
+
+current_site = Site.objects.get_current()
+
+class UserFeed(Feed):
+    def get_object(self, bits):
+        if len(bits) !=1:
+            raise ObjectDoesNotExist
+        return get_object_or_404(User, username__exact=bits[0])
+
+    def title(self, obj):
+        return _("Recent activities by %(user)s" % {'user': obj.username })
+
+    def description(self, obj):
+        return _("Recent activities by user %s."%obj.username)
+
+    def link(self, obj):
+        if not obj:
+            raise FeedDoesNotExist
+        return reverse('profile_public', args=[obj.username])
+
+    def items(self, obj):
+        return LogEntry.objects.by_user_and_public_projects(obj)
+
+    def item_title(self, item):
+        return _(item.action_type.display)
+
+    def item_link(self, item):
+        match = re.search(r'href=[\'"]?([^\'" >]+)', item.message)
+        if match:
+            return match.group(1)
+
+    def item_description(self, item):
+        return _(item.message)
+

transifex/simpleauth/views.py

 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.views import (logout as auth_logout,
                                        login as auth_login)
+from django.contrib.syndication.views import feed
 
 from transifex.simpleauth.forms import RememberMeAuthForm
 from transifex.simpleauth.util import clean_next
                   {'user': user,},
                   context_instance=RequestContext(request))
 
+def user_feed(request, username, slug=None, param='', feed_dict=None):
+    param = '%s'%(username)
+    if slug:
+        url = "%s/%s" % (slug, param)
+    else:
+        url = param
+    return feed(request, url, feed_dict)
+

transifex/templates/simpleauth/profile_public.html

 
 {% block title %}{{ block.super }} | {% trans "Profile" %} | {{ user }} {% endblock %}
 {% block breadcrumb %}{% homelink %} » {% trans "Profile" %} » {{ user }} {% endblock %}
-
+{% block extra_head %}
+<link rel="alternate" type="application/rss+xml"
+    title="User Activity | Activities by {{ user }}"
+    href= "{% url user_feed user %}" />
+{% endblock %}
 {% block content_title %}
 <h2 class="pagetitle">{% blocktrans %}Public profile of {{ user }}{% endblocktrans %}</h2>
 {% endblock %}
 
+{% block content_sec %}
+  <a class="simlink" href="{% url user_feed user %}" title="Recent activities by {{ user }}"><img border="0" src="{{ STATIC_URL }}images/icons/feed.png" /></a>
+{% endblock %}
 
 {% block content %}
 <div id="settings-intro">

transifex/templates/userprofile/profile/public.html

     </script>
     {% endif %}
 {% endblock %}
+{% block extra_head %}
+<link rel="alternate" type="application/rss+xml"
+    title="User Activity | Activities by {{profile.user}}"
+    href="{% url user_feed profile.user %}" />
+{% endblock %}
 
 {% block breadcrumb %}{% homelink %} &raquo; {% trans "Profile" %} &raquo; {{ profile.user }}{% endblock %}
 
 <h2 class="pagetitle">{% blocktrans with profile.user as user %}Public profile of {{ user }}{% endblocktrans %}</h2>
 {% endblock %}
 
+{% block content_sec %}
+  <a class="simlink" href="{% url user_feed profile.user %}" title="Recent activities by {{ profile.user }}"><img border="0" src="{{ STATIC_URL }}images/icons/feed.png" /></a>
+{% endblock %}
+
 {% block userprofile_content %}
     <div class="vcard public_profile">
         {% if profile.latitude and profile.longitude %}

transifex/urls.py

 from django.conf import settings
 from django.contrib import admin
 import authority
+from transifex.simpleauth.feeds import UserFeed
 
 # Overriding 500 error handler
 handler500 = 'views.server_error'
         url(r'^contact/', include('contact_form.urls'), name='contact'),
     )
 
+feeds = {'user': UserFeed}
+urlpatterns += patterns('',
+        url(
+        regex = r'^accounts/profile/(?P<username>.+)/feed/$',
+        view = 'simpleauth.views.user_feed',
+        name = 'user_feed',
+        kwargs = {'feed_dict': feeds, 'slug': 'user'})
+    )
+
 if settings.ENABLE_SIMPLEAUTH:
     urlpatterns += patterns('',
         url(r'^accounts/', include('simpleauth.urls')),)
         url(r'^accounts/', include('userprofile.urls')),
     )
 
+
 if settings.ENABLE_NOTICES:
     urlpatterns += patterns('',
         (r'^notices/', include('notification.urls')),