Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 12b7c2a702bea68e53c438fa2c7a4a01d890695d 1 parent 24f4764
Jannis Leidel authored
12  django/contrib/gis/sitemaps/georss.py
@@ -8,13 +8,13 @@ class GeoRSSSitemap(Sitemap):
8 8
     def __init__(self, feed_dict, slug_dict=None):
9 9
         """
10 10
         This sitemap object initializes on a feed dictionary (as would be passed
11  
-        to `django.contrib.syndication.views.feed`) and a slug dictionary.  
  11
+        to `django.contrib.gis.views.feed`) and a slug dictionary.
12 12
         If the slug dictionary is not defined, then it's assumed the keys provide
13 13
         the URL parameter to the feed.  However, if you have a complex feed (e.g.,
14 14
         you override `get_object`, then you'll need to provide a slug dictionary.
15  
-        The slug dictionary should have the same keys as the feed dictionary, but 
16  
-        each value in the slug dictionary should be a sequence of slugs that may 
17  
-        be used for valid feeds.  For example, let's say we have a feed that 
  15
+        The slug dictionary should have the same keys as the feed dictionary, but
  16
+        each value in the slug dictionary should be a sequence of slugs that may
  17
+        be used for valid feeds.  For example, let's say we have a feed that
18 18
         returns objects for a specific ZIP code in our feed dictionary:
19 19
 
20 20
             feed_dict = {'zipcode' : ZipFeed}
@@ -35,7 +35,7 @@ def __init__(self, feed_dict, slug_dict=None):
35 35
                     self.locations.append('%s/%s' % (section, slug))
36 36
             else:
37 37
                 self.locations.append(section)
38  
- 
  38
+
39 39
     def get_urls(self, page=1, site=None):
40 40
         """
41 41
         This method is overrridden so the appropriate `geo_format` attribute
@@ -49,5 +49,5 @@ def items(self):
49 49
         return self.locations
50 50
 
51 51
     def location(self, obj):
52  
-        return urlresolvers.reverse('django.contrib.syndication.views.feed', args=(obj,))
  52
+        return urlresolvers.reverse('django.contrib.gis.views.feed', args=(obj,))
53 53
 
11  django/contrib/gis/tests/__init__.py
@@ -100,15 +100,16 @@ def setup_test_environment(self, **kwargs):
100 100
 
101 101
         # Constructing the new INSTALLED_APPS, and including applications
102 102
         # within the GeoDjango test namespace.
103  
-        new_installed =  ['django.contrib.sites',
104  
-                          'django.contrib.sitemaps',
105  
-                          'django.contrib.gis',
106  
-                          ]
  103
+        new_installed =  [
  104
+            'django.contrib.sites',
  105
+            'django.contrib.sitemaps',
  106
+            'django.contrib.gis',
  107
+        ]
107 108
 
108 109
         # Calling out to `geo_apps` to get GeoDjango applications supported
109 110
         # for testing.
110 111
         new_installed.extend(geo_apps())
111  
-        settings.INSTALLED_APPS = new_installed
  112
+        settings.INSTALLED_APPS = list(self.old_installed) + new_installed
112 113
 
113 114
         # SITE_ID needs to be set
114 115
         settings.SITE_ID = 1
4  django/contrib/gis/tests/geoapp/urls.py
@@ -2,7 +2,7 @@
2 2
 from feeds import feed_dict
3 3
 
4 4
 urlpatterns = patterns('',
5  
-    (r'^feeds/(?P<url>.*)/$', 'django.contrib.syndication.views.feed', {'feed_dict': feed_dict}),
  5
+    (r'^feeds/(?P<url>.*)/$', 'django.contrib.gis.views.feed', {'feed_dict': feed_dict}),
6 6
 )
7 7
 
8 8
 from sitemaps import sitemaps
@@ -10,5 +10,5 @@
10 10
     (r'^sitemap.xml$', 'index', {'sitemaps' : sitemaps}),
11 11
     (r'^sitemaps/(?P<section>\w+)\.xml$', 'sitemap', {'sitemaps' : sitemaps}),
12 12
     (r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kml$', 'kml'),
13  
-    (r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', 'kmz'),                
  13
+    (r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', 'kmz'),
14 14
 )
22  django/contrib/gis/views.py
... ...
@@ -0,0 +1,22 @@
  1
+from django.http import Http404
  2
+
  3
+def feed(request, url, feed_dict=None):
  4
+    """Provided for backwards compatibility."""
  5
+    if not feed_dict:
  6
+        raise Http404("No feeds are registered.")
  7
+
  8
+    try:
  9
+        slug, param = url.split('/', 1)
  10
+    except ValueError:
  11
+        slug, param = url, ''
  12
+
  13
+    try:
  14
+        f = feed_dict[slug]
  15
+    except KeyError:
  16
+        raise Http404("Slug %r isn't registered." % slug)
  17
+
  18
+    instance = f()
  19
+    instance.feed_url = getattr(f, 'feed_url', None) or request.path
  20
+    instance.title_template = f.title_template or ('feeds/%s_title.html' % slug)
  21
+    instance.description_template = f.description_template or ('feeds/%s_description.html' % slug)
  22
+    return instance(request)

0 notes on commit 12b7c2a

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