feeds.py 1.29 KB
Newer Older
1 2 3 4 5 6 7 8 9
from django.contrib.syndication.views import Feed
from django.urls import reverse
from rp.models import Article

class ArticlesFeed(Feed):
    title = "Revue de presse de la Quadrature"
    link = "/feed/"
    description = "La revue de presse recense les articles de presse relatifs aux sujets de la Quadrature. Elle est compilée chaque jour par ses bénévoles, à partir de la presse francophone et internationale. Bonne lecture !"

10 11 12
    def __init__(self, **kwargs):
        self.filter_lang = kwargs['filter_lang']

13
    def items(self):
14
        return Article.objects.filter(lang=self.filter_lang) \
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
                              .order_by('-created_at')[:25]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.extracts

    def item_link(self, item):
        return item.url

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

    def item_updateddate(self, item):
        return item.updated_at

    def item_categories(self, item):
        return item.tags.all()
34 35 36 37 38 39 40 41 42 43

class ArticlesTagsFeed(ArticlesFeed):
    def __init__(self, **kwargs):
        pass

    def items(self):
        return Article.objects.filter(tags__name__in=[self.filter_tag])[:25]

    def get_object(self, request, filter_tag):
        self.filter_tag = filter_tag