Ticket #3624: feeds.2.diff
File feeds.2.diff, 4.7 KB (added by , 17 years ago) |
---|
-
django/contrib/syndication/feeds.py
85 85 try: 86 86 title_tmp = loader.get_template(self.title_template_name) 87 87 except TemplateDoesNotExist: 88 title_tmp = Template('{{ obj }}')88 title_tmp = self.__get_dynamic_attr('item_title', obj, Template('{{ obj }}')) 89 89 try: 90 90 description_tmp = loader.get_template(self.description_template_name) 91 91 except TemplateDoesNotExist: 92 description_tmp = Template('{{ obj }}')92 description_tmp = self.__get_dynamic_attr('item_description', obj, Template('{{ obj }}'))) 93 93 94 94 for item in self.__get_dynamic_attr('items', obj): 95 95 link = add_domain(current_site.domain, self.__get_dynamic_attr('item_link', item)) -
docs/syndication_feeds.txt
93 93 latest five news items:: 94 94 95 95 from django.contrib.syndication.feeds import Feed 96 from django.template import Template 96 97 from chicagocrime.models import NewsItem 97 98 98 99 class LatestEntries(Feed): … … 103 104 def items(self): 104 105 return NewsItem.objects.order_by('-pub_date')[:5] 105 106 107 def item_description(self): 108 return Template('{{ obj.body }}') 109 106 110 Note: 107 111 108 112 * The class subclasses ``django.contrib.syndication.feeds.Feed``. … … 114 118 `object-relational mapper`_, ``items()`` doesn't have to return model 115 119 instances. Although you get a few bits of functionality "for free" by 116 120 using Django models, ``items()`` can return any type of object you want. 121 * ``item_description(self)`` is method that returns a ``Template`` object. 122 This method of defining a ``Template`` can be used if you prefer this to 123 creating template files located on the file system. 117 124 * If you're creating an Atom feed, rather than an RSS feed, set the 118 125 ``subtitle`` attribute instead of the ``description`` attribute. See 119 126 `Publishing Atom and RSS feeds in tandem`_, later, for an example. … … 123 130 put into those elements. 124 131 125 132 * To specify the contents of ``<title>`` and ``<description>``, create 126 `Django templates`_ called ``feeds/latest_title.html`` and 127 ``feeds/latest_description.html``, where ``latest`` is the ``slug`` 128 specified in the URLconf for the given feed. Note the ``.html`` extension 129 is required. The RSS system renders that template for each item, passing 130 it two template context variables: 133 `Django templates`_. This can be done by either creating template files 134 called ``feeds/latest_title.html`` and ``feeds/latest_description.html``, 135 where ``latest`` is the ``slug`` specified in the URLconf for the given 136 feed, or by defining the properties ``item_title`` and ``item_description`` 137 in your subclass. Note the ``.html`` extension is required when using 138 template files. The RSS system renders that template for each item, 139 passing it two template context variables: 131 140 132 141 * ``{{ obj }}`` -- The current object (one of whichever objects you 133 142 returned in ``items()``). … … 540 549 django.core.exceptions.ObjectDoesNotExist on error. 541 550 """ 542 551 552 # ITEM TITLE -- If the template defined in title_template or the default 553 # template file 'feeds/SLUG_title.html' does not exist, the framework 554 # looks for this method. If this method is not defined, 555 # Template('{{ obj }}') is used by default. 556 557 def item_title(self): 558 """ 559 Returns a Template object defining how to render the title. 560 """ 561 543 562 # ITEM LINK -- One of these three is required. The framework looks for 544 563 # them in this order. 545 564 … … 556 575 Returns the URL for every item in the feed. 557 576 """ 558 577 578 # ITEM DESCRIPTION -- If the template defined in description_template 579 # or the default template file 'feeds/SLUG_description.html' does not 580 # exist, the framework looks for this method. If this method is not 581 # defined, Template('{{ obj }}') is used by default. 582 583 def item_description(self): 584 """ 585 Returns a Template object defining how to render the description. 586 """ 587 559 588 # ITEM AUTHOR NAME --One of the following three is optional. The 560 589 # framework looks for them in this order. 561 590