App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / django / contrib / gis / sitemaps / georss.py
blobccb7dc2e91eff67b5f4cbabade482c4ca7a76571
1 from django.core import urlresolvers
2 from django.contrib.sitemaps import Sitemap
4 class GeoRSSSitemap(Sitemap):
5 """
6 A minimal hook to produce sitemaps for GeoRSS feeds.
7 """
8 def __init__(self, feed_dict, slug_dict=None):
9 """
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']}
26 """
27 # Setting up.
28 self.feed_dict = feed_dict
29 self.locations = []
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))
36 else:
37 self.locations.append(section)
39 def get_urls(self, page=1, site=None):
40 """
41 This method is overrridden so the appropriate `geo_format` attribute
42 is placed on each URL element.
43 """
44 urls = Sitemap.get_urls(self, page=page, site=site)
45 for url in urls: url['geo_format'] = 'georss'
46 return urls
48 def items(self):
49 return self.locations
51 def location(self, obj):
52 return urlresolvers.reverse('django.contrib.gis.views.feed', args=(obj,))