Ticket #2158: syndication.diff

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

Added ability to specify title and description templates

  • syndication/views.py

     
    11from django.contrib.syndication import feeds
    22from django.http import HttpResponse, Http404
    33
    4 def feed(request, url, feed_dict=None):
     4def feed(request, url, feed_dict=None, description_template=None, title_template=None):
    55    if not feed_dict:
    66        raise Http404, "No feeds are registered."
    77
     
    1515    except KeyError:
    1616        raise Http404, "Slug %r isn't registered." % slug
    1717
     18    desc = description_template
     19    title = title_template
     20
    1821    try:
    19         feedgen = f(slug, request.path).get_feed(param)
     22        feedgen = f(slug, request.path).get_feed(param, desc, title)
    2023    except feeds.FeedDoesNotExist:
    2124        raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug
    2225
  • syndication/feeds.py

     
    4747                return attr()
    4848        return attr
    4949
    50     def get_feed(self, url=None):
     50    def get_feed(self, url=None, desc_temp=None, title_temp=None):
    5151        """
    5252        Returns a feedgenerator.DefaultFeed object, fully populated, for
    5353        this feed. Raises FeedDoesNotExist for invalid parameters.
     
    7676        )
    7777
    7878        try:
    79             title_template = loader.get_template('feeds/%s_title.html' % self.slug)
     79                        if title_temp:
     80                                title_template = loader.get_template(title_temp)
     81                        else:
     82                                title_template = loader.get_template('feeds/%s_title.html' % self.slug)
    8083        except TemplateDoesNotExist:
    8184            title_template = Template('{{ obj }}')
    8285        try:
    83             description_template = loader.get_template('feeds/%s_description.html' % self.slug)
     86                        if desc_temp:
     87                                description_template = loader.get_template(desc_temp)
     88                        else:
     89                                description_template = loader.get_template('feeds/%s_description.html' % self.slug)
    8490        except TemplateDoesNotExist:
    8591            description_template = Template('{{ obj }}')
    8692
Back to Top