Commits

Anonymous committed 98a928a

RSS feed for language-release page (statistics)

Need to also add this for other similar stat pages as well.

Comments (0)

Files changed (6)

languages/feeds.py

+from django.core.exceptions import ObjectDoesNotExist
 from django.conf import settings
+from django.shortcuts import get_object_or_404
 from django.utils.translation import ugettext_lazy as _
 from django.contrib.syndication.feeds import Feed
 from django.contrib.sites.models import Site
+from txcollections.models import Collection, CollectionRelease as Release
+from translations.models import POFile
 from models import Language
-
+current_site = Site.objects.get_current()
 
 class AllLanguages(Feed):
     current_site = Site.objects.get_current()
 
     def items(self):
         return Language.objects.all()
+
+class LanguageReleaseFeed(Feed):
+
+    def get_object(self, bits):
+        if len(bits) != 3:
+            raise ObjectDoesNotExist
+        language_slug, collection_slug, release_slug = bits
+        self.collection = get_object_or_404(Collection, 
+                                            slug__exact=collection_slug)
+        self.release = get_object_or_404(Release, slug__exact=release_slug,
+                                         collection=self.collection)
+        return Language.objects.get(code__exact=bits[0])
+
+    def title(self, obj):
+        return _("%(site_name)s: %(language)s :: %(collection)s :: "
+                 "%(release)s release") % {'site_name': current_site.name,
+                                   'language': obj.name,
+                                   'collection': self.collection.name,
+                                   'release': self.release.name,}
+
+    def description(self, obj):
+        return _("Latest translations in %s.") % obj.name
+
+    def link(self, obj):
+        if not obj:
+            raise FeedDoesNotExist
+        return obj.get_absolute_url()
+
+    def items(self, obj):
+        return POFile.objects.by_language_and_release(obj, self.release)[:100]
+
+    def item_link(self, item):
+        return item.object.get_absolute_url()

languages/templates/feeds/language_release_description.html

+{% load i18n %}
+
+<ul>
+  <li>{% trans "Translated:" %} {{ obj.trans }} ({{ obj.trans_perc }}%)</li>
+  <li>{% trans "Fuzzy:" %} {{ obj.fuzzy }}</li>
+  <li>{% trans "Untranslated:" %} {{ obj.untrans }}</li>
+  <li>{% trans "Total:" %} {{ obj.total }}</li>
+</ul>

languages/templates/feeds/language_release_title.html

+{{ obj.object.project.name}}: {{ obj.object.name }}

languages/urls.py

 from django.conf.urls.defaults import *
 from django.contrib import admin
 from models import Language
-from feeds import AllLanguages
-from views import language_detail, slug_feed, language_release
+from feeds import AllLanguages, LanguageReleaseFeed
+from views import (language_detail, slug_feed,
+                   language_release, language_release_feed)
 
 admin.autodiscover()
 
 feeds = {
     'all': AllLanguages,
+    'language_release': LanguageReleaseFeed,
 }
 
 #TODO: Temporary until we import view from a common place
         name = 'languages_latest_feed',
         kwargs = {'feed_dict': feeds,
                   'slug': 'all'}),
+    url(
+        regex = '^(?P<language_slug>[-_@\w]+)/collection/(?P<collection_slug>[-\w]+)/(?P<release_slug>[-\w]+)/feed/$',
+        view = language_release_feed,
+        name = 'language_release_feed',
+        kwargs = {'feed_dict': feeds,
+                  'slug': 'language_release'}),
 )
 
 

languages/views.py

     return feed(request, url, feed_dict)
 
 
+def language_release_feed(request,
+                          language_slug, collection_slug, release_slug,
+                          slug=None, param='', feed_dict=None,):
+    param = '%s/%s/%s' % (language_slug, collection_slug, release_slug)
+    if slug:
+        url = "%s/%s" % (slug, param)
+    else:
+        url = param
+    return feed(request, url, feed_dict)
+
+
 def language_detail(request, slug, *args, **kwargs):
     language = get_object_or_404(Language, code__iexact=slug)
     pofile_list = POFile.objects.by_language(language)
                          'collection_list': Collection.objects.all()},
         *args, **kwargs
     )
-language_detail.__doc__ = list_detail.object_detail.__doc__
+
 
 def language_release(request, slug, collection_slug, release_slug):
 

templates/languages/language_release.html

 
 {% block breadcrumb %}{{ block.super }} &raquo; <a href="{% url language_detail language.code %}">{{ language.name }}</a> &raquo; {{ release.name }}{% endblock %}
 
+{% block body_sec %}
+  <a class="simlink" href="{% url language_release_feed language_slug=language.code collection_slug=release.collection.slug release_slug=release.slug %}" title="Statistics feed for this language and release"><img border="0" src="{{ MEDIA_URL }}/images/icons/feed.png" /></a>
+{% endblock %}
+
 {% block content_title %}<h2 class="pagetitle">{{ language.name }}<sup class="entry_metalink">{{ release.name }}</sup></h2>{% endblock %}
 
 {% block body_main %}