summaryrefslogtreecommitdiff
path: root/sublab_project/projects/feeds.py
blob: 33083e45ef9d2bf65be3f08c5c752da8d26ecc17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.utils.html import strip_tags
from django.utils.text import truncate_html_words

from projects.models import Project
from news.feeds import NewsFeed

class ProjectNewsFeed(NewsFeed):
    def get_object(self, *args, **kwargs):
        return get_object_or_404(Project, **kwargs)

    def title(self, obj):
        return 'sublab.org - %s' % obj.name

    def description(self, obj):
        return obj.description

    def link(self, obj):
        return obj.get_absolute_url()

    def items(self, obj):
        return obj.news.all()[:10]

class ProjectNewsFeedAtom(ProjectNewsFeed):
    feed_type = Atom1Feed
    subtitle = ProjectNewsFeed.description

class ProjectFeed(Feed):
    title = "sublab.org projects"
    description = "the latest projects in your sublab"

    def link(self):
        return reverse(self)

    def items(self):
        return Project.objects.order_by('-date_created')[:10]

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

    def item_author_email(self, item):
        return item.contact_email

    def item_description(self, item):
        return strip_tags(truncate_html_words(item.description_html, 100))

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

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

class ProjectFeedAtom(ProjectFeed):
    feed_type = Atom1Feed
    subtitle = ProjectFeed.description