Skip to content

Commit

Permalink
Fixed #15707 -- Made the GIS feed compatible to the class based feeds…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
jezdez committed Jul 13, 2011
1 parent 24f4764 commit 12b7c2a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
12 changes: 6 additions & 6 deletions django/contrib/gis/sitemaps/georss.py
Expand Up @@ -8,13 +8,13 @@ class GeoRSSSitemap(Sitemap):
def __init__(self, feed_dict, slug_dict=None):
"""
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
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.
The slug dictionary should have the same keys as the feed dictionary, but
each value in the slug dictionary should be a sequence of slugs that may
be used for valid feeds. For example, let's say we have a feed that
The slug dictionary should have the same keys as the feed dictionary, but
each value in the slug dictionary should be a sequence of slugs that may
be used for valid feeds. For example, let's say we have a feed that
returns objects for a specific ZIP code in our feed dictionary:
feed_dict = {'zipcode' : ZipFeed}
Expand All @@ -35,7 +35,7 @@ def __init__(self, feed_dict, slug_dict=None):
self.locations.append('%s/%s' % (section, slug))
else:
self.locations.append(section)

def get_urls(self, page=1, site=None):
"""
This method is overrridden so the appropriate `geo_format` attribute
Expand All @@ -49,5 +49,5 @@ def items(self):
return self.locations

def location(self, obj):
return urlresolvers.reverse('django.contrib.syndication.views.feed', args=(obj,))
return urlresolvers.reverse('django.contrib.gis.views.feed', args=(obj,))

11 changes: 6 additions & 5 deletions django/contrib/gis/tests/__init__.py
Expand Up @@ -100,15 +100,16 @@ def setup_test_environment(self, **kwargs):

# Constructing the new INSTALLED_APPS, and including applications
# within the GeoDjango test namespace.
new_installed = ['django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.gis',
]
new_installed = [
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.gis',
]

# Calling out to `geo_apps` to get GeoDjango applications supported
# for testing.
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
settings.SITE_ID = 1
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/gis/tests/geoapp/urls.py
Expand Up @@ -2,13 +2,13 @@
from feeds import feed_dict

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
urlpatterns += patterns('django.contrib.gis.sitemaps.views',
(r'^sitemap.xml$', 'index', {'sitemaps' : sitemaps}),
(r'^sitemaps/(?P<section>\w+)\.xml$', 'sitemap', {'sitemaps' : sitemaps}),
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kml$', 'kml'),
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', 'kmz'),
(r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', 'kmz'),
)
22 changes: 22 additions & 0 deletions django/contrib/gis/views.py
@@ -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)

0 comments on commit 12b7c2a

Please sign in to comment.