2014-09-10 01:34:40 +08:00
|
|
|
from datetime import date, datetime
|
2015-01-28 20:35:27 +08:00
|
|
|
|
2014-06-07 02:47:15 +08:00
|
|
|
from django.conf.urls.i18n import i18n_patterns
|
2015-01-28 20:35:27 +08:00
|
|
|
from django.contrib.sitemaps import GenericSitemap, Sitemap, views
|
2014-06-07 02:47:15 +08:00
|
|
|
from django.http import HttpResponse
|
2018-12-08 06:52:28 +08:00
|
|
|
from django.urls import path
|
2014-09-10 01:34:40 +08:00
|
|
|
from django.utils import timezone
|
2012-01-29 17:30:28 +08:00
|
|
|
from django.views.decorators.cache import cache_page
|
2010-08-27 23:16:04 +08:00
|
|
|
|
2015-02-10 21:11:25 +08:00
|
|
|
from ..models import I18nTestModel, TestModel
|
|
|
|
|
2013-03-23 09:57:48 +08:00
|
|
|
|
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
|
|
|
|
2017-03-18 03:25:50 +08:00
|
|
|
class SimplePagedSitemap(Sitemap):
|
|
|
|
def items(self):
|
|
|
|
return [object() for x in range(Sitemap.limit + 1)]
|
|
|
|
|
|
|
|
|
2014-06-07 02:47:15 +08:00
|
|
|
class SimpleI18nSitemap(Sitemap):
|
|
|
|
changefreq = "never"
|
|
|
|
priority = 0.5
|
|
|
|
i18n = True
|
|
|
|
|
|
|
|
def items(self):
|
2016-06-07 19:24:19 +08:00
|
|
|
return I18nTestModel.objects.order_by('pk').all()
|
2014-06-07 02:47:15 +08:00
|
|
|
|
|
|
|
|
2020-07-29 16:33:20 +08:00
|
|
|
class AlternatesI18nSitemap(SimpleI18nSitemap):
|
|
|
|
alternates = True
|
|
|
|
|
|
|
|
|
|
|
|
class LimitedI18nSitemap(AlternatesI18nSitemap):
|
|
|
|
languages = ['en', 'es']
|
|
|
|
|
|
|
|
|
|
|
|
class XDefaultI18nSitemap(AlternatesI18nSitemap):
|
|
|
|
x_default = True
|
|
|
|
|
|
|
|
|
2013-09-17 22:21:11 +08:00
|
|
|
class EmptySitemap(Sitemap):
|
|
|
|
changefreq = "never"
|
|
|
|
priority = 0.5
|
|
|
|
location = '/location/'
|
|
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
|
2015-12-27 02:01:25 +08:00
|
|
|
class FixedNewerLastmodSitemap(SimpleSitemap):
|
|
|
|
lastmod = datetime(2013, 4, 20, 5, 0, 0)
|
|
|
|
|
|
|
|
|
2014-09-10 01:34:40 +08: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-07 02:47:15 +08:00
|
|
|
def testmodelview(request, id):
|
|
|
|
return HttpResponse()
|
|
|
|
|
|
|
|
|
2010-08-30 23:09:12 +08:00
|
|
|
simple_sitemaps = {
|
2010-08-27 23:16:04 +08:00
|
|
|
'simple': SimpleSitemap,
|
|
|
|
}
|
|
|
|
|
2020-07-29 16:33:20 +08:00
|
|
|
simple_i18n_sitemaps = {
|
|
|
|
'i18n': SimpleI18nSitemap,
|
|
|
|
}
|
|
|
|
|
|
|
|
alternates_i18n_sitemaps = {
|
|
|
|
'i18n-alternates': AlternatesI18nSitemap,
|
|
|
|
}
|
|
|
|
|
|
|
|
limited_i18n_sitemaps = {
|
|
|
|
'i18n-limited': LimitedI18nSitemap,
|
|
|
|
}
|
|
|
|
|
|
|
|
xdefault_i18n_sitemaps = {
|
|
|
|
'i18n-xdefault': XDefaultI18nSitemap,
|
2014-06-07 02:47:15 +08:00
|
|
|
}
|
|
|
|
|
2017-03-18 03:25:50 +08:00
|
|
|
simple_sitemaps_not_callable = {
|
|
|
|
'simple': SimpleSitemap(),
|
|
|
|
}
|
|
|
|
|
|
|
|
simple_sitemaps_paged = {
|
|
|
|
'simple': SimplePagedSitemap,
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
|
2020-07-29 16:33:20 +08:00
|
|
|
fixed_lastmod_mixed_sitemaps = {
|
2013-07-23 22:25:21 +08:00
|
|
|
'fixed-lastmod-mixed': FixedLastmodMixedSitemap,
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:22:08 +08:00
|
|
|
sitemaps_lastmod_mixed_ascending = {
|
|
|
|
'no-lastmod': EmptySitemap,
|
|
|
|
'lastmod': FixedLastmodSitemap,
|
|
|
|
}
|
|
|
|
|
|
|
|
sitemaps_lastmod_mixed_descending = {
|
|
|
|
'lastmod': FixedLastmodSitemap,
|
|
|
|
'no-lastmod': EmptySitemap,
|
|
|
|
}
|
|
|
|
|
|
|
|
sitemaps_lastmod_ascending = {
|
|
|
|
'date': DateSiteMap,
|
|
|
|
'datetime': FixedLastmodSitemap,
|
|
|
|
'datetime-newer': FixedNewerLastmodSitemap,
|
|
|
|
}
|
|
|
|
|
|
|
|
sitemaps_lastmod_descending = {
|
|
|
|
'datetime-newer': FixedNewerLastmodSitemap,
|
|
|
|
'datetime': FixedLastmodSitemap,
|
|
|
|
'date': DateSiteMap,
|
|
|
|
}
|
2015-12-27 02:01:25 +08:00
|
|
|
|
2010-08-30 23:09:12 +08:00
|
|
|
generic_sitemaps = {
|
2016-06-07 19:24:19 +08:00
|
|
|
'generic': GenericSitemap({'queryset': TestModel.objects.order_by('pk').all()}),
|
2010-08-30 23:09:12 +08:00
|
|
|
}
|
|
|
|
|
2017-03-18 03:25:50 +08:00
|
|
|
generic_sitemaps_lastmod = {
|
|
|
|
'generic': GenericSitemap({
|
|
|
|
'queryset': TestModel.objects.order_by('pk').all(),
|
|
|
|
'date_field': 'lastmod',
|
|
|
|
}),
|
|
|
|
}
|
2014-04-02 08:46:34 +08:00
|
|
|
|
|
|
|
urlpatterns = [
|
2018-12-08 06:52:28 +08:00
|
|
|
path('simple/index.xml', views.index, {'sitemaps': simple_sitemaps}),
|
|
|
|
path('simple-paged/index.xml', views.index, {'sitemaps': simple_sitemaps_paged}),
|
|
|
|
path('simple-not-callable/index.xml', views.index, {'sitemaps': simple_sitemaps_not_callable}),
|
|
|
|
path(
|
|
|
|
'simple/custom-index.xml', views.index,
|
2012-01-29 17:30:28 +08:00
|
|
|
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_index.xml'}),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'simple/sitemap-<section>.xml', views.sitemap,
|
2014-09-19 06:40:51 +08:00
|
|
|
{'sitemaps': simple_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'simple/sitemap.xml', views.sitemap,
|
2014-09-19 06:40:51 +08:00
|
|
|
{'sitemaps': simple_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'simple/i18n.xml', views.sitemap,
|
2020-07-29 16:33:20 +08:00
|
|
|
{'sitemaps': simple_i18n_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
path(
|
|
|
|
'alternates/i18n.xml', views.sitemap,
|
|
|
|
{'sitemaps': alternates_i18n_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
path(
|
|
|
|
'limited/i18n.xml', views.sitemap,
|
|
|
|
{'sitemaps': limited_i18n_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
|
|
|
path(
|
|
|
|
'x-default/i18n.xml', views.sitemap,
|
|
|
|
{'sitemaps': xdefault_i18n_sitemaps},
|
2014-09-19 06:40:51 +08:00
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'simple/custom-sitemap.xml', views.sitemap,
|
2014-09-19 06:40:51 +08:00
|
|
|
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'empty/sitemap.xml', views.sitemap,
|
2014-09-19 06:40:51 +08:00
|
|
|
{'sitemaps': empty_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'lastmod/sitemap.xml', views.sitemap,
|
2014-09-19 06:40:51 +08:00
|
|
|
{'sitemaps': fixed_lastmod_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'lastmod-mixed/sitemap.xml', views.sitemap,
|
2020-07-29 16:33:20 +08:00
|
|
|
{'sitemaps': fixed_lastmod_mixed_sitemaps},
|
2014-09-19 06:40:51 +08:00
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'lastmod/date-sitemap.xml', views.sitemap,
|
2014-09-19 06:40:51 +08:00
|
|
|
{'sitemaps': {'date-sitemap': DateSiteMap}},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'lastmod/tz-sitemap.xml', views.sitemap,
|
2014-09-19 06:40:51 +08:00
|
|
|
{'sitemaps': {'tz-sitemap': TimezoneSiteMap}},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'lastmod-sitemaps/mixed-ascending.xml', views.sitemap,
|
2015-12-27 02:01:25 +08:00
|
|
|
{'sitemaps': sitemaps_lastmod_mixed_ascending},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'lastmod-sitemaps/mixed-descending.xml', views.sitemap,
|
2015-12-27 02:01:25 +08:00
|
|
|
{'sitemaps': sitemaps_lastmod_mixed_descending},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'lastmod-sitemaps/ascending.xml', views.sitemap,
|
2015-12-27 02:01:25 +08:00
|
|
|
{'sitemaps': sitemaps_lastmod_ascending},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'lastmod-sitemaps/descending.xml', views.sitemap,
|
2015-12-27 02:01:25 +08:00
|
|
|
{'sitemaps': sitemaps_lastmod_descending},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'generic/sitemap.xml', views.sitemap,
|
2014-09-19 06:40:51 +08:00
|
|
|
{'sitemaps': generic_sitemaps},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'generic-lastmod/sitemap.xml', views.sitemap,
|
2017-03-18 03:25:50 +08:00
|
|
|
{'sitemaps': generic_sitemaps_lastmod},
|
|
|
|
name='django.contrib.sitemaps.views.sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'cached/index.xml', cache_page(1)(views.index),
|
2012-01-29 17:30:28 +08:00
|
|
|
{'sitemaps': simple_sitemaps, 'sitemap_url_name': 'cached_sitemap'}),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'cached/sitemap-<section>.xml', cache_page(1)(views.sitemap),
|
2016-01-25 03:35:46 +08:00
|
|
|
{'sitemaps': simple_sitemaps}, name='cached_sitemap'),
|
2018-12-08 06:52:28 +08:00
|
|
|
path(
|
|
|
|
'sitemap-without-entries/sitemap.xml', views.sitemap,
|
2016-01-25 03:35:46 +08:00
|
|
|
{'sitemaps': {}}, name='django.contrib.sitemaps.views.sitemap'),
|
2014-04-02 08:46:34 +08:00
|
|
|
]
|
2014-06-07 02:47:15 +08:00
|
|
|
|
|
|
|
urlpatterns += i18n_patterns(
|
2018-12-08 06:52:28 +08:00
|
|
|
path('i18n/testmodel/<int:id>/', testmodelview, name='i18n_testmodel'),
|
2014-06-07 02:47:15 +08:00
|
|
|
)
|