Ticket #1473: categories.patch

File categories.patch, 3.3 KB (added by k.shaposhnikov@…, 19 years ago)

Add support for categories to syndycation framework

  • django/contrib/syndication/feeds.py

     
    7373            author_name = self.__get_dynamic_attr('author_name', obj),
    7474            author_link = self.__get_dynamic_attr('author_link', obj),
    7575            author_email = self.__get_dynamic_attr('author_email', obj),
     76            categories = self.__get_dynamic_attr('categories', obj),
    7677        )
    7778
    7879        try:
     
    110111                author_name = author_name,
    111112                author_email = author_email,
    112113                author_link = author_link,
     114                categories = self.__get_dynamic_attr('item_categories', item),
    113115            )
    114116        return feed
  • django/utils/feedgenerator.py

     
    128128        handler.addQuickElement(u"description", self.feed['description'])
    129129        if self.feed['language'] is not None:
    130130            handler.addQuickElement(u"language", self.feed['language'])
     131        for cat in self.feed['categories']:
     132            handler.addQuickElement(u"category", cat)
    131133        self.write_items(handler)
    132134        self.endChannelElement(handler)
    133135        handler.endElement(u"rss")
  • docs/syndication_feeds.txt

     
    439439
    440440        author_link = 'http://www.example.com/' # Hard-coded author URL.
    441441
     442        # CATEGORIES --One of the following three is optional. The framework
     443        # looks for them in this order. In each case, the method/attribute
     444        # should return an iterable object, that iterates over strings.
     445
     446        def categories(self, obj):
     447            """
     448            Takes the object returned by get_object() and returns the feed's
     449            categories as iterable over strings.
     450            """
     451
     452        def categories(self):
     453            """
     454            Returns the feed's categories as iterable over strings.
     455            """
     456
     457        categories = ("python", "django") # Hard-coded list of categories.
     458
    442459        # ITEMS -- One of the following three is required. The framework looks
    443460        # for them in this order.
    444461
     
    602619
    603620        item_pubdate = datetime.datetime(2005, 5, 3) # Hard-coded pubdate.
    604621
     622        # ITEM CATEGORIES -- It's optional to use one of these three. This is a
     623        # hook that specifies how to get the list of categories for a given item.
     624        # In each case, the method/attribute should return an iterable
     625        # object, that iterates over strings.
     626
     627        def item_categories(self, item):
     628            """
     629            Takes an item, as returned by items(), and returns the item's
     630            categories.
     631            """
     632
     633        def item_categories(self):
     634            """
     635            Returns the categories for every item in the feed.
     636            """
     637
     638        item_categories = ("python", "django") # Hard-coded categories.
     639
    605640The low-level framework
    606641=======================
    607642
Back to Top