Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Improved syndication feed framework to use RequestSite if the sites f…

…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...
commit 090aa5210ebd5ce3c79db95d3f04c95ed346f42a 1 parent dcd5750
Adrian Holovaty authored July 12, 2007
13  django/contrib/syndication/feeds.py
... ...
@@ -1,6 +1,6 @@
1 1
 from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
2 2
 from django.template import Context, loader, Template, TemplateDoesNotExist
3  
-from django.contrib.sites.models import Site
  3
+from django.contrib.sites.models import Site, RequestSite
4 4
 from django.utils import feedgenerator
5 5
 from django.utils.encoding import smart_unicode, iri_to_uri
6 6
 from django.conf import settings
@@ -22,9 +22,10 @@ class Feed(object):
22 22
     title_template = None
23 23
     description_template = None
24 24
 
25  
-    def __init__(self, slug, feed_url):
  25
+    def __init__(self, slug, request):
26 26
         self.slug = slug
27  
-        self.feed_url = feed_url
  27
+        self.request = request
  28
+        self.feed_url = request.path
28 29
         self.title_template_name = self.title_template or ('feeds/%s_title.html' % slug)
29 30
         self.description_template_name = self.description_template or ('feeds/%s_description.html' % slug)
30 31
 
@@ -67,7 +68,11 @@ def get_feed(self, url=None):
67 68
         else:
68 69
             obj = None
69 70
 
70  
-        current_site = Site.objects.get_current()
  71
+        if Site._meta.installed:
  72
+            current_site = Site.objects.get_current()
  73
+        else:
  74
+            current_site = RequestSite(self.request)
  75
+
71 76
         link = self.__get_dynamic_attr('link', obj)
72 77
         link = add_domain(current_site.domain, link)
73 78
 
2  django/contrib/syndication/views.py
@@ -16,7 +16,7 @@ def feed(request, url, feed_dict=None):
16 16
         raise Http404, "Slug %r isn't registered." % slug
17 17
 
18 18
     try:
19  
-        feedgen = f(slug, request.path).get_feed(param)
  19
+        feedgen = f(slug, request).get_feed(param)
20 20
     except feeds.FeedDoesNotExist:
21 21
         raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug
22 22
 
17  docs/syndication_feeds.txt
@@ -31,6 +31,12 @@ To create a feed, just write a ``Feed`` class and point to it in your URLconf_.
31 31
 Initialization
32 32
 --------------
33 33
 
  34
+If you're not using the latest Django development version, you'll need to make
  35
+sure Django's sites framework is installed -- including its database table.
  36
+(See the `sites framework documentation`_ for more information.) This has
  37
+changed in the Django development version; the syndication feed framework no
  38
+longer requires the sites framework.
  39
+
34 40
 To activate syndication feeds on your Django site, add this line to your
35 41
 URLconf_::
36 42
 
@@ -72,6 +78,7 @@ The above example registers two feeds:
72 78
 
73 79
 Once that's set up, you just need to define the ``Feed`` classes themselves.
74 80
 
  81
+.. _sites framework documentation: ../sites/
75 82
 .. _URLconf: ../url_dispatch/
76 83
 .. _settings file: ../settings/
77 84
 
@@ -131,9 +138,14 @@ put into those elements.
131 138
 
132 139
           * ``{{ obj }}`` -- The current object (one of whichever objects you
133 140
             returned in ``items()``).
134  
-          * ``{{ site }}`` -- A ``django.models.core.sites.Site`` object
  141
+          * ``{{ site }}`` -- A ``django.contrib.sites.models.Site`` object
135 142
             representing the current site. This is useful for
136  
-            ``{{ site.domain }}`` or ``{{ site.name }}``.
  143
+            ``{{ site.domain }}`` or ``{{ site.name }}``. Note that if you're
  144
+            using the latest Django development version and do *not* have the
  145
+            Django sites framework installed, this will be set to a
  146
+            ``django.contrib.sites.models.RequestSite`` object. See the
  147
+            `RequestSite section of the sites framework documentation`_ for
  148
+            more.
137 149
 
138 150
       If you don't create a template for either the title or description, the
139 151
       framework will use the template ``"{{ obj }}"`` by default -- that is,
@@ -164,6 +176,7 @@ put into those elements.
164 176
 .. _chicagocrime.org: http://www.chicagocrime.org/
165 177
 .. _object-relational mapper: ../db-api/
166 178
 .. _Django templates: ../templates/
  179
+.. _RequestSite section of the sites framework documentation: ../sites/#requestsite-objects
167 180
 
168 181
 A complex example
169 182
 -----------------

0 notes on commit 090aa52

Please sign in to comment.
Something went wrong with that request. Please try again.