~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to pybb/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:
4
4
from django.utils.feedgenerator import Atom1Feed
5
5
from pybb.models import Post, Topic, Forum
6
6
 
 
7
 
7
8
class PybbFeed(Feed):
8
9
    feed_type = Atom1Feed
9
10
 
10
 
    def title(self,obj):
 
11
    def title(self, obj):
11
12
        if obj == self.all_objects:
12
13
            return self.all_title
13
14
        else:
14
15
            return self.one_title % obj.name
15
 
        
 
16
 
16
17
    def items(self, obj):
17
18
        if obj == self.all_objects:
18
19
            return obj.order_by('-created')[:15]
19
20
        else:
20
21
            return self.items_for_object(obj)
21
 
        
 
22
 
22
23
    def link(self, obj):
23
24
        if obj == self.all_objects:
24
25
            return reverse('pybb_index')
25
 
        return "/ewfwevw%s" % reverse('pybb_forum', args=(obj.pk,))
 
26
        return '/ewfwevw%s' % reverse('pybb_forum', args=(obj.pk,))
26
27
 
27
 
    def get_object(self,request, *args, **kwargs):
28
 
        """
29
 
        Implement getting feeds for a specific subforum
30
 
        """
 
28
    def get_object(self, request, *args, **kwargs):
 
29
        """Implement getting feeds for a specific subforum."""
31
30
        if not 'topic_id' in kwargs:
32
31
            # Latest Posts/Topics on all forums
33
32
            return self.all_objects
34
33
        else:
35
34
            # Latest Posts/Topics for specific Forum
36
35
            try:
37
 
                forum=Forum.objects.get(pk=int(kwargs['topic_id']))
 
36
                forum = Forum.objects.get(pk=int(kwargs['topic_id']))
38
37
                return forum
39
38
            except ValueError:
40
39
                pass
41
40
        raise ObjectDoesNotExist
42
 
    
43
 
    # Must be used for valid Atom feeds    
 
41
 
 
42
    # Must be used for valid Atom feeds
44
43
    def item_updateddate(self, obj):
45
44
        return obj.created
46
 
    
 
45
 
47
46
    def item_link(self, item):
48
47
        return item.get_absolute_url()
49
48
 
50
49
# Validated through http://validator.w3.org/feed/
 
50
 
 
51
 
51
52
class LastPosts(PybbFeed):
52
53
    all_title = 'Latest posts on all forums'
53
54
    one_title = 'Latest posts on forum %s'
56
57
 
57
58
    all_objects = Post.objects.filter(hidden=False)
58
59
 
59
 
    def items_for_object(self,obj):
60
 
        return Post.objects.filter( hidden = False, topic__forum = obj ).order_by('-created')[:15]
 
60
    def items_for_object(self, obj):
 
61
        return Post.objects.filter(hidden=False, topic__forum=obj).order_by('-created')[:15]
61
62
 
62
63
    def item_author_name(self, item):
63
 
        """
64
 
        Takes the object returned by get_object and returns the feeds's
65
 
        auhor's name as a Python string
66
 
        """
 
64
        """Takes the object returned by get_object and returns the feeds's
 
65
        auhor's name as a Python string."""
67
66
        return item.user.username
68
67
 
69
68
# Validated through http://validator.w3.org/feed/
 
69
 
 
70
 
70
71
class LastTopics(PybbFeed):
71
72
    all_title = 'Latest topics on all forums'
72
73
    one_title = 'Latest topics on forum %s'
73
74
    title_template = 'pybb/feeds/topics_title.html'
74
75
    description_template = 'pybb/feeds/topics_description.html'
75
 
    
76
 
    all_objects = Topic.objects.exclude(posts__hidden = True)
77
 
 
78
 
    def items_for_object(self,item):
79
 
        return Topic.objects.exclude( posts__hidden = True ).filter( forum = item ).order_by('-created')[:15]
 
76
 
 
77
    all_objects = Topic.objects.exclude(posts__hidden=True)
 
78
 
 
79
    def items_for_object(self, item):
 
80
        return Topic.objects.exclude(posts__hidden=True).filter(forum=item).order_by('-created')[:15]
80
81
 
81
82
    def item_author_name(self, item):
82
 
        """
83
 
        Takes the object returned by get_object and returns the feeds's
84
 
        auhor's name as a Python string
85
 
        """
 
83
        """Takes the object returned by get_object and returns the feeds's
 
84
        auhor's name as a Python string."""
86
85
        return item.user.username
87