~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to news/feeds.py

  • Committer: franku
  • Date: 2016-12-13 18:28:51 UTC
  • mto: This revision was merged to the branch mainline in revision 443.
  • Revision ID: somal@arcor.de-20161213182851-bo5ebf8pdvw5beua
run the script

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from django.contrib.syndication.views import Feed, FeedDoesNotExist
2
2
from django.core.exceptions import ObjectDoesNotExist
3
 
from django.urls import reverse
 
3
from django.core.urlresolvers import reverse
4
4
from news.models import Post, Category
5
5
 
6
6
# Validated through http://validator.w3.org/feed/
21
21
 
22
22
    def item_pubdate(self, item):
23
23
        return item.publish
 
24
 
 
25
# Currently not used / not checked for compatibility for django 1.8
 
26
 
 
27
 
 
28
class NewsPostsByCategory(Feed):
 
29
    title = 'Widelands.org posts category feed'
 
30
 
 
31
    def get_object(self, bits):
 
32
        if len(bits) != 1:
 
33
            raise ObjectDoesNotExist
 
34
        return Category.objects.get(slug__exact=bits[0])
 
35
 
 
36
    def link(self, item):
 
37
        if not item:
 
38
            raise FeedDoesNotExist
 
39
        return item.get_absolute_url()
 
40
 
 
41
    def description(self, item):
 
42
        return 'Posts recently categorized as %s' % item.title
 
43
 
 
44
    def items(self, item):
 
45
        return item.post_set.published()[:10]