summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-06-26 23:19:03 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-06-26 23:19:03 +0000
commite923ed2a83a08ba2db7347e5d467f26949fa4877 (patch)
tree7dcf669a96b7b3bba98b92f9c7fc104ac62388b3
parent6dc719312df548dd5766b79b1e4c947c54285b93 (diff)
Fixed #2158 -- Added title_template and description_template hooks to Feed class in syndication framework.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3214 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/syndication/feeds.py16
-rw-r--r--docs/syndication_feeds.txt14
2 files changed, 23 insertions, 7 deletions
diff --git a/django/contrib/syndication/feeds.py b/django/contrib/syndication/feeds.py
index 3deefc5866..e648c6c746 100644
--- a/django/contrib/syndication/feeds.py
+++ b/django/contrib/syndication/feeds.py
@@ -16,10 +16,14 @@ class Feed(object):
item_pubdate = None
item_enclosure_url = None
feed_type = feedgenerator.DefaultFeed
+ title_template = None
+ description_template = None
def __init__(self, slug, feed_url):
self.slug = slug
self.feed_url = feed_url
+ self.title_template_name = self.title_template or ('feeds/%s_title.html' % slug)
+ self.description_template_name = self.description_template or ('feeds/%s_description.html' % slug)
def item_link(self, item):
try:
@@ -77,13 +81,13 @@ class Feed(object):
)
try:
- title_template = loader.get_template('feeds/%s_title.html' % self.slug)
+ title_tmp = loader.get_template(self.title_template_name)
except TemplateDoesNotExist:
- title_template = Template('{{ obj }}')
+ title_tmp = Template('{{ obj }}')
try:
- description_template = loader.get_template('feeds/%s_description.html' % self.slug)
+ description_tmp = loader.get_template(self.description_template_name)
except TemplateDoesNotExist:
- description_template = Template('{{ obj }}')
+ description_tmp = Template('{{ obj }}')
for item in self.__get_dynamic_attr('items', obj):
link = add_domain(current_site.domain, self.__get_dynamic_attr('item_link', item))
@@ -102,9 +106,9 @@ class Feed(object):
else:
author_email = author_link = None
feed.add_item(
- title = title_template.render(Context({'obj': item, 'site': current_site})).decode('utf-8'),
+ title = title_tmp.render(Context({'obj': item, 'site': current_site})).decode('utf-8'),
link = link,
- description = description_template.render(Context({'obj': item, 'site': current_site})).decode('utf-8'),
+ description = description_tmp.render(Context({'obj': item, 'site': current_site})).decode('utf-8'),
unique_id = link,
enclosure = enc,
pubdate = self.__get_dynamic_attr('item_pubdate', item),
diff --git a/docs/syndication_feeds.txt b/docs/syndication_feeds.txt
index 4f77c4ff21..c84785b20b 100644
--- a/docs/syndication_feeds.txt
+++ b/docs/syndication_feeds.txt
@@ -134,7 +134,9 @@ put into those elements.
If you don't create a template for either the title or description, the
framework will use the template ``"{{ obj }}"`` by default -- that is,
- the normal string representation of the object.
+ the normal string representation of the object. You can also change the
+ names of these two templates by specifying ``title_template`` and
+ ``description_template`` as attributes of your ``Feed`` class.
* To specify the contents of ``<link>``, you have two options. For each
item in ``items()``, Django first tries executing a
``get_absolute_url()`` method on that object. If that method doesn't
@@ -342,6 +344,16 @@ This example illustrates all possible attributes and methods for a ``Feed`` clas
feed_type = feedgenerator.Rss201rev2Feed
+ # TEMPLATE NAMES -- Optional. These should be strings representing
+ # names of Django templates that the system should use in rendering the
+ # title and description of your feed items. Both are optional.
+ # If you don't specify one, or either, Django will use the template
+ # 'feeds/SLUG_title.html' and 'feeds/SLUG_description.html', where SLUG
+ # is the slug you specify in the URL.
+
+ title_template = None
+ description_template = None
+
# TITLE -- One of the following three is required. The framework looks
# for them in this order.