/usr/lib/python2.7/dist-packages/notification/feeds.py is in python-django-notification 0.1.5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | from datetime import datetime
from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.sites.models import Site
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from django.template.defaultfilters import linebreaks, escape, striptags
from django.utils.translation import ugettext_lazy as _
from notification.models import Notice
from notification.atomformat import Feed
ITEMS_PER_FEED = getattr(settings, 'ITEMS_PER_FEED', 20)
DEFAULT_HTTP_PROTOCOL = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http")
class BaseNoticeFeed(Feed):
def item_id(self, notification):
return "%s://%s%s" % (
DEFAULT_HTTP_PROTOCOL,
Site.objects.get_current().domain,
notification.get_absolute_url(),
)
def item_title(self, notification):
return striptags(notification.message)
def item_updated(self, notification):
return notification.added
def item_published(self, notification):
return notification.added
def item_content(self, notification):
return {"type" : "html", }, linebreaks(escape(notification.message))
def item_links(self, notification):
return [{"href" : self.item_id(notification)}]
def item_authors(self, notification):
return [{"name" : notification.user.username}]
class NoticeUserFeed(BaseNoticeFeed):
def get_object(self, params):
return get_object_or_404(User, username=params[0].lower())
def feed_id(self, user):
return "%s://%s%s" % (
DEFAULT_HTTP_PROTOCOL,
Site.objects.get_current().domain,
reverse('notification_feed_for_user'),
)
def feed_title(self, user):
return _('Notices Feed')
def feed_updated(self, user):
qs = Notice.objects.filter(user=user)
# We return an arbitrary date if there are no results, because there
# must be a feed_updated field as per the Atom specifications, however
# there is no real data to go by, and an arbitrary date can be static.
if qs.count() == 0:
return datetime(year=2008, month=7, day=1)
return qs.latest('added').added
def feed_links(self, user):
complete_url = "%s://%s%s" % (
DEFAULT_HTTP_PROTOCOL,
Site.objects.get_current().domain,
reverse('notification_notices'),
)
return ({'href': complete_url},)
def items(self, user):
return Notice.objects.notices_for(user).order_by("-added")[:ITEMS_PER_FEED]
|