Ticket #2762: 2007-11-24.diff
File 2007-11-24.diff, 5.8 KB (added by , 18 years ago) |
---|
-
django/utils/feedgenerator.py
40 40 "Base class for all syndication feeds. Subclasses should provide write()" 41 41 def __init__(self, title, link, description, language=None, author_email=None, 42 42 author_name=None, author_link=None, subtitle=None, categories=None, 43 feed_url=None ):43 feed_url=None, feed_copyright=None): 44 44 self.feed = { 45 45 'title': title, 46 46 'link': link, … … 52 52 'subtitle': subtitle, 53 53 'categories': categories or (), 54 54 'feed_url': feed_url, 55 'feed_copyright': feed_copyright, 55 56 } 56 57 self.items = [] 57 58 58 59 def add_item(self, title, link, description, author_email=None, 59 60 author_name=None, author_link=None, pubdate=None, comments=None, 60 unique_id=None, enclosure=None, categories=() ):61 unique_id=None, enclosure=None, categories=(), item_copyright=None): 61 62 """ 62 63 Adds an item to the feed. All args are expected to be Python Unicode 63 64 objects except pubdate, which is a datetime.datetime object, and … … 75 76 'unique_id': unique_id, 76 77 'enclosure': enclosure, 77 78 'categories': categories or (), 79 'item_copyright': item_copyright, 78 80 }) 79 81 80 82 def num_items(self): … … 128 130 handler.addQuickElement(u"language", self.feed['language']) 129 131 for cat in self.feed['categories']: 130 132 handler.addQuickElement(u"category", cat) 133 if self.feed['feed_copyright'] is not None: 134 handler.addQuickElement(u"copyright", self.feed['feed_copyright']) 131 135 self.write_items(handler) 132 136 self.endChannelElement(handler) 133 137 handler.endElement(u"rss") … … 212 216 handler.addQuickElement(u"subtitle", self.feed['subtitle']) 213 217 for cat in self.feed['categories']: 214 218 handler.addQuickElement(u"category", "", {u"term": cat}) 219 if self.feed['feed_copyright'] is not None: 220 handler.addQuickElement(u"rights", self.feed['feed_copyright']) 215 221 self.write_items(handler) 216 222 handler.endElement(u"feed") 217 223 … … 252 258 u"length": item['enclosure'].length, 253 259 u"type": item['enclosure'].mime_type}) 254 260 255 # Categories :261 # Categories. 256 262 for cat in item['categories']: 257 263 handler.addQuickElement(u"category", u"", {u"term": cat}) 258 264 265 # Rights. 266 if item['item_copyright'] is not None: 267 handler.addQuickElement(u"rights", item['item_copyright']) 268 259 269 handler.endElement(u"entry") 260 270 261 271 # This isolates the decision of what the system default is, so calling code can -
django/contrib/syndication/feeds.py
78 78 author_link = self.__get_dynamic_attr('author_link', obj), 79 79 author_email = self.__get_dynamic_attr('author_email', obj), 80 80 categories = self.__get_dynamic_attr('categories', obj), 81 feed_copyright = self.__get_dynamic_attr('feed_copyright', obj), 81 82 ) 82 83 83 84 try: … … 116 117 author_email = author_email, 117 118 author_link = author_link, 118 119 categories = self.__get_dynamic_attr('item_categories', item), 120 item_copyright = self.__get_dynamic_attr('item_copyright', item), 119 121 ) 120 122 return feed -
docs/syndication_feeds.txt
127 127 it two template context variables: 128 128 129 129 * ``{{ obj }}`` -- The current object (one of whichever objects you 130 returned in ``items()``). 130 returned in ``items()``). 131 131 * ``{{ site }}`` -- A ``django.models.core.sites.Site`` object 132 132 representing the current site. This is useful for 133 133 ``{{ site.domain }}`` or ``{{ site.name }}``. … … 478 478 479 479 categories = ("python", "django") # Hard-coded list of categories. 480 480 481 # COPYRIGHT NOTICE -- One of the following three is optional. The 482 # framework looks for them in this order. 483 484 def copyright(self, obj): 485 """ 486 Takes the object returned by get_object() and returns the feed's 487 copyright notice as a normal Python string. 488 """ 489 490 def copyright(self): 491 """ 492 Returns the feed's copyright notice as a normal Python string. 493 """ 494 495 copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright notice. 496 481 497 # ITEMS -- One of the following three is required. The framework looks 482 498 # for them in this order. 483 499 … … 659 675 660 676 item_categories = ("python", "django") # Hard-coded categories. 661 677 678 # ITEM COPYRIGHT NOTICE -- One of the following three is optional. The 679 # framework looks for them in this order. 662 680 681 def item_copyright(self, obj): 682 """ 683 Takes an item, as returned by items(), and returns the item's 684 copyright notice as a normal Python string. 685 """ 686 687 def item_copyright(self): 688 """ 689 Returns the copyright notice for every item in the feed. 690 """ 691 692 item_copyright = 'Copyright (c) 2007, Sally Smith' # Hard-coded copyright notice. 693 694 663 695 The low-level framework 664 696 ======================= 665 697