Skip to content

Commit

Permalink
Improved syndication feed framework to use RequestSite if the sites f…
Browse files Browse the repository at this point in the history
…ramework is not installed -- i.e., the sites framework is no longer required to use the syndication feed framework. This is backwards incompatible if anybody has subclassed Feed and overridden __init__(), because the second parameter is now expected to be an HttpRequest object instead of request.path

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5654 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Jul 12, 2007
1 parent dcd5750 commit 090aa52
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
13 changes: 9 additions & 4 deletions django/contrib/syndication/feeds.py
@@ -1,6 +1,6 @@
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.template import Context, loader, Template, TemplateDoesNotExist
from django.contrib.sites.models import Site
from django.contrib.sites.models import Site, RequestSite
from django.utils import feedgenerator
from django.utils.encoding import smart_unicode, iri_to_uri
from django.conf import settings
Expand All @@ -22,9 +22,10 @@ class Feed(object):
title_template = None
description_template = None

def __init__(self, slug, feed_url):
def __init__(self, slug, request):
self.slug = slug
self.feed_url = feed_url
self.request = request
self.feed_url = request.path
self.title_template_name = self.title_template or ('feeds/%s_title.html' % slug)
self.description_template_name = self.description_template or ('feeds/%s_description.html' % slug)

Expand Down Expand Up @@ -67,7 +68,11 @@ def get_feed(self, url=None):
else:
obj = None

current_site = Site.objects.get_current()
if Site._meta.installed:
current_site = Site.objects.get_current()
else:
current_site = RequestSite(self.request)

link = self.__get_dynamic_attr('link', obj)
link = add_domain(current_site.domain, link)

Expand Down
2 changes: 1 addition & 1 deletion django/contrib/syndication/views.py
Expand Up @@ -16,7 +16,7 @@ def feed(request, url, feed_dict=None):
raise Http404, "Slug %r isn't registered." % slug

try:
feedgen = f(slug, request.path).get_feed(param)
feedgen = f(slug, request).get_feed(param)
except feeds.FeedDoesNotExist:
raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug

Expand Down
17 changes: 15 additions & 2 deletions docs/syndication_feeds.txt
Expand Up @@ -31,6 +31,12 @@ To create a feed, just write a ``Feed`` class and point to it in your URLconf_.
Initialization
--------------

If you're not using the latest Django development version, you'll need to make
sure Django's sites framework is installed -- including its database table.
(See the `sites framework documentation`_ for more information.) This has
changed in the Django development version; the syndication feed framework no
longer requires the sites framework.

To activate syndication feeds on your Django site, add this line to your
URLconf_::

Expand Down Expand Up @@ -72,6 +78,7 @@ The above example registers two feeds:

Once that's set up, you just need to define the ``Feed`` classes themselves.

.. _sites framework documentation: ../sites/
.. _URLconf: ../url_dispatch/
.. _settings file: ../settings/

Expand Down Expand Up @@ -131,9 +138,14 @@ put into those elements.

* ``{{ obj }}`` -- The current object (one of whichever objects you
returned in ``items()``).
* ``{{ site }}`` -- A ``django.models.core.sites.Site`` object
* ``{{ site }}`` -- A ``django.contrib.sites.models.Site`` object
representing the current site. This is useful for
``{{ site.domain }}`` or ``{{ site.name }}``.
``{{ site.domain }}`` or ``{{ site.name }}``. Note that if you're
using the latest Django development version and do *not* have the
Django sites framework installed, this will be set to a
``django.contrib.sites.models.RequestSite`` object. See the
`RequestSite section of the sites framework documentation`_ for
more.

If you don't create a template for either the title or description, the
framework will use the template ``"{{ obj }}"`` by default -- that is,
Expand Down Expand Up @@ -164,6 +176,7 @@ put into those elements.
.. _chicagocrime.org: http://www.chicagocrime.org/
.. _object-relational mapper: ../db-api/
.. _Django templates: ../templates/
.. _RequestSite section of the sites framework documentation: ../sites/#requestsite-objects

A complex example
-----------------
Expand Down

0 comments on commit 090aa52

Please sign in to comment.