1 from django
.core
import urlresolvers
2 from django
.contrib
.sitemaps
import Sitemap
4 class GeoRSSSitemap(Sitemap
):
6 A minimal hook to produce sitemaps for GeoRSS feeds.
8 def __init__(self
, feed_dict
, slug_dict
=None):
10 This sitemap object initializes on a feed dictionary (as would be passed
11 to `django.contrib.gis.views.feed`) and a slug dictionary.
12 If the slug dictionary is not defined, then it's assumed the keys provide
13 the URL parameter to the feed. However, if you have a complex feed (e.g.,
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
18 returns objects for a specific ZIP code in our feed dictionary:
20 feed_dict = {'zipcode' : ZipFeed}
22 Then we would use a slug dictionary with a list of the zip code slugs
23 corresponding to feeds you want listed in the sitemap:
25 slug_dict = {'zipcode' : ['77002', '77054']}
28 self
.feed_dict
= feed_dict
30 if slug_dict
is None: slug_dict
= {}
31 # Getting the feed locations.
32 for section
in feed_dict
.keys():
33 if slug_dict
.get(section
, False):
34 for slug
in slug_dict
[section
]:
35 self
.locations
.append('%s/%s' % (section
, slug
))
37 self
.locations
.append(section
)
39 def get_urls(self
, page
=1, site
=None):
41 This method is overrridden so the appropriate `geo_format` attribute
42 is placed on each URL element.
44 urls
= Sitemap
.get_urls(self
, page
=page
, site
=site
)
45 for url
in urls
: url
['geo_format'] = 'georss'
51 def location(self
, obj
):
52 return urlresolvers
.reverse('django.contrib.gis.views.feed', args
=(obj
,))