Code

Ticket #2158: syndication.diff

File syndication.diff, 2.2 KB (added by James Wheare, 8 years ago)

Added ability to specify title and description templates

Line 
1Index: syndication/views.py
2===================================================================
3--- syndication/views.py        (revision 3131)
4+++ syndication/views.py        (working copy)
5@@ -1,7 +1,7 @@
6 from django.contrib.syndication import feeds
7 from django.http import HttpResponse, Http404
8 
9-def feed(request, url, feed_dict=None):
10+def feed(request, url, feed_dict=None, description_template=None, title_template=None):
11     if not feed_dict:
12         raise Http404, "No feeds are registered."
13 
14@@ -15,8 +15,11 @@
15     except KeyError:
16         raise Http404, "Slug %r isn't registered." % slug
17 
18+    desc = description_template
19+    title = title_template
20+
21     try:
22-        feedgen = f(slug, request.path).get_feed(param)
23+        feedgen = f(slug, request.path).get_feed(param, desc, title)
24     except feeds.FeedDoesNotExist:
25         raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug
26 
27Index: syndication/feeds.py
28===================================================================
29--- syndication/feeds.py        (revision 3131)
30+++ syndication/feeds.py        (working copy)
31@@ -47,7 +47,7 @@
32                 return attr()
33         return attr
34 
35-    def get_feed(self, url=None):
36+    def get_feed(self, url=None, desc_temp=None, title_temp=None):
37         """
38         Returns a feedgenerator.DefaultFeed object, fully populated, for
39         this feed. Raises FeedDoesNotExist for invalid parameters.
40@@ -76,11 +76,17 @@
41         )
42 
43         try:
44-            title_template = loader.get_template('feeds/%s_title.html' % self.slug)
45+                       if title_temp:
46+                               title_template = loader.get_template(title_temp)
47+                       else:
48+                               title_template = loader.get_template('feeds/%s_title.html' % self.slug)
49         except TemplateDoesNotExist:
50             title_template = Template('{{ obj }}')
51         try:
52-            description_template = loader.get_template('feeds/%s_description.html' % self.slug)
53+                       if desc_temp:
54+                               description_template = loader.get_template(desc_temp)
55+                       else:
56+                               description_template = loader.get_template('feeds/%s_description.html' % self.slug)
57         except TemplateDoesNotExist:
58             description_template = Template('{{ obj }}')
59