Ticket #3624: item_title_and_description_methods.patch

File item_title_and_description_methods.patch, 2.6 KB (added by sf, 7 years ago)

Another approach to solve that problem.

  • django/contrib/syndication/feeds.py

     
    3030        self.title_template_name = self.title_template or ('feeds/%s_title.html' % slug)
    3131        self.description_template_name = self.description_template or ('feeds/%s_description.html' % slug)
    3232
     33    def item_title(self, item):
     34        if not hasattr(self, '_title_tmp'):
     35            try:
     36                self._title_tmp = loader.get_template(self.title_template_name)
     37            except TemplateDoesNotExist:
     38                self._title_tmp = Template('{{ obj }}')
     39        return self._title_tmp.render(RequestContext(self.request, {'obj': item }))
     40
     41    def item_description(self, item):
     42        if not hasattr(self, '_description_tmp'):
     43            try:
     44                self._description_tmp = loader.get_template(self.description_template_name)
     45            except TemplateDoesNotExist:
     46                self._description_tmp = Template('{{ obj }}')
     47        return self._description_tmp.render(RequestContext(self.request, {'obj': item }))
     48
    3349    def item_link(self, item):
    3450        try:
    3551            return item.get_absolute_url()
     
    99115            ttl = self.__get_dynamic_attr('ttl', obj),
    100116        )
    101117
    102         try:
    103             title_tmp = loader.get_template(self.title_template_name)
    104         except TemplateDoesNotExist:
    105             title_tmp = Template('{{ obj }}')
    106         try:
    107             description_tmp = loader.get_template(self.description_template_name)
    108         except TemplateDoesNotExist:
    109             description_tmp = Template('{{ obj }}')
    110118
    111119        for item in self.__get_dynamic_attr('items', obj):
    112120            link = add_domain(current_site.domain, self.__get_dynamic_attr('item_link', item))
     
    125133            else:
    126134                author_email = author_link = None
    127135            feed.add_item(
    128                 title = title_tmp.render(RequestContext(self.request, {'obj': item, 'site': current_site})),
     136                title = self.__get_dynamic_attr('item_title', item),
    129137                link = link,
    130                 description = description_tmp.render(RequestContext(self.request, {'obj': item, 'site': current_site})),
     138                description = self.__get_dynamic_attr('item_description', item),
    131139                unique_id = self.__get_dynamic_attr('item_guid', item, link),
    132140                enclosure = enc,
    133141                pubdate = self.__get_dynamic_attr('item_pubdate', item),
Back to Top