Fixed #15707 -- Made the GIS feed compatible to the class based feeds and introduced a little helper view that works like the previous feed view in the syndication app which was removed in r15976.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16540 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jannis Leidel 2011-07-13 09:36:07 +00:00
parent 24f4764a48
commit 12b7c2a702
4 changed files with 36 additions and 13 deletions

View File

@ -8,7 +8,7 @@ class GeoRSSSitemap(Sitemap):
def __init__(self, feed_dict, slug_dict=None): def __init__(self, feed_dict, slug_dict=None):
""" """
This sitemap object initializes on a feed dictionary (as would be passed This sitemap object initializes on a feed dictionary (as would be passed
to `django.contrib.syndication.views.feed`) and a slug dictionary. to `django.contrib.gis.views.feed`) and a slug dictionary.
If the slug dictionary is not defined, then it's assumed the keys provide If the slug dictionary is not defined, then it's assumed the keys provide
the URL parameter to the feed. However, if you have a complex feed (e.g., the URL parameter to the feed. However, if you have a complex feed (e.g.,
you override `get_object`, then you'll need to provide a slug dictionary. you override `get_object`, then you'll need to provide a slug dictionary.
@ -49,5 +49,5 @@ class GeoRSSSitemap(Sitemap):
return self.locations return self.locations
def location(self, obj): def location(self, obj):
return urlresolvers.reverse('django.contrib.syndication.views.feed', args=(obj,)) return urlresolvers.reverse('django.contrib.gis.views.feed', args=(obj,))

View File

@ -100,7 +100,8 @@ class GeoDjangoTestSuiteRunner(DjangoTestSuiteRunner):
# Constructing the new INSTALLED_APPS, and including applications # Constructing the new INSTALLED_APPS, and including applications
# within the GeoDjango test namespace. # within the GeoDjango test namespace.
new_installed = ['django.contrib.sites', new_installed = [
'django.contrib.sites',
'django.contrib.sitemaps', 'django.contrib.sitemaps',
'django.contrib.gis', 'django.contrib.gis',
] ]
@ -108,7 +109,7 @@ class GeoDjangoTestSuiteRunner(DjangoTestSuiteRunner):
# Calling out to `geo_apps` to get GeoDjango applications supported # Calling out to `geo_apps` to get GeoDjango applications supported
# for testing. # for testing.
new_installed.extend(geo_apps()) new_installed.extend(geo_apps())
settings.INSTALLED_APPS = new_installed settings.INSTALLED_APPS = list(self.old_installed) + new_installed
# SITE_ID needs to be set # SITE_ID needs to be set
settings.SITE_ID = 1 settings.SITE_ID = 1

View File

@ -2,7 +2,7 @@ from django.conf.urls.defaults import *
from feeds import feed_dict from feeds import feed_dict
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feed_dict}), (r'^feeds/(?P<url>.*)/$', 'django.contrib.gis.views.feed', {'feed_dict': feed_dict}),
) )
from sitemaps import sitemaps from sitemaps import sitemaps

View File

@ -0,0 +1,22 @@
from django.http import Http404
def feed(request, url, feed_dict=None):
"""Provided for backwards compatibility."""
if not feed_dict:
raise Http404("No feeds are registered.")
try:
slug, param = url.split('/', 1)
except ValueError:
slug, param = url, ''
try:
f = feed_dict[slug]
except KeyError:
raise Http404("Slug %r isn't registered." % slug)
instance = f()
instance.feed_url = getattr(f, 'feed_url', None) or request.path
instance.title_template = f.title_template or ('feeds/%s_title.html' % slug)
instance.description_template = f.description_template or ('feeds/%s_description.html' % slug)
return instance(request)