feeds.py 3.05 KB
Newer Older
1
from django.conf import settings
2
from django.contrib.syndication.views import Feed, FeedDoesNotExist
3
from django.urls import reverse
4
from django.utils.translation import ugettext_lazy as _
5

6 7
from languages.models import Language
from teams.models import Team
8
from vertimus.models import Action, ActionArchived
9

10 11 12 13

class LatestActionsByLanguage(Feed):
    title_template = 'feeds/actions_title.html'
    description_template = 'feeds/actions_description.html'
14

15 16
    def get_object(self, request, locale):
        return Language.objects.get(locale=locale)
17 18

    def title(self, obj):
19
        return _("%(site)s — Workflow actions for the %(lang)s language") % {
20
                  'site': settings.SITE_DOMAIN, 'lang': obj.name }
21 22 23 24 25 26 27

    def link(self, obj):
        if not obj:
            raise FeedDoesNotExist
        return obj.get_team_url()

    def description(self, obj):
28
        return _("Latest actions of the GNOME Translation Project for the %s language") % obj.name
29 30

    def items(self, obj):
31 32 33 34 35
        actions = Action.objects.filter(state_db__language=obj.id).select_related('state_db'
            ).union(
            ActionArchived.objects.filter(state_db__language=obj.id).defer('sequence').select_related('state_db')
        )
        return actions.order_by('-created')[:20]
36 37

    def item_link(self, item):
38 39 40 41 42 43
        link = reverse('vertimus_by_names', args=(
            item.state_db.branch.module.name,
            item.state_db.branch.name,
            item.state_db.domain.name,
            item.state_db.language.locale,
        ))
44
        return "%s#%d" % (link, item.id)
45 46 47 48 49 50 51 52 53 54 55 56

    def item_pubdate(self, item):
        return item.created

    def item_author_name(self, item):
        return item.person


class LatestActionsByTeam(Feed):
    title_template = 'feeds/actions_title.html'
    description_template = 'feeds/actions_description.html'

57 58
    def get_object(self, request, team_name):
        return Team.objects.get(name=team_name)
59 60

    def title(self, obj):
61
        return _("%(site)s — Workflow actions of the %(lang)s team") % {
62
                  'site': settings.SITE_DOMAIN, 'lang': obj}
63 64 65 66 67 68 69

    def link(self, obj):
        if not obj:
            raise FeedDoesNotExist
        return obj.get_absolute_url()

    def description(self, obj):
70
        return _("Latest actions made by the %s team of the GNOME Translation Project") % obj
71 72

    def items(self, obj):
73 74 75 76 77
        actions = Action.objects.filter(state_db__language__team=obj.id).select_related('state_db'
            ).union(
            ActionArchived.objects.filter(state_db__language__team=obj.id).defer('sequence').select_related('state_db')
        )
        return actions.order_by('-created')[:20]
78 79

    def item_link(self, item):
80 81 82 83 84 85
        link = reverse('vertimus_by_names', args=(
            item.state_db.branch.module.name,
            item.state_db.branch.name,
            item.state_db.domain.name,
            item.state_db.language.locale,
        ))
86
        return "%s#%d" % (link, item.id)
87 88 89 90 91 92

    def item_pubdate(self, item):
        return item.created

    def item_author_name(self, item):
        return item.person