Django

Code

Changeset 1228

Show
Ignore:
Timestamp:
11/13/05 23:15:40 (3 years ago)
Author:
adrian
Message:

Fixed #787 -- High-level syndication framework now picks up author details. Also updated documentation. Thanks, mattycakes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/syndication/feeds.py

    r1227 r1228  
    2828            raise ImproperlyConfigured, "Give your %s class a get_absolute_url() method, or define an item_link() method in your Feed class." % item.__class__.__name__ 
    2929 
    30     def __get_dynamic_attr(self, attname, obj): 
    31         attr = getattr(self, attname) 
     30    def __get_dynamic_attr(self, attname, obj, default=None): 
     31        try: 
     32            attr = getattr(self, attname) 
     33        except AttributeError: 
     34            return default 
    3235        if callable(attr): 
    3336            try: 
     
    6063            language = LANGUAGE_CODE.decode(), 
    6164            feed_url = add_domain(current_site, self.feed_url), 
     65            author_name = self.__get_dynamic_attr('author_name', obj), 
     66            author_link = self.__get_dynamic_attr('author_link', obj), 
     67            author_email = self.__get_dynamic_attr('author_email', obj), 
    6268        ) 
    6369 
     
    8187                    mime_type = self.__get_dynamic_attr('item_enclosure_mime_type', item).decode('utf-8'), 
    8288                ) 
     89            author_name = self.__get_dynamic_attr('item_author_name', item) 
     90            if author_name is not None: 
     91                author_email = self.__get_dynamic_attr('item_author_email', item) 
     92                author_link = self.__get_dynamic_attr('item_author_link', item) 
     93            else: 
     94                author_email = author_link = None 
    8395            feed.add_item( 
    8496                title = title_template.render(Context({'obj': item, 'site': current_site})).decode('utf-8'), 
     
    88100                enclosure = enc, 
    89101                pubdate = self.__get_dynamic_attr('item_pubdate', item), 
     102                author_name = author_name, 
     103                author_email = author_email, 
     104                author_link = author_link, 
    90105            ) 
    91106        return feed 
  • django/trunk/django/utils/feedgenerator.py

    r1227 r1228  
    5959 
    6060    def add_item(self, title, link, description, author_email=None, 
    61         author_name=None, pubdate=None, comments=None, 
     61        author_name=None, author_link=None, pubdate=None, comments=None, 
    6262        unique_id=None, enclosure=None, categories=()): 
    6363        """ 
     
    7272            'author_email': author_email, 
    7373            'author_name': author_name, 
     74            'author_link': author_link, 
    7475            'pubdate': pubdate, 
    7576            'comments': comments, 
     
    227228                if item['author_email'] is not None: 
    228229                    handler.addQuickElement(u"email", item['author_email']) 
     230                if item['author_link'] is not None: 
     231                    handler.addQuickElement(u"uri", item['author_link']) 
    229232                handler.endElement(u"author") 
    230233 
  • django/trunk/docs/syndication_feeds.txt

    r1227 r1228  
    387387        description = 'Foo bar baz.' # Hard-coded description. 
    388388 
     389        # AUTHOR NAME --One of the following three is optional. The framework 
     390        # looks for them in this order. 
     391 
     392        def author_name(self, obj): 
     393            """ 
     394            Takes the object returned by get_object() and returns the feed's 
     395            author's name as a normal Python string. 
     396            """ 
     397 
     398        def author_name(self): 
     399            """ 
     400            Returns the feed's author's name as a normal Python string. 
     401            """ 
     402 
     403        author_name = 'Sally Smith' # Hard-coded author name. 
     404 
     405        # AUTHOR E-MAIL --One of the following three is optional. The framework 
     406        # looks for them in this order. 
     407 
     408        def author_email(self, obj): 
     409            """ 
     410            Takes the object returned by get_object() and returns the feed's 
     411            author's e-mail as a normal Python string. 
     412            """ 
     413 
     414        def author_name(self): 
     415            """ 
     416            Returns the feed's author's e-mail as a normal Python string. 
     417            """ 
     418 
     419        author_email = 'test@example.com' # Hard-coded author e-mail. 
     420 
     421        # AUTHOR LINK --One of the following three is optional. The framework 
     422        # looks for them in this order. In each case, the URL should include 
     423        # the "http://" and domain name. 
     424 
     425        def author_link(self, obj): 
     426            """ 
     427            Takes the object returned by get_object() and returns the feed's 
     428            author's URL as a normal Python string. 
     429            """ 
     430 
     431        def author_link(self): 
     432            """ 
     433            Returns the feed's author's URL as a normal Python string. 
     434            """ 
     435 
     436        author_link = 'http://www.example.com/' # Hard-coded author URL. 
     437 
    389438        # ITEMS -- One of the following three is required. The framework looks 
    390439        # for them in this order. 
     
    428477            Returns the URL for every item in the feed. 
    429478            """ 
     479 
     480        # ITEM AUTHOR NAME --One of the following three is optional. The 
     481        # framework looks for them in this order. 
     482 
     483        def item_author_name(self, item): 
     484            """ 
     485            Takes an item, as returned by items(), and returns the item's 
     486            author's name as a normal Python string. 
     487            """ 
     488 
     489        def item_author_name(self): 
     490            """ 
     491            Returns the author name for every item in the feed. 
     492            """ 
     493 
     494        item_author_name = 'Sally Smith' # Hard-coded author name. 
     495 
     496        # ITEM AUTHOR E-MAIL --One of the following three is optional. The 
     497        # framework looks for them in this order. 
     498        # 
     499        # If you specify this, you must specify item_author_name. 
     500 
     501        def item_author_email(self, obj): 
     502            """ 
     503            Takes an item, as returned by items(), and returns the item's 
     504            author's e-mail as a normal Python string. 
     505            """ 
     506 
     507        def item_author_email(self): 
     508            """ 
     509            Returns the author e-mail for every item in the feed. 
     510            """ 
     511 
     512        item_author_email = 'test@example.com' # Hard-coded author e-mail. 
     513 
     514        # ITEM AUTHOR LINK --One of the following three is optional. The 
     515        # framework looks for them in this order. In each case, the URL should 
     516        # include the "http://" and domain name. 
     517        # 
     518        # If you specify this, you must specify item_author_name. 
     519 
     520        def item_author_link(self, obj): 
     521            """ 
     522            Takes an item, as returned by items(), and returns the item's 
     523            author's URL as a normal Python string. 
     524            """ 
     525 
     526        def item_author_link(self): 
     527            """ 
     528            Returns the author URL for every item in the feed. 
     529            """ 
     530 
     531        item_author_link = 'http://www.example.com/' # Hard-coded author URL. 
    430532 
    431533        # ITEM ENCLOSURE URL -- One of these three is required if you're