2014-09-09 17:34:40 +00:00
|
|
|
from datetime import date, datetime
|
2015-01-28 12:35:27 +00:00
|
|
|
|
2014-04-02 00:46:34 +00:00
|
|
|
from django.conf.urls import url
|
2014-06-06 18:47:15 +00:00
|
|
|
from django.conf.urls.i18n import i18n_patterns
|
2015-01-28 12:35:27 +00:00
|
|
|
from django.contrib.sitemaps import GenericSitemap, Sitemap, views
|
2014-06-06 18:47:15 +00:00
|
|
|
from django.http import HttpResponse
|
2014-09-09 17:34:40 +00:00
|
|
|
from django.utils import timezone
|
2012-01-29 09:30:28 +00:00
|
|
|
from django.views.decorators.cache import cache_page
|
2010-08-27 15:16:04 +00:00
|
|
|
|
2015-02-10 13:11:25 +00:00
|
|
|
from ..models import I18nTestModel, TestModel
|
|
|
|
|
2013-03-23 01:57:48 +00:00
|
|
|
|
2010-08-27 15:16:04 +00:00
|
|
|
class SimpleSitemap(Sitemap):
|
|
|
|
changefreq = "never"
|
|
|
|
priority = 0.5
|
2010-08-30 15:09:12 +00:00
|
|
|
location = '/location/'
|
2010-08-27 15:16:04 +00:00
|
|
|
lastmod = datetime.now()
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return [object()]
|
|
|
|
|
2013-07-23 14:25:21 +00:00
|
|
|
|
2014-06-06 18:47:15 +00:00
|
|
|
class SimpleI18nSitemap(Sitemap):
|
|
|
|
changefreq = "never"
|
|
|
|
priority = 0.5
|
|
|
|
i18n = True
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return I18nTestModel.objects.all()
|
|
|
|
|
|
|
|
|
2013-09-17 14:21:11 +00:00
|
|
|
class EmptySitemap(Sitemap):
|
|
|
|
changefreq = "never"
|
|
|
|
priority = 0.5
|
|
|
|
location = '/location/'
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2013-07-23 14:25:21 +00: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]
|
|
|
|
|
|
|
|
|
2014-09-09 17:34:40 +00:00
|
|
|
class DateSiteMap(SimpleSitemap):
|
|
|
|
lastmod = date(2013, 3, 13)
|
|
|
|
|
|
|
|
|
|
|
|
class TimezoneSiteMap(SimpleSitemap):
|
|
|
|
lastmod = datetime(2013, 3, 13, 10, 0, 0, tzinfo=timezone.get_fixed_timezone(-300))
|
|
|
|
|
|
|
|
|
2014-06-06 18:47:15 +00:00
|
|
|
def testmodelview(request, id):
|
|
|
|
return HttpResponse()
|
|
|
|
|
|
|
|
|
2010-08-30 15:09:12 +00:00
|
|
|
simple_sitemaps = {
|
2010-08-27 15:16:04 +00:00
|
|
|
'simple': SimpleSitemap,
|
|
|
|
}
|
|
|
|
|
2014-06-06 18:47:15 +00:00
|
|
|
simple_i18nsitemaps = {
|
|
|
|
'simple': SimpleI18nSitemap,
|
|
|
|
}
|
|
|
|
|
2013-09-17 14:21:11 +00:00
|
|
|
empty_sitemaps = {
|
|
|
|
'empty': EmptySitemap,
|
|
|
|
}
|
|
|
|
|
2013-07-23 14:25:21 +00:00
|
|
|
fixed_lastmod_sitemaps = {
|
|
|
|
'fixed-lastmod': FixedLastmodSitemap,
|
|
|
|
}
|
|
|
|
|
|
|
|
fixed_lastmod__mixed_sitemaps = {
|
|
|
|
'fixed-lastmod-mixed': FixedLastmodMixedSitemap,
|
|
|
|
}
|
|
|
|
|
2010-08-30 15:09:12 +00:00
|
|
|
generic_sitemaps = {
|
2013-03-23 01:57:48 +00:00
|
|
|
'generic': GenericSitemap({'queryset': TestModel.objects.all()}),
|
2010-08-30 15:09:12 +00:00
|
|
|
}
|
|
|
|
|
2014-04-02 00:46:34 +00:00
|
|
|
|
|
|
|
urlpatterns = [
|
|
|
|
url(r'^simple/index\.xml$', views.index, {'sitemaps': simple_sitemaps}),
|
|
|
|
url(r'^simple/custom-index\.xml$', views.index,
|
2012-01-29 09:30:28 +00:00
|
|
|
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_index.xml'}),
|
2014-04-02 00:46:34 +00:00
|
|
|
url(r'^simple/sitemap-(?P<section>.+)\.xml$', views.sitemap,
|
2014-09-18 22:40:51 +00:00
|
|
|
{'sitemaps': simple_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
url(r'^simple/sitemap\.xml$', views.sitemap,
|
|
|
|
{'sitemaps': simple_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
url(r'^simple/i18n\.xml$', views.sitemap,
|
|
|
|
{'sitemaps': simple_i18nsitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2014-04-02 00:46:34 +00:00
|
|
|
url(r'^simple/custom-sitemap\.xml$', views.sitemap,
|
2014-09-18 22:40:51 +00:00
|
|
|
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
url(r'^empty/sitemap\.xml$', views.sitemap,
|
|
|
|
{'sitemaps': empty_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
url(r'^lastmod/sitemap\.xml$', views.sitemap,
|
|
|
|
{'sitemaps': fixed_lastmod_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
url(r'^lastmod-mixed/sitemap\.xml$', views.sitemap,
|
|
|
|
{'sitemaps': fixed_lastmod__mixed_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2014-09-09 17:34:40 +00:00
|
|
|
url(r'^lastmod/date-sitemap.xml$', views.sitemap,
|
2014-09-18 22:40:51 +00:00
|
|
|
{'sitemaps': {'date-sitemap': DateSiteMap}},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2014-09-09 17:34:40 +00:00
|
|
|
url(r'^lastmod/tz-sitemap.xml$', views.sitemap,
|
2014-09-18 22:40:51 +00:00
|
|
|
{'sitemaps': {'tz-sitemap': TimezoneSiteMap}},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
url(r'^generic/sitemap\.xml$', views.sitemap,
|
|
|
|
{'sitemaps': generic_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2012-01-29 09:30:28 +00: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')
|
2014-04-02 00:46:34 +00:00
|
|
|
]
|
2014-06-06 18:47:15 +00:00
|
|
|
|
|
|
|
urlpatterns += i18n_patterns(
|
|
|
|
url(r'^i18n/testmodel/(?P<id>\d+)/$', testmodelview, name='i18n_testmodel'),
|
|
|
|
)
|