telemeta.views.feed module
# -*- coding: utf-8 -*- # Copyright (C) 2010-2012 Parisson SARL # This file is part of Telemeta. # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # Authors: Guillaume Pellerin <yomguy@parisson.com> from telemeta.views.core import * class LastestRevisionsFeed(Feed): "the RSS feed of the lastest revisions" organization = settings.TELEMETA_ORGANIZATION subjects = settings.TELEMETA_SUBJECTS tags = ['title', 'description', 'comment'] title = organization.decode('utf8') + ' - Telemeta - ' + ugettext('Last changes') link = "" description = ' '.join([subject.decode('utf-8') for subject in subjects]) n_items = 100 def items(self): return get_revisions(self.n_items) def item_title(self, r): element = r['element'] if element.title == '': title = str(element.public_id) else: title = element.title return element.element_type + ' : ' + title def item_description(self, r): revision = r['revision'] element = r['element'] description = '<b>modified by ' + revision.user.username + ' on ' + unicode(revision.time) + '</b><br /><br />' dict = element.__dict__ for tag in dict.keys(): try: value = dict[tag] if value != '': description += tag + ' : ' + value + '<br />' except: continue return description.encode('utf-8') def item_link(self, r): revision = r['revision'] element = r['element'] if revision.element_type[-1] == 's': dir = revision.element_type else: dir = revision.element_type + 's' link = '/archives/' + dir + '/' + str(element.public_id) return link class UserRevisionsFeed(LastestRevisionsFeed): def get_object(self, request, username): return get_object_or_404(User, username=username) def items(self, obj): return get_revisions(self.n_items, obj)
Module variables
var ITEM_PUBLIC_ACCESS_CHOICES
var ITEM_TRANSODING_STATUS
var PUBLIC_ACCESS_CHOICES
var SCOPE_CHOICES
var TYPE_CHOICES
var app_name
var code_linesep
var collection_code_regex
var collection_published_code_regex
var collection_unpublished_code_regex
var default_decoding
var default_encoding
var engine
var eol
var ext
var item_code_regex
var item_published_code_regex
var item_unpublished_code_regex
var mime_type
var mods
var private_extra_types
var public_extra_types
var resource_code_regex
var strict_code
Classes
class LastestRevisionsFeed
the RSS feed of the lastest revisions
class LastestRevisionsFeed(Feed): "the RSS feed of the lastest revisions" organization = settings.TELEMETA_ORGANIZATION subjects = settings.TELEMETA_SUBJECTS tags = ['title', 'description', 'comment'] title = organization.decode('utf8') + ' - Telemeta - ' + ugettext('Last changes') link = "" description = ' '.join([subject.decode('utf-8') for subject in subjects]) n_items = 100 def items(self): return get_revisions(self.n_items) def item_title(self, r): element = r['element'] if element.title == '': title = str(element.public_id) else: title = element.title return element.element_type + ' : ' + title def item_description(self, r): revision = r['revision'] element = r['element'] description = '<b>modified by ' + revision.user.username + ' on ' + unicode(revision.time) + '</b><br /><br />' dict = element.__dict__ for tag in dict.keys(): try: value = dict[tag] if value != '': description += tag + ' : ' + value + '<br />' except: continue return description.encode('utf-8') def item_link(self, r): revision = r['revision'] element = r['element'] if revision.element_type[-1] == 's': dir = revision.element_type else: dir = revision.element_type + 's' link = '/archives/' + dir + '/' + str(element.public_id) return link
Ancestors (in MRO)
- LastestRevisionsFeed
- django.contrib.syndication.views.Feed
- __builtin__.object
Class variables
var description
var description_template
var feed_type
var link
var n_items
var organization
var subject
var subjects
var title
var title_template
Methods
def feed_extra_kwargs(
self, obj)
Returns an extra keyword arguments dictionary that is used when initializing the feed generator.
def feed_extra_kwargs(self, obj): """ Returns an extra keyword arguments dictionary that is used when initializing the feed generator. """ return {}
def get_context_data(
self, **kwargs)
Returns a dictionary to use as extra context if either
self.description_template
or self.item_template
are used.
Default implementation preserves the old behavior of using {'obj': item, 'site': current_site} as the context.
def get_context_data(self, **kwargs): """ Returns a dictionary to use as extra context if either ``self.description_template`` or ``self.item_template`` are used. Default implementation preserves the old behavior of using {'obj': item, 'site': current_site} as the context. """ return {'obj': kwargs.get('item'), 'site': kwargs.get('site')}
def get_feed(
self, obj, request)
Returns a feedgenerator.DefaultFeed object, fully populated, for this feed. Raises FeedDoesNotExist for invalid parameters.
def get_feed(self, obj, request): """ Returns a feedgenerator.DefaultFeed object, fully populated, for this feed. Raises FeedDoesNotExist for invalid parameters. """ current_site = get_current_site(request) link = self.__get_dynamic_attr('link', obj) link = add_domain(current_site.domain, link, request.is_secure()) feed = self.feed_type( title = self.__get_dynamic_attr('title', obj), subtitle = self.__get_dynamic_attr('subtitle', obj), link = link, description = self.__get_dynamic_attr('description', obj), language = settings.LANGUAGE_CODE, feed_url = add_domain( current_site.domain, self.__get_dynamic_attr('feed_url', obj) or request.path, request.is_secure(), ), author_name = self.__get_dynamic_attr('author_name', obj), author_link = self.__get_dynamic_attr('author_link', obj), author_email = self.__get_dynamic_attr('author_email', obj), categories = self.__get_dynamic_attr('categories', obj), feed_copyright = self.__get_dynamic_attr('feed_copyright', obj), feed_guid = self.__get_dynamic_attr('feed_guid', obj), ttl = self.__get_dynamic_attr('ttl', obj), **self.feed_extra_kwargs(obj) ) title_tmp = None if self.title_template is not None: try: title_tmp = loader.get_template(self.title_template) except TemplateDoesNotExist: pass description_tmp = None if self.description_template is not None: try: description_tmp = loader.get_template(self.description_template) except TemplateDoesNotExist: pass for item in self.__get_dynamic_attr('items', obj): context = self.get_context_data(item=item, site=current_site, obj=obj, request=request) if title_tmp is not None: title = title_tmp.render(RequestContext(request, context)) else: title = self.__get_dynamic_attr('item_title', item) if description_tmp is not None: description = description_tmp.render(RequestContext(request, context)) else: description = self.__get_dynamic_attr('item_description', item) link = add_domain( current_site.domain, self.__get_dynamic_attr('item_link', item), request.is_secure(), ) enc = None enc_url = self.__get_dynamic_attr('item_enclosure_url', item) if enc_url: enc = feedgenerator.Enclosure( url = smart_text(enc_url), length = smart_text(self.__get_dynamic_attr('item_enclosure_length', item)), mime_type = smart_text(self.__get_dynamic_attr('item_enclosure_mime_type', item)) ) author_name = self.__get_dynamic_attr('item_author_name', item) if author_name is not None: author_email = self.__get_dynamic_attr('item_author_email', item) author_link = self.__get_dynamic_attr('item_author_link', item) else: author_email = author_link = None pubdate = self.__get_dynamic_attr('item_pubdate', item) if pubdate and is_naive(pubdate): ltz = tzinfo.LocalTimezone(pubdate) pubdate = pubdate.replace(tzinfo=ltz) feed.add_item( title = title, link = link, description = description, unique_id = self.__get_dynamic_attr('item_guid', item, link), unique_id_is_permalink = self.__get_dynamic_attr( 'item_guid_is_permalink', item), enclosure = enc, pubdate = pubdate, author_name = author_name, author_email = author_email, author_link = author_link, categories = self.__get_dynamic_attr('item_categories', item), item_copyright = self.__get_dynamic_attr('item_copyright', item), **self.item_extra_kwargs(item) ) return feed
def get_object(
self, request, *args, **kwargs)
def get_object(self, request, *args, **kwargs): return None
def item_description(
self, r)
def item_description(self, r): revision = r['revision'] element = r['element'] description = '<b>modified by ' + revision.user.username + ' on ' + unicode(revision.time) + '</b><br /><br />' dict = element.__dict__ for tag in dict.keys(): try: value = dict[tag] if value != '': description += tag + ' : ' + value + '<br />' except: continue return description.encode('utf-8')
def item_extra_kwargs(
self, item)
Returns an extra keyword arguments dictionary that is used with
the add_item
call of the feed generator.
def item_extra_kwargs(self, item): """ Returns an extra keyword arguments dictionary that is used with the `add_item` call of the feed generator. """ return {}
def item_link(
self, r)
def item_link(self, r): revision = r['revision'] element = r['element'] if revision.element_type[-1] == 's': dir = revision.element_type else: dir = revision.element_type + 's' link = '/archives/' + dir + '/' + str(element.public_id) return link
def item_title(
self, r)
def item_title(self, r): element = r['element'] if element.title == '': title = str(element.public_id) else: title = element.title return element.element_type + ' : ' + title
def items(
self)
def items(self): return get_revisions(self.n_items)
class UserRevisionsFeed
class UserRevisionsFeed(LastestRevisionsFeed): def get_object(self, request, username): return get_object_or_404(User, username=username) def items(self, obj): return get_revisions(self.n_items, obj)
Ancestors (in MRO)
- UserRevisionsFeed
- LastestRevisionsFeed
- django.contrib.syndication.views.Feed
- __builtin__.object
Class variables
Inheritance:
LastestRevisionsFeed
.tags
Methods
def feed_extra_kwargs(
self, obj)
Inheritance:
LastestRevisionsFeed
.feed_extra_kwargs
Returns an extra keyword arguments dictionary that is used when initializing the feed generator.
def feed_extra_kwargs(self, obj): """ Returns an extra keyword arguments dictionary that is used when initializing the feed generator. """ return {}
def get_context_data(
self, **kwargs)
Inheritance:
LastestRevisionsFeed
.get_context_data
Returns a dictionary to use as extra context if either
self.description_template
or self.item_template
are used.
Default implementation preserves the old behavior of using {'obj': item, 'site': current_site} as the context.
def get_context_data(self, **kwargs): """ Returns a dictionary to use as extra context if either ``self.description_template`` or ``self.item_template`` are used. Default implementation preserves the old behavior of using {'obj': item, 'site': current_site} as the context. """ return {'obj': kwargs.get('item'), 'site': kwargs.get('site')}
def get_feed(
self, obj, request)
Inheritance:
LastestRevisionsFeed
.get_feed
Returns a feedgenerator.DefaultFeed object, fully populated, for this feed. Raises FeedDoesNotExist for invalid parameters.
def get_feed(self, obj, request): """ Returns a feedgenerator.DefaultFeed object, fully populated, for this feed. Raises FeedDoesNotExist for invalid parameters. """ current_site = get_current_site(request) link = self.__get_dynamic_attr('link', obj) link = add_domain(current_site.domain, link, request.is_secure()) feed = self.feed_type( title = self.__get_dynamic_attr('title', obj), subtitle = self.__get_dynamic_attr('subtitle', obj), link = link, description = self.__get_dynamic_attr('description', obj), language = settings.LANGUAGE_CODE, feed_url = add_domain( current_site.domain, self.__get_dynamic_attr('feed_url', obj) or request.path, request.is_secure(), ), author_name = self.__get_dynamic_attr('author_name', obj), author_link = self.__get_dynamic_attr('author_link', obj), author_email = self.__get_dynamic_attr('author_email', obj), categories = self.__get_dynamic_attr('categories', obj), feed_copyright = self.__get_dynamic_attr('feed_copyright', obj), feed_guid = self.__get_dynamic_attr('feed_guid', obj), ttl = self.__get_dynamic_attr('ttl', obj), **self.feed_extra_kwargs(obj) ) title_tmp = None if self.title_template is not None: try: title_tmp = loader.get_template(self.title_template) except TemplateDoesNotExist: pass description_tmp = None if self.description_template is not None: try: description_tmp = loader.get_template(self.description_template) except TemplateDoesNotExist: pass for item in self.__get_dynamic_attr('items', obj): context = self.get_context_data(item=item, site=current_site, obj=obj, request=request) if title_tmp is not None: title = title_tmp.render(RequestContext(request, context)) else: title = self.__get_dynamic_attr('item_title', item) if description_tmp is not None: description = description_tmp.render(RequestContext(request, context)) else: description = self.__get_dynamic_attr('item_description', item) link = add_domain( current_site.domain, self.__get_dynamic_attr('item_link', item), request.is_secure(), ) enc = None enc_url = self.__get_dynamic_attr('item_enclosure_url', item) if enc_url: enc = feedgenerator.Enclosure( url = smart_text(enc_url), length = smart_text(self.__get_dynamic_attr('item_enclosure_length', item)), mime_type = smart_text(self.__get_dynamic_attr('item_enclosure_mime_type', item)) ) author_name = self.__get_dynamic_attr('item_author_name', item) if author_name is not None: author_email = self.__get_dynamic_attr('item_author_email', item) author_link = self.__get_dynamic_attr('item_author_link', item) else: author_email = author_link = None pubdate = self.__get_dynamic_attr('item_pubdate', item) if pubdate and is_naive(pubdate): ltz = tzinfo.LocalTimezone(pubdate) pubdate = pubdate.replace(tzinfo=ltz) feed.add_item( title = title, link = link, description = description, unique_id = self.__get_dynamic_attr('item_guid', item, link), unique_id_is_permalink = self.__get_dynamic_attr( 'item_guid_is_permalink', item), enclosure = enc, pubdate = pubdate, author_name = author_name, author_email = author_email, author_link = author_link, categories = self.__get_dynamic_attr('item_categories', item), item_copyright = self.__get_dynamic_attr('item_copyright', item), **self.item_extra_kwargs(item) ) return feed
def get_object(
self, request, username)
Inheritance:
LastestRevisionsFeed
.get_object
def get_object(self, request, username): return get_object_or_404(User, username=username)
def item_description(
self, r)
Inheritance:
LastestRevisionsFeed
.item_description
def item_description(self, r): revision = r['revision'] element = r['element'] description = '<b>modified by ' + revision.user.username + ' on ' + unicode(revision.time) + '</b><br /><br />' dict = element.__dict__ for tag in dict.keys(): try: value = dict[tag] if value != '': description += tag + ' : ' + value + '<br />' except: continue return description.encode('utf-8')
def item_extra_kwargs(
self, item)
Inheritance:
LastestRevisionsFeed
.item_extra_kwargs
Returns an extra keyword arguments dictionary that is used with
the add_item
call of the feed generator.
def item_extra_kwargs(self, item): """ Returns an extra keyword arguments dictionary that is used with the `add_item` call of the feed generator. """ return {}
def item_link(
self, r)
Inheritance:
LastestRevisionsFeed
.item_link
def item_link(self, r): revision = r['revision'] element = r['element'] if revision.element_type[-1] == 's': dir = revision.element_type else: dir = revision.element_type + 's' link = '/archives/' + dir + '/' + str(element.public_id) return link
def item_title(
self, r)
Inheritance:
LastestRevisionsFeed
.item_title
def item_title(self, r): element = r['element'] if element.title == '': title = str(element.public_id) else: title = element.title return element.element_type + ' : ' + title
def items(
self, obj)
Inheritance:
LastestRevisionsFeed
.items
def items(self, obj): return get_revisions(self.n_items, obj)