[1.0.X] Fixed #10141 -- Added a missing import to the complex Feed example. Thanks to Temoto for the report.

Merge of r9858 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@9868 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2009-02-22 06:41:41 +00:00
parent 429b57d642
commit 8519146963
1 changed files with 17 additions and 16 deletions

View File

@ -143,7 +143,7 @@ into those elements.
* ``{{ obj }}`` -- The current object (one of whichever objects you * ``{{ obj }}`` -- The current object (one of whichever objects you
returned in :meth:`items()`). returned in :meth:`items()`).
* ``{{ site }}`` -- A :class:`django.contrib.sites.models.Site` object * ``{{ site }}`` -- A :class:`django.contrib.sites.models.Site` object
representing the current site. This is useful for ``{{ site.domain representing the current site. This is useful for ``{{ site.domain
}}`` or ``{{ site.name }}``. If you do *not* have the Django sites }}`` or ``{{ site.name }}``. If you do *not* have the Django sites
@ -181,9 +181,9 @@ into those elements.
{{ obj.title }} {{ obj.title }}
* latest_description.html: * latest_description.html:
.. code-block:: html+django .. code-block:: html+django
{{ obj.description }} {{ obj.description }}
.. _chicagocrime.org: http://www.chicagocrime.org/ .. _chicagocrime.org: http://www.chicagocrime.org/
@ -213,6 +213,7 @@ the feed.
An example makes this clear. Here's the code for these beat-specific feeds:: An example makes this clear. Here's the code for these beat-specific feeds::
from django.contrib.syndication.feeds import FeedDoesNotExist from django.contrib.syndication.feeds import FeedDoesNotExist
from django.core.exceptions import ObjectDoesNotExist
class BeatFeed(Feed): class BeatFeed(Feed):
def get_object(self, bits): def get_object(self, bits):
@ -278,9 +279,9 @@ request to the URL :file:`/rss/beats/0613/`:
* First, it tries to call a method, passing the ``obj`` argument, where * First, it tries to call a method, passing the ``obj`` argument, where
``obj`` is the object returned by :meth:`get_object()`. ``obj`` is the object returned by :meth:`get_object()`.
* Failing that, it tries to call a method with no arguments. * Failing that, it tries to call a method with no arguments.
* Failing that, it uses the class attribute. * Failing that, it uses the class attribute.
Inside the :meth:`link()` method, we handle the possibility that ``obj`` Inside the :meth:`link()` method, we handle the possibility that ``obj``
@ -840,11 +841,11 @@ They share this interface:
Initialize the feed with the given dictionary of metadata, which applies to Initialize the feed with the given dictionary of metadata, which applies to
the entire feed. Required keyword arguments are: the entire feed. Required keyword arguments are:
* ``title`` * ``title``
* ``link`` * ``link``
* ``description`` * ``description``
There's also a bunch of other optional keywords: There's also a bunch of other optional keywords:
* ``language`` * ``language``
@ -857,7 +858,7 @@ They share this interface:
* ``feed_copyright`` * ``feed_copyright``
* ``feed_guid`` * ``feed_guid``
* ``ttl`` * ``ttl``
Any extra keyword arguments you pass to ``__init__`` will be stored in Any extra keyword arguments you pass to ``__init__`` will be stored in
``self.feed`` for use with `custom feed generators`_. ``self.feed`` for use with `custom feed generators`_.
@ -866,7 +867,7 @@ They share this interface:
.. method:: SyndicationFeed.add_item(**kwargs) .. method:: SyndicationFeed.add_item(**kwargs)
Add an item to the feed with the given parameters. Add an item to the feed with the given parameters.
Required keyword arguments are: Required keyword arguments are:
@ -893,7 +894,7 @@ They share this interface:
* ``pubdate`` should be a `Python datetime object`_. * ``pubdate`` should be a `Python datetime object`_.
* ``enclosure`` should be an instance of ``feedgenerator.Enclosure``. * ``enclosure`` should be an instance of ``feedgenerator.Enclosure``.
* ``categories`` should be a sequence of Unicode objects. * ``categories`` should be a sequence of Unicode objects.
.. method:: SyndicationFeed.write(outfile, encoding) .. method:: SyndicationFeed.write(outfile, encoding)
@ -927,7 +928,7 @@ Custom feed generators
---------------------- ----------------------
If you need to produce a custom feed format, you've got a couple of options. If you need to produce a custom feed format, you've got a couple of options.
If the feed format is totally custom, you'll want to subclass If the feed format is totally custom, you'll want to subclass
``SyndicationFeed`` and completely replace the ``write()`` and ``SyndicationFeed`` and completely replace the ``write()`` and
``writeString()`` methods. ``writeString()`` methods.
@ -938,25 +939,25 @@ feeds typically add extra elements and/or attributes to the underlying format,
and there are a set of methods that ``SyndicationFeed`` calls to get these extra and there are a set of methods that ``SyndicationFeed`` calls to get these extra
attributes. Thus, you can subclass the appropriate feed generator class attributes. Thus, you can subclass the appropriate feed generator class
(``Atom1Feed`` or ``Rss201rev2Feed``) and extend these callbacks. They are: (``Atom1Feed`` or ``Rss201rev2Feed``) and extend these callbacks. They are:
.. _georss: http://georss.org/ .. _georss: http://georss.org/
.. _itunes podcast format: http://www.apple.com/itunes/store/podcaststechspecs.html .. _itunes podcast format: http://www.apple.com/itunes/store/podcaststechspecs.html
``SyndicationFeed.root_attributes(self, )`` ``SyndicationFeed.root_attributes(self, )``
Return a ``dict`` of attributes to add to the root feed element Return a ``dict`` of attributes to add to the root feed element
(``feed``/``channel``). (``feed``/``channel``).
``SyndicationFeed.add_root_elements(self, handler)`` ``SyndicationFeed.add_root_elements(self, handler)``
Callback to add elements inside the root feed element Callback to add elements inside the root feed element
(``feed``/``channel``). ``handler`` is an `XMLGenerator`_ from Python's (``feed``/``channel``). ``handler`` is an `XMLGenerator`_ from Python's
built-in SAX library; you'll call methods on it to add to the XML built-in SAX library; you'll call methods on it to add to the XML
document in process. document in process.
``SyndicationFeed.item_attributes(self, item)`` ``SyndicationFeed.item_attributes(self, item)``
Return a ``dict`` of attributes to add to each item (``item``/``entry``) Return a ``dict`` of attributes to add to each item (``item``/``entry``)
element. The argument, ``item``, is a dictionary of all the data passed to element. The argument, ``item``, is a dictionary of all the data passed to
``SyndicationFeed.add_item()``. ``SyndicationFeed.add_item()``.
``SyndicationFeed.add_item_elements(self, handler, item)`` ``SyndicationFeed.add_item_elements(self, handler, item)``
Callback to add elements to each item (``item``/``entry``) element. Callback to add elements to each item (``item``/``entry``) element.
``handler`` and ``item`` are as above. ``handler`` and ``item`` are as above.
@ -973,7 +974,7 @@ For example, you might start implementing an iTunes RSS feed generator like so::
attrs = super(iTunesFeed, self).root_attributes() attrs = super(iTunesFeed, self).root_attributes()
attrs['xmlns:itunes'] = 'http://www.itunes.com/dtds/podcast-1.0.dtd' attrs['xmlns:itunes'] = 'http://www.itunes.com/dtds/podcast-1.0.dtd'
return attrs return attrs
def add_root_elements(self, handler): def add_root_elements(self, handler):
super(iTunesFeed, self).add_root_elements(handler) super(iTunesFeed, self).add_root_elements(handler)
handler.addQuickElement('itunes:explicit', 'clean') handler.addQuickElement('itunes:explicit', 'clean')