Ticket #6618: syndication-optionaltemplates.diff
File syndication-optionaltemplates.diff, 4.3 KB (added by , 16 years ago) |
---|
-
django/contrib/syndication/feeds.py
29 29 self.feed_url = request.path 30 30 self.title_template_name = self.title_template or ('feeds/%s_title.html' % slug) 31 31 self.description_template_name = self.description_template or ('feeds/%s_description.html' % slug) 32 if Site._meta.installed: 33 self.current_site = Site.objects.get_current() 34 else: 35 self.current_site = RequestSite(self.request) 32 36 33 37 def item_link(self, item): 34 38 try: 35 39 return item.get_absolute_url() 36 40 except AttributeError: 37 41 raise ImproperlyConfigured, "Give your %s class a get_absolute_url() method, or define an item_link() method in your Feed class." % item.__class__.__name__ 42 43 def item_title(self, item): 44 try: 45 title_tmp = loader.get_template(self.title_template_name) 46 except TemplateDoesNotExist: 47 return unicode(item) 48 title_rc = RequestContext(self.request, {'obj': item, 'site': self.current_site}) 49 title_rc.autoescape = False 50 return title_tmp.render(title_rc) 51 52 def item_description(self, item): 53 try: 54 description_tmp = loader.get_template(self.description_template_name) 55 except TemplateDoesNotExist: 56 return unicode(item) 57 description_rc = RequestContext(self.request, {'obj': item, 'site': self.current_site}) 58 description_rc.autoescape = False 59 return description_tmp.render(description_rc) 38 60 39 61 def __get_dynamic_attr(self, attname, obj, default=None): 40 62 try: … … 74 96 except ObjectDoesNotExist: 75 97 raise FeedDoesNotExist 76 98 77 if Site._meta.installed:78 current_site = Site.objects.get_current()79 else:80 current_site = RequestSite(self.request)81 82 99 link = self.__get_dynamic_attr('link', obj) 83 link = add_domain( current_site.domain, link)100 link = add_domain(self.current_site.domain, link) 84 101 85 102 feed = self.feed_type( 86 103 title = self.__get_dynamic_attr('title', obj), … … 88 105 link = link, 89 106 description = self.__get_dynamic_attr('description', obj), 90 107 language = settings.LANGUAGE_CODE.decode(), 91 feed_url = add_domain( current_site.domain,108 feed_url = add_domain(self.current_site.domain, 92 109 self.__get_dynamic_attr('feed_url', obj)), 93 110 author_name = self.__get_dynamic_attr('author_name', obj), 94 111 author_link = self.__get_dynamic_attr('author_link', obj), … … 99 116 ttl = self.__get_dynamic_attr('ttl', obj), 100 117 ) 101 118 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 }}')110 111 119 for item in self.__get_dynamic_attr('items', obj): 112 link = add_domain( current_site.domain, self.__get_dynamic_attr('item_link', item))120 link = add_domain(self.current_site.domain, self.__get_dynamic_attr('item_link', item)) 113 121 enc = None 114 122 enc_url = self.__get_dynamic_attr('item_enclosure_url', item) 115 123 if enc_url: … … 125 133 else: 126 134 author_email = author_link = None 127 135 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), 129 137 link = link, 130 description = description_tmp.render(RequestContext(self.request, {'obj': item, 'site': current_site})),138 description = self.__get_dynamic_attr('item_description', item), 131 139 unique_id = self.__get_dynamic_attr('item_guid', item, link), 132 140 enclosure = enc, 133 141 pubdate = self.__get_dynamic_attr('item_pubdate', item),