~widelands-dev/widelands-website/trunk

404.2.7 by franku
updated pip_requirements.text; more conversion on generic views
1
from django.contrib.syndication.views import Feed
489.1.13 by franku
django.conf.urlresolvers -> django.urls
2
from django.urls import reverse
133 by Holger Rapp
Each subforum has now it's own RSS feed
3
from django.core.exceptions import ObjectDoesNotExist
404.2.20 by franku
Activated feeds for pybb; cleanups
4
from django.utils.feedgenerator import Atom1Feed
133 by Holger Rapp
Each subforum has now it's own RSS feed
5
from pybb.models import Post, Topic, Forum
497.2.10 by franku
use the deleted username also for feeds; removed useless functions from feeds
6
from django.conf import settings
22 by Holger Rapp
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(
7
438.1.6 by franku
run the script
8
22 by Holger Rapp
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(
9
class PybbFeed(Feed):
10
    feed_type = Atom1Feed
367 by Holger Rapp
Made feeds a bit more solid against wrong requests.
11
438.1.6 by franku
run the script
12
    def title(self, obj):
133 by Holger Rapp
Each subforum has now it's own RSS feed
13
        if obj == self.all_objects:
14
            return self.all_title
15
        else:
16
            return self.one_title % obj.name
438.1.6 by franku
run the script
17
133 by Holger Rapp
Each subforum has now it's own RSS feed
18
    def items(self, obj):
19
        if obj == self.all_objects:
20
            return obj.order_by('-created')[:15]
367 by Holger Rapp
Made feeds a bit more solid against wrong requests.
21
        else:
133 by Holger Rapp
Each subforum has now it's own RSS feed
22
            return self.items_for_object(obj)
438.1.6 by franku
run the script
23
209.1.46 by Timo Wingender
Fix feeds for forum and wiki: add author name for atom feeds and fix id for forum feeds
24
    def link(self, obj):
133 by Holger Rapp
Each subforum has now it's own RSS feed
25
        if obj == self.all_objects:
26
            return reverse('pybb_index')
438.1.6 by franku
run the script
27
        return '/ewfwevw%s' % reverse('pybb_forum', args=(obj.pk,))
367 by Holger Rapp
Made feeds a bit more solid against wrong requests.
28
438.1.6 by franku
run the script
29
    def get_object(self, request, *args, **kwargs):
30
        """Implement getting feeds for a specific subforum."""
404.2.20 by franku
Activated feeds for pybb; cleanups
31
        if not 'topic_id' in kwargs:
32
            # Latest Posts/Topics on all forums
404.2.19 by franku
first try on pybb feeds; not ready
33
            return self.all_objects
404.2.20 by franku
Activated feeds for pybb; cleanups
34
        else:
35
            # Latest Posts/Topics for specific Forum
404.2.19 by franku
first try on pybb feeds; not ready
36
            try:
438.1.6 by franku
run the script
37
                forum = Forum.objects.get(pk=int(kwargs['topic_id']))
404.2.19 by franku
first try on pybb feeds; not ready
38
                return forum
39
            except ValueError:
40
                pass
41
        raise ObjectDoesNotExist
438.1.6 by franku
run the script
42
43
    # Must be used for valid Atom feeds
404.2.20 by franku
Activated feeds for pybb; cleanups
44
    def item_updateddate(self, obj):
22 by Holger Rapp
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(
45
        return obj.created
438.1.6 by franku
run the script
46
404.2.20 by franku
Activated feeds for pybb; cleanups
47
    def item_link(self, item):
48
        return item.get_absolute_url()
49
50
# Validated through http://validator.w3.org/feed/
438.1.6 by franku
run the script
51
52
22 by Holger Rapp
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(
53
class LastPosts(PybbFeed):
404.2.18 by franku
News and wiki feeds again, validated through w3c; cleanups
54
    all_title = 'Latest posts on all forums'
404.2.20 by franku
Activated feeds for pybb; cleanups
55
    one_title = 'Latest posts on forum %s'
22 by Holger Rapp
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(
56
    title_template = 'pybb/feeds/posts_title.html'
57
    description_template = 'pybb/feeds/posts_description.html'
367 by Holger Rapp
Made feeds a bit more solid against wrong requests.
58
528.1.5 by franku
refactored name of manager; fixed ordering
59
    all_objects = Post.objects.public()
504.2.5 by franku
implement hide/unhide toggling of topics
60
438.1.6 by franku
run the script
61
    def items_for_object(self, obj):
528.1.2 by franku
use the new model manager for feeds
62
        # Latest posts for forum 'xy'
528.1.5 by franku
refactored name of manager; fixed ordering
63
        return Post.objects.public(limit=15)
22 by Holger Rapp
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(
64
404.2.20 by franku
Activated feeds for pybb; cleanups
65
# Validated through http://validator.w3.org/feed/
438.1.6 by franku
run the script
66
67
22 by Holger Rapp
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(
68
class LastTopics(PybbFeed):
404.2.18 by franku
News and wiki feeds again, validated through w3c; cleanups
69
    all_title = 'Latest topics on all forums'
70
    one_title = 'Latest topics on forum %s'
22 by Holger Rapp
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(
71
    title_template = 'pybb/feeds/topics_title.html'
72
    description_template = 'pybb/feeds/topics_description.html'
438.1.6 by franku
run the script
73
512.1.9 by franku
don't show internal topics/post in feeds; show group to admin/pybb/forumslist
74
    all_objects = Topic.objects.exclude(
75
        forum__category__internal=True).exclude(posts__hidden=True)
438.1.6 by franku
run the script
76
77
    def items_for_object(self, item):
512.1.11 by franku
added comments
78
        # Latest topics on forum 'xy'
512.1.9 by franku
don't show internal topics/post in feeds; show group to admin/pybb/forumslist
79
        return Topic.objects.exclude(
80
            forum__category__internal=True).exclude(
81
            posts__hidden=True).filter(forum=item).order_by('-created')[:15]