~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to notification/feeds.py

  • Committer: franku
  • Author(s): GunChleoc
  • Date: 2016-12-13 18:30:38 UTC
  • mfrom: (438.1.6 pyformat_util)
  • Revision ID: somal@arcor.de-20161213183038-5cgmvfh2fkgmoc1s
adding a script to run pyformat over the code base

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
ITEMS_PER_FEED = getattr(settings, 'ITEMS_PER_FEED', 20)
15
15
 
 
16
 
16
17
class BaseNoticeFeed(Feed):
 
18
 
17
19
    def item_id(self, notification):
18
 
        return "http://%s%s" % (
 
20
        return 'http://%s%s' % (
19
21
            Site.objects.get_current().domain,
20
22
            notification.get_absolute_url(),
21
23
        )
22
 
    
 
24
 
23
25
    def item_title(self, notification):
24
26
        return striptags(notification.message)
25
 
    
 
27
 
26
28
    def item_updated(self, notification):
27
29
        return notification.added
28
 
    
 
30
 
29
31
    def item_published(self, notification):
30
32
        return notification.added
31
 
    
 
33
 
32
34
    def item_content(self, notification):
33
 
        return {"type" : "html", }, linebreaks(escape(notification.message))
34
 
    
 
35
        return {'type': 'html', }, linebreaks(escape(notification.message))
 
36
 
35
37
    def item_links(self, notification):
36
 
        return [{"href" : self.item_id(notification)}]
37
 
    
 
38
        return [{'href': self.item_id(notification)}]
 
39
 
38
40
    def item_authors(self, notification):
39
 
        return [{"name" : notification.user.username}]
 
41
        return [{'name': notification.user.username}]
 
42
 
40
43
 
41
44
class NoticeUserFeed(BaseNoticeFeed):
 
45
 
42
46
    def get_object(self, params):
43
47
        return get_object_or_404(User, username=params[0].lower())
44
48
 
45
49
    def feed_id(self, user):
46
 
        return "http://%s%s" % (
47
 
                Site.objects.get_current().domain,
48
 
                reverse('notification_feed_for_user'),
49
 
            )
 
50
        return 'http://%s%s' % (
 
51
            Site.objects.get_current().domain,
 
52
            reverse('notification_feed_for_user'),
 
53
        )
50
54
 
51
55
    def feed_title(self, user):
52
56
        return _('Notices Feed')
61
65
        return qs.latest('added').added
62
66
 
63
67
    def feed_links(self, user):
64
 
        complete_url = "http://%s%s" % (
65
 
                Site.objects.get_current().domain,
66
 
                reverse('notification_notices'),
67
 
            )
 
68
        complete_url = 'http://%s%s' % (
 
69
            Site.objects.get_current().domain,
 
70
            reverse('notification_notices'),
 
71
        )
68
72
        return ({'href': complete_url},)
69
73
 
70
74
    def items(self, user):
71
 
        return Notice.objects.notices_for(user).order_by("-added")[:ITEMS_PER_FEED]
 
75
        return Notice.objects.notices_for(user).order_by('-added')[:ITEMS_PER_FEED]