2010-08-27 23:16:04 +08:00
|
|
|
from datetime import datetime
|
2012-01-29 17:30:28 +08:00
|
|
|
from django.conf.urls import patterns, url
|
|
|
|
from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap, views
|
|
|
|
from django.views.decorators.cache import cache_page
|
2010-08-27 23:16:04 +08:00
|
|
|
|
2013-03-23 09:57:48 +08:00
|
|
|
from django.contrib.sitemaps.tests.base import TestModel
|
|
|
|
|
|
|
|
|
2010-08-27 23:16:04 +08:00
|
|
|
class SimpleSitemap(Sitemap):
|
|
|
|
changefreq = "never"
|
|
|
|
priority = 0.5
|
2010-08-30 23:09:12 +08:00
|
|
|
location = '/location/'
|
2010-08-27 23:16:04 +08:00
|
|
|
lastmod = datetime.now()
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return [object()]
|
|
|
|
|
2013-07-23 22:25:21 +08:00
|
|
|
|
2013-09-17 22:21:11 +08:00
|
|
|
class EmptySitemap(Sitemap):
|
|
|
|
changefreq = "never"
|
|
|
|
priority = 0.5
|
|
|
|
location = '/location/'
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2013-07-23 22:25:21 +08:00
|
|
|
class FixedLastmodSitemap(SimpleSitemap):
|
|
|
|
lastmod = datetime(2013, 3, 13, 10, 0, 0)
|
|
|
|
|
|
|
|
|
|
|
|
class FixedLastmodMixedSitemap(Sitemap):
|
|
|
|
changefreq = "never"
|
|
|
|
priority = 0.5
|
|
|
|
location = '/location/'
|
|
|
|
loop = 0
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
o1 = TestModel()
|
|
|
|
o1.lastmod = datetime(2013, 3, 13, 10, 0, 0)
|
|
|
|
o2 = TestModel()
|
|
|
|
return [o1, o2]
|
|
|
|
|
|
|
|
|
2010-08-30 23:09:12 +08:00
|
|
|
simple_sitemaps = {
|
2010-08-27 23:16:04 +08:00
|
|
|
'simple': SimpleSitemap,
|
|
|
|
}
|
|
|
|
|
2013-09-17 22:21:11 +08:00
|
|
|
empty_sitemaps = {
|
|
|
|
'empty': EmptySitemap,
|
|
|
|
}
|
|
|
|
|
2013-07-23 22:25:21 +08:00
|
|
|
fixed_lastmod_sitemaps = {
|
|
|
|
'fixed-lastmod': FixedLastmodSitemap,
|
|
|
|
}
|
|
|
|
|
|
|
|
fixed_lastmod__mixed_sitemaps = {
|
|
|
|
'fixed-lastmod-mixed': FixedLastmodMixedSitemap,
|
|
|
|
}
|
|
|
|
|
2010-08-30 23:09:12 +08:00
|
|
|
generic_sitemaps = {
|
2013-03-23 09:57:48 +08:00
|
|
|
'generic': GenericSitemap({'queryset': TestModel.objects.all()}),
|
2010-08-30 23:09:12 +08:00
|
|
|
}
|
|
|
|
|
2010-09-11 07:30:46 +08:00
|
|
|
flatpage_sitemaps = {
|
|
|
|
'flatpages': FlatPageSitemap,
|
|
|
|
}
|
|
|
|
|
2010-08-27 23:16:04 +08:00
|
|
|
urlpatterns = patterns('django.contrib.sitemaps.views',
|
2010-12-13 06:56:29 +08:00
|
|
|
(r'^simple/index\.xml$', 'index', {'sitemaps': simple_sitemaps}),
|
2012-01-29 17:30:28 +08:00
|
|
|
(r'^simple/custom-index\.xml$', 'index',
|
|
|
|
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_index.xml'}),
|
|
|
|
(r'^simple/sitemap-(?P<section>.+)\.xml$', 'sitemap',
|
|
|
|
{'sitemaps': simple_sitemaps}),
|
2010-08-30 23:09:12 +08:00
|
|
|
(r'^simple/sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps}),
|
2012-01-29 17:30:28 +08:00
|
|
|
(r'^simple/custom-sitemap\.xml$', 'sitemap',
|
|
|
|
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'}),
|
2013-09-17 22:21:11 +08:00
|
|
|
(r'^empty/sitemap\.xml$', 'sitemap', {'sitemaps': empty_sitemaps}),
|
2013-07-23 22:25:21 +08:00
|
|
|
(r'^lastmod/sitemap\.xml$', 'sitemap', {'sitemaps': fixed_lastmod_sitemaps}),
|
|
|
|
(r'^lastmod-mixed/sitemap\.xml$', 'sitemap', {'sitemaps': fixed_lastmod__mixed_sitemaps}),
|
2010-08-30 23:09:12 +08:00
|
|
|
(r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}),
|
2010-09-11 07:30:46 +08:00
|
|
|
(r'^flatpages/sitemap\.xml$', 'sitemap', {'sitemaps': flatpage_sitemaps}),
|
2012-01-29 17:30:28 +08:00
|
|
|
url(r'^cached/index\.xml$', cache_page(1)(views.index),
|
|
|
|
{'sitemaps': simple_sitemaps, 'sitemap_url_name': 'cached_sitemap'}),
|
|
|
|
url(r'^cached/sitemap-(?P<section>.+)\.xml', cache_page(1)(views.sitemap),
|
|
|
|
{'sitemaps': simple_sitemaps}, name='cached_sitemap')
|
2010-08-27 23:16:04 +08:00
|
|
|
)
|