http.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from datetime import datetime
  2. from django.conf.urls import patterns, url
  3. from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap, views
  4. from django.views.decorators.cache import cache_page
  5. from django.contrib.sitemaps.tests.base import TestModel
  6. class SimpleSitemap(Sitemap):
  7. changefreq = "never"
  8. priority = 0.5
  9. location = '/location/'
  10. lastmod = datetime.now()
  11. def items(self):
  12. return [object()]
  13. class EmptySitemap(Sitemap):
  14. changefreq = "never"
  15. priority = 0.5
  16. location = '/location/'
  17. def items(self):
  18. return []
  19. class FixedLastmodSitemap(SimpleSitemap):
  20. lastmod = datetime(2013, 3, 13, 10, 0, 0)
  21. class FixedLastmodMixedSitemap(Sitemap):
  22. changefreq = "never"
  23. priority = 0.5
  24. location = '/location/'
  25. loop = 0
  26. def items(self):
  27. o1 = TestModel()
  28. o1.lastmod = datetime(2013, 3, 13, 10, 0, 0)
  29. o2 = TestModel()
  30. return [o1, o2]
  31. simple_sitemaps = {
  32. 'simple': SimpleSitemap,
  33. }
  34. empty_sitemaps = {
  35. 'empty': EmptySitemap,
  36. }
  37. fixed_lastmod_sitemaps = {
  38. 'fixed-lastmod': FixedLastmodSitemap,
  39. }
  40. fixed_lastmod__mixed_sitemaps = {
  41. 'fixed-lastmod-mixed': FixedLastmodMixedSitemap,
  42. }
  43. generic_sitemaps = {
  44. 'generic': GenericSitemap({'queryset': TestModel.objects.all()}),
  45. }
  46. flatpage_sitemaps = {
  47. 'flatpages': FlatPageSitemap,
  48. }
  49. urlpatterns = patterns('django.contrib.sitemaps.views',
  50. (r'^simple/index\.xml$', 'index', {'sitemaps': simple_sitemaps}),
  51. (r'^simple/custom-index\.xml$', 'index',
  52. {'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_index.xml'}),
  53. (r'^simple/sitemap-(?P<section>.+)\.xml$', 'sitemap',
  54. {'sitemaps': simple_sitemaps}),
  55. (r'^simple/sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps}),
  56. (r'^simple/custom-sitemap\.xml$', 'sitemap',
  57. {'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'}),
  58. (r'^empty/sitemap\.xml$', 'sitemap', {'sitemaps': empty_sitemaps}),
  59. (r'^lastmod/sitemap\.xml$', 'sitemap', {'sitemaps': fixed_lastmod_sitemaps}),
  60. (r'^lastmod-mixed/sitemap\.xml$', 'sitemap', {'sitemaps': fixed_lastmod__mixed_sitemaps}),
  61. (r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}),
  62. (r'^flatpages/sitemap\.xml$', 'sitemap', {'sitemaps': flatpage_sitemaps}),
  63. url(r'^cached/index\.xml$', cache_page(1)(views.index),
  64. {'sitemaps': simple_sitemaps, 'sitemap_url_name': 'cached_sitemap'}),
  65. url(r'^cached/sitemap-(?P<section>.+)\.xml', cache_page(1)(views.sitemap),
  66. {'sitemaps': simple_sitemaps}, name='cached_sitemap')
  67. )