File: http.py

package info (click to toggle)
python-django 3%3A3.2.19-1%2Bdeb12u2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 56,696 kB
  • sloc: python: 264,418; javascript: 18,362; xml: 193; makefile: 178; sh: 43
file content (253 lines) | stat: -rw-r--r-- 7,253 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
from datetime import date, datetime

from django.conf.urls.i18n import i18n_patterns
from django.contrib.sitemaps import GenericSitemap, Sitemap, views
from django.http import HttpResponse
from django.urls import path
from django.utils import timezone
from django.views.decorators.cache import cache_page

from ..models import I18nTestModel, TestModel


class SimpleSitemap(Sitemap):
    changefreq = "never"
    priority = 0.5
    location = '/location/'
    lastmod = datetime.now()

    def items(self):
        return [object()]


class SimplePagedSitemap(Sitemap):
    def items(self):
        return [object() for x in range(Sitemap.limit + 1)]


class SimpleI18nSitemap(Sitemap):
    changefreq = "never"
    priority = 0.5
    i18n = True

    def items(self):
        return I18nTestModel.objects.order_by('pk').all()


class AlternatesI18nSitemap(SimpleI18nSitemap):
    alternates = True


class LimitedI18nSitemap(AlternatesI18nSitemap):
    languages = ['en', 'es']


class XDefaultI18nSitemap(AlternatesI18nSitemap):
    x_default = True


class EmptySitemap(Sitemap):
    changefreq = "never"
    priority = 0.5
    location = '/location/'


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]


class FixedNewerLastmodSitemap(SimpleSitemap):
    lastmod = datetime(2013, 4, 20, 5, 0, 0)


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))


def testmodelview(request, id):
    return HttpResponse()


simple_sitemaps = {
    'simple': SimpleSitemap,
}

simple_i18n_sitemaps = {
    'i18n': SimpleI18nSitemap,
}

alternates_i18n_sitemaps = {
    'i18n-alternates': AlternatesI18nSitemap,
}

limited_i18n_sitemaps = {
    'i18n-limited': LimitedI18nSitemap,
}

xdefault_i18n_sitemaps = {
    'i18n-xdefault': XDefaultI18nSitemap,
}

simple_sitemaps_not_callable = {
    'simple': SimpleSitemap(),
}

simple_sitemaps_paged = {
    'simple': SimplePagedSitemap,
}

empty_sitemaps = {
    'empty': EmptySitemap,
}

fixed_lastmod_sitemaps = {
    'fixed-lastmod': FixedLastmodSitemap,
}

fixed_lastmod_mixed_sitemaps = {
    'fixed-lastmod-mixed': FixedLastmodMixedSitemap,
}

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,
}

generic_sitemaps = {
    'generic': GenericSitemap({'queryset': TestModel.objects.order_by('pk').all()}),
}

generic_sitemaps_lastmod = {
    'generic': GenericSitemap({
        'queryset': TestModel.objects.order_by('pk').all(),
        'date_field': 'lastmod',
    }),
}

urlpatterns = [
    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,
        {'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_index.xml'}),
    path(
        'simple/sitemap-<section>.xml', views.sitemap,
        {'sitemaps': simple_sitemaps},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'simple/sitemap.xml', views.sitemap,
        {'sitemaps': simple_sitemaps},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'simple/i18n.xml', views.sitemap,
        {'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},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'simple/custom-sitemap.xml', views.sitemap,
        {'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'empty/sitemap.xml', views.sitemap,
        {'sitemaps': empty_sitemaps},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'lastmod/sitemap.xml', views.sitemap,
        {'sitemaps': fixed_lastmod_sitemaps},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'lastmod-mixed/sitemap.xml', views.sitemap,
        {'sitemaps': fixed_lastmod_mixed_sitemaps},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'lastmod/date-sitemap.xml', views.sitemap,
        {'sitemaps': {'date-sitemap': DateSiteMap}},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'lastmod/tz-sitemap.xml', views.sitemap,
        {'sitemaps': {'tz-sitemap': TimezoneSiteMap}},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'lastmod-sitemaps/mixed-ascending.xml', views.sitemap,
        {'sitemaps': sitemaps_lastmod_mixed_ascending},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'lastmod-sitemaps/mixed-descending.xml', views.sitemap,
        {'sitemaps': sitemaps_lastmod_mixed_descending},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'lastmod-sitemaps/ascending.xml', views.sitemap,
        {'sitemaps': sitemaps_lastmod_ascending},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'lastmod-sitemaps/descending.xml', views.sitemap,
        {'sitemaps': sitemaps_lastmod_descending},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'generic/sitemap.xml', views.sitemap,
        {'sitemaps': generic_sitemaps},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'generic-lastmod/sitemap.xml', views.sitemap,
        {'sitemaps': generic_sitemaps_lastmod},
        name='django.contrib.sitemaps.views.sitemap'),
    path(
        'cached/index.xml', cache_page(1)(views.index),
        {'sitemaps': simple_sitemaps, 'sitemap_url_name': 'cached_sitemap'}),
    path(
        'cached/sitemap-<section>.xml', cache_page(1)(views.sitemap),
        {'sitemaps': simple_sitemaps}, name='cached_sitemap'),
    path(
        'sitemap-without-entries/sitemap.xml', views.sitemap,
        {'sitemaps': {}}, name='django.contrib.sitemaps.views.sitemap'),
]

urlpatterns += i18n_patterns(
    path('i18n/testmodel/<int:id>/', testmodelview, name='i18n_testmodel'),
)