PageRenderTime 149ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/django/contrib/gis/sitemaps/georss.py

https://code.google.com/p/mango-py/
Python | 53 lines | 34 code | 4 blank | 15 comment | 3 complexity | f3314c6b9e852edb8faeb930e95e83c8 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.core import urlresolvers
  2. from django.contrib.sitemaps import Sitemap
  3. class GeoRSSSitemap(Sitemap):
  4. """
  5. A minimal hook to produce sitemaps for GeoRSS feeds.
  6. """
  7. def __init__(self, feed_dict, slug_dict=None):
  8. """
  9. This sitemap object initializes on a feed dictionary (as would be passed
  10. to `django.contrib.syndication.views.feed`) and a slug dictionary.
  11. If the slug dictionary is not defined, then it's assumed the keys provide
  12. the URL parameter to the feed. However, if you have a complex feed (e.g.,
  13. you override `get_object`, then you'll need to provide a slug dictionary.
  14. The slug dictionary should have the same keys as the feed dictionary, but
  15. each value in the slug dictionary should be a sequence of slugs that may
  16. be used for valid feeds. For example, let's say we have a feed that
  17. returns objects for a specific ZIP code in our feed dictionary:
  18. feed_dict = {'zipcode' : ZipFeed}
  19. Then we would use a slug dictionary with a list of the zip code slugs
  20. corresponding to feeds you want listed in the sitemap:
  21. slug_dict = {'zipcode' : ['77002', '77054']}
  22. """
  23. # Setting up.
  24. self.feed_dict = feed_dict
  25. self.locations = []
  26. if slug_dict is None: slug_dict = {}
  27. # Getting the feed locations.
  28. for section in feed_dict.keys():
  29. if slug_dict.get(section, False):
  30. for slug in slug_dict[section]:
  31. self.locations.append('%s/%s' % (section, slug))
  32. else:
  33. self.locations.append(section)
  34. def get_urls(self, page=1, site=None):
  35. """
  36. This method is overrridden so the appropriate `geo_format` attribute
  37. is placed on each URL element.
  38. """
  39. urls = Sitemap.get_urls(self, page=page, site=site)
  40. for url in urls: url['geo_format'] = 'georss'
  41. return urls
  42. def items(self):
  43. return self.locations
  44. def location(self, obj):
  45. return urlresolvers.reverse('django.contrib.syndication.views.feed', args=(obj,))