Django

Code

Changeset 5654

Show
Ignore:
Timestamp:
07/12/07 00:29:32 (1 year ago)
Author:
adrian
Message:

Improved syndication feed framework to use RequestSite? if the sites framework 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

Files:

Legend:

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

    r5643 r5654  
    11from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist 
    22from django.template import Context, loader, Template, TemplateDoesNotExist 
    3 from django.contrib.sites.models import Site 
     3from django.contrib.sites.models import Site, RequestSite 
    44from django.utils import feedgenerator 
    55from django.utils.encoding import smart_unicode, iri_to_uri 
     
    2323    description_template = None 
    2424 
    25     def __init__(self, slug, feed_url): 
     25    def __init__(self, slug, request): 
    2626        self.slug = slug 
    27         self.feed_url = feed_url 
     27        self.request = request 
     28        self.feed_url = request.path 
    2829        self.title_template_name = self.title_template or ('feeds/%s_title.html' % slug) 
    2930        self.description_template_name = self.description_template or ('feeds/%s_description.html' % slug) 
     
    6869            obj = None 
    6970 
    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 
    7176        link = self.__get_dynamic_attr('link', obj) 
    7277        link = add_domain(current_site.domain, link) 
  • django/trunk/django/contrib/syndication/views.py

    r4265 r5654  
    1717 
    1818    try: 
    19         feedgen = f(slug, request.path).get_feed(param) 
     19        feedgen = f(slug, request).get_feed(param) 
    2020    except feeds.FeedDoesNotExist: 
    2121        raise Http404, "Invalid feed parameters. Slug %r is valid, but other parameters, or lack thereof, are not." % slug 
  • django/trunk/docs/syndication_feeds.txt

    r5650 r5654  
    3131Initialization 
    3232-------------- 
     33 
     34If you're not using the latest Django development version, you'll need to make 
     35sure Django's sites framework is installed -- including its database table. 
     36(See the `sites framework documentation`_ for more information.) This has 
     37changed in the Django development version; the syndication feed framework no 
     38longer requires the sites framework. 
    3339 
    3440To activate syndication feeds on your Django site, add this line to your 
     
    7379Once that's set up, you just need to define the ``Feed`` classes themselves. 
    7480 
     81.. _sites framework documentation: ../sites/ 
    7582.. _URLconf: ../url_dispatch/ 
    7683.. _settings file: ../settings/ 
     
    132139          * ``{{ obj }}`` -- The current object (one of whichever objects you 
    133140            returned in ``items()``). 
    134           * ``{{ site }}`` -- A ``django.models.core.sites.Site`` object 
     141          * ``{{ site }}`` -- A ``django.contrib.sites.models.Site`` object 
    135142            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. 
    137149 
    138150      If you don't create a template for either the title or description, the 
     
    165177.. _object-relational mapper: ../db-api/ 
    166178.. _Django templates: ../templates/ 
     179.. _RequestSite section of the sites framework documentation: ../sites/#requestsite-objects 
    167180 
    168181A complex example