Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- testbed/django__django/django/__init__.py +24 -0
- testbed/django__django/django/__main__.py +9 -0
- testbed/django__django/django/shortcuts.py +155 -0
- testbed/django__django/django/views/__init__.py +3 -0
- testbed/django__django/django/views/csrf.py +79 -0
- testbed/django__django/django/views/debug.py +665 -0
- testbed/django__django/django/views/decorators/clickjacking.py +90 -0
- testbed/django__django/django/views/decorators/debug.py +145 -0
- testbed/django__django/django/views/decorators/vary.py +44 -0
- testbed/django__django/django/views/generic/__init__.py +39 -0
- testbed/django__django/django/views/generic/dates.py +795 -0
- testbed/django__django/django/views/generic/edit.py +274 -0
- testbed/django__django/django/views/generic/list.py +220 -0
- testbed/django__django/django/views/i18n.py +251 -0
- testbed/django__django/django/views/static.py +121 -0
- testbed/django__django/django/views/templates/csrf_403.html +84 -0
- testbed/django__django/django/views/templates/directory_index.html +21 -0
- testbed/django__django/django/views/templates/technical_404.html +82 -0
- testbed/django__django/django/views/templates/technical_500.html +491 -0
- testbed/django__django/django/views/templates/technical_500.txt +66 -0
- testbed/django__django/docs/_ext/djangodocs.py +396 -0
- testbed/django__django/docs/_theme/djangodocs-epub/epub-cover.html +10 -0
- testbed/django__django/docs/_theme/djangodocs-epub/static/epub.css +66 -0
- testbed/django__django/docs/_theme/djangodocs-epub/theme.conf +8 -0
- testbed/django__django/docs/_theme/djangodocs/genindex.html +4 -0
- testbed/django__django/docs/_theme/djangodocs/layout.html +147 -0
- testbed/django__django/docs/_theme/djangodocs/modindex.html +3 -0
- testbed/django__django/docs/_theme/djangodocs/search.html +3 -0
- testbed/django__django/docs/_theme/djangodocs/static/console-tabs.css +46 -0
- testbed/django__django/docs/_theme/djangodocs/static/default.css +3 -0
- testbed/django__django/docs/_theme/djangodocs/static/djangodocs.css +145 -0
- testbed/django__django/docs/_theme/djangodocs/static/fontawesome/LICENSE.txt +34 -0
- testbed/django__django/docs/_theme/djangodocs/static/fontawesome/README.md +7 -0
- testbed/django__django/docs/_theme/djangodocs/static/fontawesome/css/fa-brands.min.css +5 -0
- testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.eot +0 -0
- testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.svg +0 -0
- testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.ttf +0 -0
- testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.woff +0 -0
- testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.woff2 +0 -0
- testbed/django__django/docs/_theme/djangodocs/static/homepage.css +22 -0
- testbed/django__django/docs/_theme/djangodocs/static/reset-fonts-grids.css +8 -0
- testbed/django__django/docs/_theme/djangodocs/theme.conf +4 -0
- testbed/django__django/docs/faq/admin.txt +111 -0
- testbed/django__django/docs/faq/contributing.txt +107 -0
- testbed/django__django/docs/faq/general.txt +219 -0
- testbed/django__django/docs/faq/help.txt +93 -0
- testbed/django__django/docs/faq/index.txt +15 -0
- testbed/django__django/docs/faq/install.txt +90 -0
- testbed/django__django/docs/faq/models.txt +97 -0
- testbed/django__django/docs/faq/troubleshooting.txt +57 -0
testbed/django__django/django/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.utils.version import get_version
|
| 2 |
+
|
| 3 |
+
VERSION = (5, 0, 0, "alpha", 0)
|
| 4 |
+
|
| 5 |
+
__version__ = get_version(VERSION)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def setup(set_prefix=True):
|
| 9 |
+
"""
|
| 10 |
+
Configure the settings (this happens as a side effect of accessing the
|
| 11 |
+
first setting), configure logging and populate the app registry.
|
| 12 |
+
Set the thread-local urlresolvers script prefix if `set_prefix` is True.
|
| 13 |
+
"""
|
| 14 |
+
from django.apps import apps
|
| 15 |
+
from django.conf import settings
|
| 16 |
+
from django.urls import set_script_prefix
|
| 17 |
+
from django.utils.log import configure_logging
|
| 18 |
+
|
| 19 |
+
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
|
| 20 |
+
if set_prefix:
|
| 21 |
+
set_script_prefix(
|
| 22 |
+
"/" if settings.FORCE_SCRIPT_NAME is None else settings.FORCE_SCRIPT_NAME
|
| 23 |
+
)
|
| 24 |
+
apps.populate(settings.INSTALLED_APPS)
|
testbed/django__django/django/__main__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Invokes django-admin when the django module is run as a script.
|
| 3 |
+
|
| 4 |
+
Example: python -m django check
|
| 5 |
+
"""
|
| 6 |
+
from django.core import management
|
| 7 |
+
|
| 8 |
+
if __name__ == "__main__":
|
| 9 |
+
management.execute_from_command_line()
|
testbed/django__django/django/shortcuts.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module collects helper functions and classes that "span" multiple levels
|
| 3 |
+
of MVC. In other words, these functions/classes introduce controlled coupling
|
| 4 |
+
for convenience's sake.
|
| 5 |
+
"""
|
| 6 |
+
from django.http import (
|
| 7 |
+
Http404,
|
| 8 |
+
HttpResponse,
|
| 9 |
+
HttpResponsePermanentRedirect,
|
| 10 |
+
HttpResponseRedirect,
|
| 11 |
+
)
|
| 12 |
+
from django.template import loader
|
| 13 |
+
from django.urls import NoReverseMatch, reverse
|
| 14 |
+
from django.utils.functional import Promise
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def render(
|
| 18 |
+
request, template_name, context=None, content_type=None, status=None, using=None
|
| 19 |
+
):
|
| 20 |
+
"""
|
| 21 |
+
Return an HttpResponse whose content is filled with the result of calling
|
| 22 |
+
django.template.loader.render_to_string() with the passed arguments.
|
| 23 |
+
"""
|
| 24 |
+
content = loader.render_to_string(template_name, context, request, using=using)
|
| 25 |
+
return HttpResponse(content, content_type, status)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def redirect(to, *args, permanent=False, **kwargs):
|
| 29 |
+
"""
|
| 30 |
+
Return an HttpResponseRedirect to the appropriate URL for the arguments
|
| 31 |
+
passed.
|
| 32 |
+
|
| 33 |
+
The arguments could be:
|
| 34 |
+
|
| 35 |
+
* A model: the model's `get_absolute_url()` function will be called.
|
| 36 |
+
|
| 37 |
+
* A view name, possibly with arguments: `urls.reverse()` will be used
|
| 38 |
+
to reverse-resolve the name.
|
| 39 |
+
|
| 40 |
+
* A URL, which will be used as-is for the redirect location.
|
| 41 |
+
|
| 42 |
+
Issues a temporary redirect by default; pass permanent=True to issue a
|
| 43 |
+
permanent redirect.
|
| 44 |
+
"""
|
| 45 |
+
redirect_class = (
|
| 46 |
+
HttpResponsePermanentRedirect if permanent else HttpResponseRedirect
|
| 47 |
+
)
|
| 48 |
+
return redirect_class(resolve_url(to, *args, **kwargs))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _get_queryset(klass):
|
| 52 |
+
"""
|
| 53 |
+
Return a QuerySet or a Manager.
|
| 54 |
+
Duck typing in action: any class with a `get()` method (for
|
| 55 |
+
get_object_or_404) or a `filter()` method (for get_list_or_404) might do
|
| 56 |
+
the job.
|
| 57 |
+
"""
|
| 58 |
+
# If it is a model class or anything else with ._default_manager
|
| 59 |
+
if hasattr(klass, "_default_manager"):
|
| 60 |
+
return klass._default_manager.all()
|
| 61 |
+
return klass
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def get_object_or_404(klass, *args, **kwargs):
|
| 65 |
+
"""
|
| 66 |
+
Use get() to return an object, or raise an Http404 exception if the object
|
| 67 |
+
does not exist.
|
| 68 |
+
|
| 69 |
+
klass may be a Model, Manager, or QuerySet object. All other passed
|
| 70 |
+
arguments and keyword arguments are used in the get() query.
|
| 71 |
+
|
| 72 |
+
Like with QuerySet.get(), MultipleObjectsReturned is raised if more than
|
| 73 |
+
one object is found.
|
| 74 |
+
"""
|
| 75 |
+
queryset = _get_queryset(klass)
|
| 76 |
+
if not hasattr(queryset, "get"):
|
| 77 |
+
klass__name = (
|
| 78 |
+
klass.__name__ if isinstance(klass, type) else klass.__class__.__name__
|
| 79 |
+
)
|
| 80 |
+
raise ValueError(
|
| 81 |
+
"First argument to get_object_or_404() must be a Model, Manager, "
|
| 82 |
+
"or QuerySet, not '%s'." % klass__name
|
| 83 |
+
)
|
| 84 |
+
try:
|
| 85 |
+
return queryset.get(*args, **kwargs)
|
| 86 |
+
except queryset.model.DoesNotExist:
|
| 87 |
+
raise Http404(
|
| 88 |
+
"No %s matches the given query." % queryset.model._meta.object_name
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def get_list_or_404(klass, *args, **kwargs):
|
| 93 |
+
"""
|
| 94 |
+
Use filter() to return a list of objects, or raise an Http404 exception if
|
| 95 |
+
the list is empty.
|
| 96 |
+
|
| 97 |
+
klass may be a Model, Manager, or QuerySet object. All other passed
|
| 98 |
+
arguments and keyword arguments are used in the filter() query.
|
| 99 |
+
"""
|
| 100 |
+
queryset = _get_queryset(klass)
|
| 101 |
+
if not hasattr(queryset, "filter"):
|
| 102 |
+
klass__name = (
|
| 103 |
+
klass.__name__ if isinstance(klass, type) else klass.__class__.__name__
|
| 104 |
+
)
|
| 105 |
+
raise ValueError(
|
| 106 |
+
"First argument to get_list_or_404() must be a Model, Manager, or "
|
| 107 |
+
"QuerySet, not '%s'." % klass__name
|
| 108 |
+
)
|
| 109 |
+
obj_list = list(queryset.filter(*args, **kwargs))
|
| 110 |
+
if not obj_list:
|
| 111 |
+
raise Http404(
|
| 112 |
+
"No %s matches the given query." % queryset.model._meta.object_name
|
| 113 |
+
)
|
| 114 |
+
return obj_list
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def resolve_url(to, *args, **kwargs):
|
| 118 |
+
"""
|
| 119 |
+
Return a URL appropriate for the arguments passed.
|
| 120 |
+
|
| 121 |
+
The arguments could be:
|
| 122 |
+
|
| 123 |
+
* A model: the model's `get_absolute_url()` function will be called.
|
| 124 |
+
|
| 125 |
+
* A view name, possibly with arguments: `urls.reverse()` will be used
|
| 126 |
+
to reverse-resolve the name.
|
| 127 |
+
|
| 128 |
+
* A URL, which will be returned as-is.
|
| 129 |
+
"""
|
| 130 |
+
# If it's a model, use get_absolute_url()
|
| 131 |
+
if hasattr(to, "get_absolute_url"):
|
| 132 |
+
return to.get_absolute_url()
|
| 133 |
+
|
| 134 |
+
if isinstance(to, Promise):
|
| 135 |
+
# Expand the lazy instance, as it can cause issues when it is passed
|
| 136 |
+
# further to some Python functions like urlparse.
|
| 137 |
+
to = str(to)
|
| 138 |
+
|
| 139 |
+
# Handle relative URLs
|
| 140 |
+
if isinstance(to, str) and to.startswith(("./", "../")):
|
| 141 |
+
return to
|
| 142 |
+
|
| 143 |
+
# Next try a reverse URL resolution.
|
| 144 |
+
try:
|
| 145 |
+
return reverse(to, args=args, kwargs=kwargs)
|
| 146 |
+
except NoReverseMatch:
|
| 147 |
+
# If this is a callable, re-raise.
|
| 148 |
+
if callable(to):
|
| 149 |
+
raise
|
| 150 |
+
# If this doesn't "feel" like a URL, re-raise.
|
| 151 |
+
if "/" not in to and "." not in to:
|
| 152 |
+
raise
|
| 153 |
+
|
| 154 |
+
# Finally, fall back and assume it's a URL
|
| 155 |
+
return to
|
testbed/django__django/django/views/__init__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.views.generic.base import View
|
| 2 |
+
|
| 3 |
+
__all__ = ["View"]
|
testbed/django__django/django/views/csrf.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
from django.conf import settings
|
| 4 |
+
from django.http import HttpResponseForbidden
|
| 5 |
+
from django.template import Context, Engine, TemplateDoesNotExist, loader
|
| 6 |
+
from django.utils.translation import gettext as _
|
| 7 |
+
from django.utils.version import get_docs_version
|
| 8 |
+
|
| 9 |
+
CSRF_FAILURE_TEMPLATE_NAME = "403_csrf.html"
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def builtin_template_path(name):
|
| 13 |
+
"""
|
| 14 |
+
Return a path to a builtin template.
|
| 15 |
+
|
| 16 |
+
Avoid calling this function at the module level or in a class-definition
|
| 17 |
+
because __file__ may not exist, e.g. in frozen environments.
|
| 18 |
+
"""
|
| 19 |
+
return Path(__file__).parent / "templates" / name
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def csrf_failure(request, reason="", template_name=CSRF_FAILURE_TEMPLATE_NAME):
|
| 23 |
+
"""
|
| 24 |
+
Default view used when request fails CSRF protection
|
| 25 |
+
"""
|
| 26 |
+
from django.middleware.csrf import REASON_NO_CSRF_COOKIE, REASON_NO_REFERER
|
| 27 |
+
|
| 28 |
+
c = {
|
| 29 |
+
"title": _("Forbidden"),
|
| 30 |
+
"main": _("CSRF verification failed. Request aborted."),
|
| 31 |
+
"reason": reason,
|
| 32 |
+
"no_referer": reason == REASON_NO_REFERER,
|
| 33 |
+
"no_referer1": _(
|
| 34 |
+
"You are seeing this message because this HTTPS site requires a "
|
| 35 |
+
"“Referer header” to be sent by your web browser, but none was "
|
| 36 |
+
"sent. This header is required for security reasons, to ensure "
|
| 37 |
+
"that your browser is not being hijacked by third parties."
|
| 38 |
+
),
|
| 39 |
+
"no_referer2": _(
|
| 40 |
+
"If you have configured your browser to disable “Referer” headers, "
|
| 41 |
+
"please re-enable them, at least for this site, or for HTTPS "
|
| 42 |
+
"connections, or for “same-origin” requests."
|
| 43 |
+
),
|
| 44 |
+
"no_referer3": _(
|
| 45 |
+
'If you are using the <meta name="referrer" '
|
| 46 |
+
'content="no-referrer"> tag or including the “Referrer-Policy: '
|
| 47 |
+
"no-referrer” header, please remove them. The CSRF protection "
|
| 48 |
+
"requires the “Referer” header to do strict referer checking. If "
|
| 49 |
+
"you’re concerned about privacy, use alternatives like "
|
| 50 |
+
'<a rel="noreferrer" …> for links to third-party sites.'
|
| 51 |
+
),
|
| 52 |
+
"no_cookie": reason == REASON_NO_CSRF_COOKIE,
|
| 53 |
+
"no_cookie1": _(
|
| 54 |
+
"You are seeing this message because this site requires a CSRF "
|
| 55 |
+
"cookie when submitting forms. This cookie is required for "
|
| 56 |
+
"security reasons, to ensure that your browser is not being "
|
| 57 |
+
"hijacked by third parties."
|
| 58 |
+
),
|
| 59 |
+
"no_cookie2": _(
|
| 60 |
+
"If you have configured your browser to disable cookies, please "
|
| 61 |
+
"re-enable them, at least for this site, or for “same-origin” "
|
| 62 |
+
"requests."
|
| 63 |
+
),
|
| 64 |
+
"DEBUG": settings.DEBUG,
|
| 65 |
+
"docs_version": get_docs_version(),
|
| 66 |
+
"more": _("More information is available with DEBUG=True."),
|
| 67 |
+
}
|
| 68 |
+
try:
|
| 69 |
+
t = loader.get_template(template_name)
|
| 70 |
+
except TemplateDoesNotExist:
|
| 71 |
+
if template_name == CSRF_FAILURE_TEMPLATE_NAME:
|
| 72 |
+
# If the default template doesn't exist, use the fallback template.
|
| 73 |
+
with builtin_template_path("csrf_403.html").open(encoding="utf-8") as fh:
|
| 74 |
+
t = Engine().from_string(fh.read())
|
| 75 |
+
c = Context(c)
|
| 76 |
+
else:
|
| 77 |
+
# Raise if a developer-specified template doesn't exist.
|
| 78 |
+
raise
|
| 79 |
+
return HttpResponseForbidden(t.render(c))
|
testbed/django__django/django/views/debug.py
ADDED
|
@@ -0,0 +1,665 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import inspect
|
| 3 |
+
import itertools
|
| 4 |
+
import re
|
| 5 |
+
import sys
|
| 6 |
+
import types
|
| 7 |
+
import warnings
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
from django.conf import settings
|
| 11 |
+
from django.http import Http404, HttpResponse, HttpResponseNotFound
|
| 12 |
+
from django.template import Context, Engine, TemplateDoesNotExist
|
| 13 |
+
from django.template.defaultfilters import pprint
|
| 14 |
+
from django.urls import resolve
|
| 15 |
+
from django.utils import timezone
|
| 16 |
+
from django.utils.datastructures import MultiValueDict
|
| 17 |
+
from django.utils.encoding import force_str
|
| 18 |
+
from django.utils.module_loading import import_string
|
| 19 |
+
from django.utils.regex_helper import _lazy_re_compile
|
| 20 |
+
from django.utils.version import PY311, get_docs_version
|
| 21 |
+
from django.views.decorators.debug import coroutine_functions_to_sensitive_variables
|
| 22 |
+
|
| 23 |
+
# Minimal Django templates engine to render the error templates
|
| 24 |
+
# regardless of the project's TEMPLATES setting. Templates are
|
| 25 |
+
# read directly from the filesystem so that the error handler
|
| 26 |
+
# works even if the template loader is broken.
|
| 27 |
+
DEBUG_ENGINE = Engine(
|
| 28 |
+
debug=True,
|
| 29 |
+
libraries={"i18n": "django.templatetags.i18n"},
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def builtin_template_path(name):
|
| 34 |
+
"""
|
| 35 |
+
Return a path to a builtin template.
|
| 36 |
+
|
| 37 |
+
Avoid calling this function at the module level or in a class-definition
|
| 38 |
+
because __file__ may not exist, e.g. in frozen environments.
|
| 39 |
+
"""
|
| 40 |
+
return Path(__file__).parent / "templates" / name
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class ExceptionCycleWarning(UserWarning):
|
| 44 |
+
pass
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class CallableSettingWrapper:
|
| 48 |
+
"""
|
| 49 |
+
Object to wrap callable appearing in settings.
|
| 50 |
+
* Not to call in the debug page (#21345).
|
| 51 |
+
* Not to break the debug page if the callable forbidding to set attributes
|
| 52 |
+
(#23070).
|
| 53 |
+
"""
|
| 54 |
+
|
| 55 |
+
def __init__(self, callable_setting):
|
| 56 |
+
self._wrapped = callable_setting
|
| 57 |
+
|
| 58 |
+
def __repr__(self):
|
| 59 |
+
return repr(self._wrapped)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def technical_500_response(request, exc_type, exc_value, tb, status_code=500):
|
| 63 |
+
"""
|
| 64 |
+
Create a technical server error response. The last three arguments are
|
| 65 |
+
the values returned from sys.exc_info() and friends.
|
| 66 |
+
"""
|
| 67 |
+
reporter = get_exception_reporter_class(request)(request, exc_type, exc_value, tb)
|
| 68 |
+
if request.accepts("text/html"):
|
| 69 |
+
html = reporter.get_traceback_html()
|
| 70 |
+
return HttpResponse(html, status=status_code)
|
| 71 |
+
else:
|
| 72 |
+
text = reporter.get_traceback_text()
|
| 73 |
+
return HttpResponse(
|
| 74 |
+
text, status=status_code, content_type="text/plain; charset=utf-8"
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
@functools.lru_cache
|
| 79 |
+
def get_default_exception_reporter_filter():
|
| 80 |
+
# Instantiate the default filter for the first time and cache it.
|
| 81 |
+
return import_string(settings.DEFAULT_EXCEPTION_REPORTER_FILTER)()
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def get_exception_reporter_filter(request):
|
| 85 |
+
default_filter = get_default_exception_reporter_filter()
|
| 86 |
+
return getattr(request, "exception_reporter_filter", default_filter)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def get_exception_reporter_class(request):
|
| 90 |
+
default_exception_reporter_class = import_string(
|
| 91 |
+
settings.DEFAULT_EXCEPTION_REPORTER
|
| 92 |
+
)
|
| 93 |
+
return getattr(
|
| 94 |
+
request, "exception_reporter_class", default_exception_reporter_class
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def get_caller(request):
|
| 99 |
+
resolver_match = request.resolver_match
|
| 100 |
+
if resolver_match is None:
|
| 101 |
+
try:
|
| 102 |
+
resolver_match = resolve(request.path)
|
| 103 |
+
except Http404:
|
| 104 |
+
pass
|
| 105 |
+
return "" if resolver_match is None else resolver_match._func_path
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class SafeExceptionReporterFilter:
|
| 109 |
+
"""
|
| 110 |
+
Use annotations made by the sensitive_post_parameters and
|
| 111 |
+
sensitive_variables decorators to filter out sensitive information.
|
| 112 |
+
"""
|
| 113 |
+
|
| 114 |
+
cleansed_substitute = "********************"
|
| 115 |
+
hidden_settings = _lazy_re_compile(
|
| 116 |
+
"API|TOKEN|KEY|SECRET|PASS|SIGNATURE|HTTP_COOKIE", flags=re.I
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
def cleanse_setting(self, key, value):
|
| 120 |
+
"""
|
| 121 |
+
Cleanse an individual setting key/value of sensitive content. If the
|
| 122 |
+
value is a dictionary, recursively cleanse the keys in that dictionary.
|
| 123 |
+
"""
|
| 124 |
+
if key == settings.SESSION_COOKIE_NAME:
|
| 125 |
+
is_sensitive = True
|
| 126 |
+
else:
|
| 127 |
+
try:
|
| 128 |
+
is_sensitive = self.hidden_settings.search(key)
|
| 129 |
+
except TypeError:
|
| 130 |
+
is_sensitive = False
|
| 131 |
+
|
| 132 |
+
if is_sensitive:
|
| 133 |
+
cleansed = self.cleansed_substitute
|
| 134 |
+
elif isinstance(value, dict):
|
| 135 |
+
cleansed = {k: self.cleanse_setting(k, v) for k, v in value.items()}
|
| 136 |
+
elif isinstance(value, list):
|
| 137 |
+
cleansed = [self.cleanse_setting("", v) for v in value]
|
| 138 |
+
elif isinstance(value, tuple):
|
| 139 |
+
cleansed = tuple([self.cleanse_setting("", v) for v in value])
|
| 140 |
+
else:
|
| 141 |
+
cleansed = value
|
| 142 |
+
|
| 143 |
+
if callable(cleansed):
|
| 144 |
+
cleansed = CallableSettingWrapper(cleansed)
|
| 145 |
+
|
| 146 |
+
return cleansed
|
| 147 |
+
|
| 148 |
+
def get_safe_settings(self):
|
| 149 |
+
"""
|
| 150 |
+
Return a dictionary of the settings module with values of sensitive
|
| 151 |
+
settings replaced with stars (*********).
|
| 152 |
+
"""
|
| 153 |
+
settings_dict = {}
|
| 154 |
+
for k in dir(settings):
|
| 155 |
+
if k.isupper():
|
| 156 |
+
settings_dict[k] = self.cleanse_setting(k, getattr(settings, k))
|
| 157 |
+
return settings_dict
|
| 158 |
+
|
| 159 |
+
def get_safe_request_meta(self, request):
|
| 160 |
+
"""
|
| 161 |
+
Return a dictionary of request.META with sensitive values redacted.
|
| 162 |
+
"""
|
| 163 |
+
if not hasattr(request, "META"):
|
| 164 |
+
return {}
|
| 165 |
+
return {k: self.cleanse_setting(k, v) for k, v in request.META.items()}
|
| 166 |
+
|
| 167 |
+
def get_safe_cookies(self, request):
|
| 168 |
+
"""
|
| 169 |
+
Return a dictionary of request.COOKIES with sensitive values redacted.
|
| 170 |
+
"""
|
| 171 |
+
if not hasattr(request, "COOKIES"):
|
| 172 |
+
return {}
|
| 173 |
+
return {k: self.cleanse_setting(k, v) for k, v in request.COOKIES.items()}
|
| 174 |
+
|
| 175 |
+
def is_active(self, request):
|
| 176 |
+
"""
|
| 177 |
+
This filter is to add safety in production environments (i.e. DEBUG
|
| 178 |
+
is False). If DEBUG is True then your site is not safe anyway.
|
| 179 |
+
This hook is provided as a convenience to easily activate or
|
| 180 |
+
deactivate the filter on a per request basis.
|
| 181 |
+
"""
|
| 182 |
+
return settings.DEBUG is False
|
| 183 |
+
|
| 184 |
+
def get_cleansed_multivaluedict(self, request, multivaluedict):
|
| 185 |
+
"""
|
| 186 |
+
Replace the keys in a MultiValueDict marked as sensitive with stars.
|
| 187 |
+
This mitigates leaking sensitive POST parameters if something like
|
| 188 |
+
request.POST['nonexistent_key'] throws an exception (#21098).
|
| 189 |
+
"""
|
| 190 |
+
sensitive_post_parameters = getattr(request, "sensitive_post_parameters", [])
|
| 191 |
+
if self.is_active(request) and sensitive_post_parameters:
|
| 192 |
+
multivaluedict = multivaluedict.copy()
|
| 193 |
+
for param in sensitive_post_parameters:
|
| 194 |
+
if param in multivaluedict:
|
| 195 |
+
multivaluedict[param] = self.cleansed_substitute
|
| 196 |
+
return multivaluedict
|
| 197 |
+
|
| 198 |
+
def get_post_parameters(self, request):
|
| 199 |
+
"""
|
| 200 |
+
Replace the values of POST parameters marked as sensitive with
|
| 201 |
+
stars (*********).
|
| 202 |
+
"""
|
| 203 |
+
if request is None:
|
| 204 |
+
return {}
|
| 205 |
+
else:
|
| 206 |
+
sensitive_post_parameters = getattr(
|
| 207 |
+
request, "sensitive_post_parameters", []
|
| 208 |
+
)
|
| 209 |
+
if self.is_active(request) and sensitive_post_parameters:
|
| 210 |
+
cleansed = request.POST.copy()
|
| 211 |
+
if sensitive_post_parameters == "__ALL__":
|
| 212 |
+
# Cleanse all parameters.
|
| 213 |
+
for k in cleansed:
|
| 214 |
+
cleansed[k] = self.cleansed_substitute
|
| 215 |
+
return cleansed
|
| 216 |
+
else:
|
| 217 |
+
# Cleanse only the specified parameters.
|
| 218 |
+
for param in sensitive_post_parameters:
|
| 219 |
+
if param in cleansed:
|
| 220 |
+
cleansed[param] = self.cleansed_substitute
|
| 221 |
+
return cleansed
|
| 222 |
+
else:
|
| 223 |
+
return request.POST
|
| 224 |
+
|
| 225 |
+
def cleanse_special_types(self, request, value):
|
| 226 |
+
try:
|
| 227 |
+
# If value is lazy or a complex object of another kind, this check
|
| 228 |
+
# might raise an exception. isinstance checks that lazy
|
| 229 |
+
# MultiValueDicts will have a return value.
|
| 230 |
+
is_multivalue_dict = isinstance(value, MultiValueDict)
|
| 231 |
+
except Exception as e:
|
| 232 |
+
return "{!r} while evaluating {!r}".format(e, value)
|
| 233 |
+
|
| 234 |
+
if is_multivalue_dict:
|
| 235 |
+
# Cleanse MultiValueDicts (request.POST is the one we usually care about)
|
| 236 |
+
value = self.get_cleansed_multivaluedict(request, value)
|
| 237 |
+
return value
|
| 238 |
+
|
| 239 |
+
def get_traceback_frame_variables(self, request, tb_frame):
|
| 240 |
+
"""
|
| 241 |
+
Replace the values of variables marked as sensitive with
|
| 242 |
+
stars (*********).
|
| 243 |
+
"""
|
| 244 |
+
sensitive_variables = None
|
| 245 |
+
|
| 246 |
+
# Coroutines don't have a proper `f_back` so they need to be inspected
|
| 247 |
+
# separately. Handle this by stashing the registered sensitive
|
| 248 |
+
# variables in a global dict indexed by `hash(file_path:line_number)`.
|
| 249 |
+
if (
|
| 250 |
+
tb_frame.f_code.co_flags & inspect.CO_COROUTINE != 0
|
| 251 |
+
and tb_frame.f_code.co_name != "sensitive_variables_wrapper"
|
| 252 |
+
):
|
| 253 |
+
key = hash(
|
| 254 |
+
f"{tb_frame.f_code.co_filename}:{tb_frame.f_code.co_firstlineno}"
|
| 255 |
+
)
|
| 256 |
+
sensitive_variables = coroutine_functions_to_sensitive_variables.get(
|
| 257 |
+
key, None
|
| 258 |
+
)
|
| 259 |
+
|
| 260 |
+
if sensitive_variables is None:
|
| 261 |
+
# Loop through the frame's callers to see if the
|
| 262 |
+
# sensitive_variables decorator was used.
|
| 263 |
+
current_frame = tb_frame
|
| 264 |
+
while current_frame is not None:
|
| 265 |
+
if (
|
| 266 |
+
current_frame.f_code.co_name == "sensitive_variables_wrapper"
|
| 267 |
+
and "sensitive_variables_wrapper" in current_frame.f_locals
|
| 268 |
+
):
|
| 269 |
+
# The sensitive_variables decorator was used, so take note
|
| 270 |
+
# of the sensitive variables' names.
|
| 271 |
+
wrapper = current_frame.f_locals["sensitive_variables_wrapper"]
|
| 272 |
+
sensitive_variables = getattr(wrapper, "sensitive_variables", None)
|
| 273 |
+
break
|
| 274 |
+
current_frame = current_frame.f_back
|
| 275 |
+
|
| 276 |
+
cleansed = {}
|
| 277 |
+
if self.is_active(request) and sensitive_variables:
|
| 278 |
+
if sensitive_variables == "__ALL__":
|
| 279 |
+
# Cleanse all variables
|
| 280 |
+
for name in tb_frame.f_locals:
|
| 281 |
+
cleansed[name] = self.cleansed_substitute
|
| 282 |
+
else:
|
| 283 |
+
# Cleanse specified variables
|
| 284 |
+
for name, value in tb_frame.f_locals.items():
|
| 285 |
+
if name in sensitive_variables:
|
| 286 |
+
value = self.cleansed_substitute
|
| 287 |
+
else:
|
| 288 |
+
value = self.cleanse_special_types(request, value)
|
| 289 |
+
cleansed[name] = value
|
| 290 |
+
else:
|
| 291 |
+
# Potentially cleanse the request and any MultiValueDicts if they
|
| 292 |
+
# are one of the frame variables.
|
| 293 |
+
for name, value in tb_frame.f_locals.items():
|
| 294 |
+
cleansed[name] = self.cleanse_special_types(request, value)
|
| 295 |
+
|
| 296 |
+
if (
|
| 297 |
+
tb_frame.f_code.co_name == "sensitive_variables_wrapper"
|
| 298 |
+
and "sensitive_variables_wrapper" in tb_frame.f_locals
|
| 299 |
+
):
|
| 300 |
+
# For good measure, obfuscate the decorated function's arguments in
|
| 301 |
+
# the sensitive_variables decorator's frame, in case the variables
|
| 302 |
+
# associated with those arguments were meant to be obfuscated from
|
| 303 |
+
# the decorated function's frame.
|
| 304 |
+
cleansed["func_args"] = self.cleansed_substitute
|
| 305 |
+
cleansed["func_kwargs"] = self.cleansed_substitute
|
| 306 |
+
|
| 307 |
+
return cleansed.items()
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
class ExceptionReporter:
|
| 311 |
+
"""Organize and coordinate reporting on exceptions."""
|
| 312 |
+
|
| 313 |
+
@property
|
| 314 |
+
def html_template_path(self):
|
| 315 |
+
return builtin_template_path("technical_500.html")
|
| 316 |
+
|
| 317 |
+
@property
|
| 318 |
+
def text_template_path(self):
|
| 319 |
+
return builtin_template_path("technical_500.txt")
|
| 320 |
+
|
| 321 |
+
def __init__(self, request, exc_type, exc_value, tb, is_email=False):
|
| 322 |
+
self.request = request
|
| 323 |
+
self.filter = get_exception_reporter_filter(self.request)
|
| 324 |
+
self.exc_type = exc_type
|
| 325 |
+
self.exc_value = exc_value
|
| 326 |
+
self.tb = tb
|
| 327 |
+
self.is_email = is_email
|
| 328 |
+
|
| 329 |
+
self.template_info = getattr(self.exc_value, "template_debug", None)
|
| 330 |
+
self.template_does_not_exist = False
|
| 331 |
+
self.postmortem = None
|
| 332 |
+
|
| 333 |
+
def _get_raw_insecure_uri(self):
|
| 334 |
+
"""
|
| 335 |
+
Return an absolute URI from variables available in this request. Skip
|
| 336 |
+
allowed hosts protection, so may return insecure URI.
|
| 337 |
+
"""
|
| 338 |
+
return "{scheme}://{host}{path}".format(
|
| 339 |
+
scheme=self.request.scheme,
|
| 340 |
+
host=self.request._get_raw_host(),
|
| 341 |
+
path=self.request.get_full_path(),
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
def get_traceback_data(self):
|
| 345 |
+
"""Return a dictionary containing traceback information."""
|
| 346 |
+
if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist):
|
| 347 |
+
self.template_does_not_exist = True
|
| 348 |
+
self.postmortem = self.exc_value.chain or [self.exc_value]
|
| 349 |
+
|
| 350 |
+
frames = self.get_traceback_frames()
|
| 351 |
+
for i, frame in enumerate(frames):
|
| 352 |
+
if "vars" in frame:
|
| 353 |
+
frame_vars = []
|
| 354 |
+
for k, v in frame["vars"]:
|
| 355 |
+
v = pprint(v)
|
| 356 |
+
# Trim large blobs of data
|
| 357 |
+
if len(v) > 4096:
|
| 358 |
+
v = "%s… <trimmed %d bytes string>" % (v[0:4096], len(v))
|
| 359 |
+
frame_vars.append((k, v))
|
| 360 |
+
frame["vars"] = frame_vars
|
| 361 |
+
frames[i] = frame
|
| 362 |
+
|
| 363 |
+
unicode_hint = ""
|
| 364 |
+
if self.exc_type and issubclass(self.exc_type, UnicodeError):
|
| 365 |
+
start = getattr(self.exc_value, "start", None)
|
| 366 |
+
end = getattr(self.exc_value, "end", None)
|
| 367 |
+
if start is not None and end is not None:
|
| 368 |
+
unicode_str = self.exc_value.args[1]
|
| 369 |
+
unicode_hint = force_str(
|
| 370 |
+
unicode_str[max(start - 5, 0) : min(end + 5, len(unicode_str))],
|
| 371 |
+
"ascii",
|
| 372 |
+
errors="replace",
|
| 373 |
+
)
|
| 374 |
+
from django import get_version
|
| 375 |
+
|
| 376 |
+
if self.request is None:
|
| 377 |
+
user_str = None
|
| 378 |
+
else:
|
| 379 |
+
try:
|
| 380 |
+
user_str = str(self.request.user)
|
| 381 |
+
except Exception:
|
| 382 |
+
# request.user may raise OperationalError if the database is
|
| 383 |
+
# unavailable, for example.
|
| 384 |
+
user_str = "[unable to retrieve the current user]"
|
| 385 |
+
|
| 386 |
+
c = {
|
| 387 |
+
"is_email": self.is_email,
|
| 388 |
+
"unicode_hint": unicode_hint,
|
| 389 |
+
"frames": frames,
|
| 390 |
+
"request": self.request,
|
| 391 |
+
"request_meta": self.filter.get_safe_request_meta(self.request),
|
| 392 |
+
"request_COOKIES_items": self.filter.get_safe_cookies(self.request).items(),
|
| 393 |
+
"user_str": user_str,
|
| 394 |
+
"filtered_POST_items": list(
|
| 395 |
+
self.filter.get_post_parameters(self.request).items()
|
| 396 |
+
),
|
| 397 |
+
"settings": self.filter.get_safe_settings(),
|
| 398 |
+
"sys_executable": sys.executable,
|
| 399 |
+
"sys_version_info": "%d.%d.%d" % sys.version_info[0:3],
|
| 400 |
+
"server_time": timezone.now(),
|
| 401 |
+
"django_version_info": get_version(),
|
| 402 |
+
"sys_path": sys.path,
|
| 403 |
+
"template_info": self.template_info,
|
| 404 |
+
"template_does_not_exist": self.template_does_not_exist,
|
| 405 |
+
"postmortem": self.postmortem,
|
| 406 |
+
}
|
| 407 |
+
if self.request is not None:
|
| 408 |
+
c["request_GET_items"] = self.request.GET.items()
|
| 409 |
+
c["request_FILES_items"] = self.request.FILES.items()
|
| 410 |
+
c["request_insecure_uri"] = self._get_raw_insecure_uri()
|
| 411 |
+
c["raising_view_name"] = get_caller(self.request)
|
| 412 |
+
|
| 413 |
+
# Check whether exception info is available
|
| 414 |
+
if self.exc_type:
|
| 415 |
+
c["exception_type"] = self.exc_type.__name__
|
| 416 |
+
if self.exc_value:
|
| 417 |
+
c["exception_value"] = str(self.exc_value)
|
| 418 |
+
if exc_notes := getattr(self.exc_value, "__notes__", None):
|
| 419 |
+
c["exception_notes"] = "\n" + "\n".join(exc_notes)
|
| 420 |
+
if frames:
|
| 421 |
+
c["lastframe"] = frames[-1]
|
| 422 |
+
return c
|
| 423 |
+
|
| 424 |
+
def get_traceback_html(self):
|
| 425 |
+
"""Return HTML version of debug 500 HTTP error page."""
|
| 426 |
+
with self.html_template_path.open(encoding="utf-8") as fh:
|
| 427 |
+
t = DEBUG_ENGINE.from_string(fh.read())
|
| 428 |
+
c = Context(self.get_traceback_data(), use_l10n=False)
|
| 429 |
+
return t.render(c)
|
| 430 |
+
|
| 431 |
+
def get_traceback_text(self):
|
| 432 |
+
"""Return plain text version of debug 500 HTTP error page."""
|
| 433 |
+
with self.text_template_path.open(encoding="utf-8") as fh:
|
| 434 |
+
t = DEBUG_ENGINE.from_string(fh.read())
|
| 435 |
+
c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False)
|
| 436 |
+
return t.render(c)
|
| 437 |
+
|
| 438 |
+
def _get_source(self, filename, loader, module_name):
|
| 439 |
+
source = None
|
| 440 |
+
if hasattr(loader, "get_source"):
|
| 441 |
+
try:
|
| 442 |
+
source = loader.get_source(module_name)
|
| 443 |
+
except ImportError:
|
| 444 |
+
pass
|
| 445 |
+
if source is not None:
|
| 446 |
+
source = source.splitlines()
|
| 447 |
+
if source is None:
|
| 448 |
+
try:
|
| 449 |
+
with open(filename, "rb") as fp:
|
| 450 |
+
source = fp.read().splitlines()
|
| 451 |
+
except OSError:
|
| 452 |
+
pass
|
| 453 |
+
return source
|
| 454 |
+
|
| 455 |
+
def _get_lines_from_file(
|
| 456 |
+
self, filename, lineno, context_lines, loader=None, module_name=None
|
| 457 |
+
):
|
| 458 |
+
"""
|
| 459 |
+
Return context_lines before and after lineno from file.
|
| 460 |
+
Return (pre_context_lineno, pre_context, context_line, post_context).
|
| 461 |
+
"""
|
| 462 |
+
source = self._get_source(filename, loader, module_name)
|
| 463 |
+
if source is None:
|
| 464 |
+
return None, [], None, []
|
| 465 |
+
|
| 466 |
+
# If we just read the source from a file, or if the loader did not
|
| 467 |
+
# apply tokenize.detect_encoding to decode the source into a
|
| 468 |
+
# string, then we should do that ourselves.
|
| 469 |
+
if isinstance(source[0], bytes):
|
| 470 |
+
encoding = "ascii"
|
| 471 |
+
for line in source[:2]:
|
| 472 |
+
# File coding may be specified. Match pattern from PEP-263
|
| 473 |
+
# (https://www.python.org/dev/peps/pep-0263/)
|
| 474 |
+
match = re.search(rb"coding[:=]\s*([-\w.]+)", line)
|
| 475 |
+
if match:
|
| 476 |
+
encoding = match[1].decode("ascii")
|
| 477 |
+
break
|
| 478 |
+
source = [str(sline, encoding, "replace") for sline in source]
|
| 479 |
+
|
| 480 |
+
lower_bound = max(0, lineno - context_lines)
|
| 481 |
+
upper_bound = lineno + context_lines
|
| 482 |
+
|
| 483 |
+
try:
|
| 484 |
+
pre_context = source[lower_bound:lineno]
|
| 485 |
+
context_line = source[lineno]
|
| 486 |
+
post_context = source[lineno + 1 : upper_bound]
|
| 487 |
+
except IndexError:
|
| 488 |
+
return None, [], None, []
|
| 489 |
+
return lower_bound, pre_context, context_line, post_context
|
| 490 |
+
|
| 491 |
+
def _get_explicit_or_implicit_cause(self, exc_value):
|
| 492 |
+
explicit = getattr(exc_value, "__cause__", None)
|
| 493 |
+
suppress_context = getattr(exc_value, "__suppress_context__", None)
|
| 494 |
+
implicit = getattr(exc_value, "__context__", None)
|
| 495 |
+
return explicit or (None if suppress_context else implicit)
|
| 496 |
+
|
| 497 |
+
def get_traceback_frames(self):
|
| 498 |
+
# Get the exception and all its causes
|
| 499 |
+
exceptions = []
|
| 500 |
+
exc_value = self.exc_value
|
| 501 |
+
while exc_value:
|
| 502 |
+
exceptions.append(exc_value)
|
| 503 |
+
exc_value = self._get_explicit_or_implicit_cause(exc_value)
|
| 504 |
+
if exc_value in exceptions:
|
| 505 |
+
warnings.warn(
|
| 506 |
+
"Cycle in the exception chain detected: exception '%s' "
|
| 507 |
+
"encountered again." % exc_value,
|
| 508 |
+
ExceptionCycleWarning,
|
| 509 |
+
)
|
| 510 |
+
# Avoid infinite loop if there's a cyclic reference (#29393).
|
| 511 |
+
break
|
| 512 |
+
|
| 513 |
+
frames = []
|
| 514 |
+
# No exceptions were supplied to ExceptionReporter
|
| 515 |
+
if not exceptions:
|
| 516 |
+
return frames
|
| 517 |
+
|
| 518 |
+
# In case there's just one exception, take the traceback from self.tb
|
| 519 |
+
exc_value = exceptions.pop()
|
| 520 |
+
tb = self.tb if not exceptions else exc_value.__traceback__
|
| 521 |
+
while True:
|
| 522 |
+
frames.extend(self.get_exception_traceback_frames(exc_value, tb))
|
| 523 |
+
try:
|
| 524 |
+
exc_value = exceptions.pop()
|
| 525 |
+
except IndexError:
|
| 526 |
+
break
|
| 527 |
+
tb = exc_value.__traceback__
|
| 528 |
+
return frames
|
| 529 |
+
|
| 530 |
+
def get_exception_traceback_frames(self, exc_value, tb):
|
| 531 |
+
exc_cause = self._get_explicit_or_implicit_cause(exc_value)
|
| 532 |
+
exc_cause_explicit = getattr(exc_value, "__cause__", True)
|
| 533 |
+
if tb is None:
|
| 534 |
+
yield {
|
| 535 |
+
"exc_cause": exc_cause,
|
| 536 |
+
"exc_cause_explicit": exc_cause_explicit,
|
| 537 |
+
"tb": None,
|
| 538 |
+
"type": "user",
|
| 539 |
+
}
|
| 540 |
+
while tb is not None:
|
| 541 |
+
# Support for __traceback_hide__ which is used by a few libraries
|
| 542 |
+
# to hide internal frames.
|
| 543 |
+
if tb.tb_frame.f_locals.get("__traceback_hide__"):
|
| 544 |
+
tb = tb.tb_next
|
| 545 |
+
continue
|
| 546 |
+
filename = tb.tb_frame.f_code.co_filename
|
| 547 |
+
function = tb.tb_frame.f_code.co_name
|
| 548 |
+
lineno = tb.tb_lineno - 1
|
| 549 |
+
loader = tb.tb_frame.f_globals.get("__loader__")
|
| 550 |
+
module_name = tb.tb_frame.f_globals.get("__name__") or ""
|
| 551 |
+
(
|
| 552 |
+
pre_context_lineno,
|
| 553 |
+
pre_context,
|
| 554 |
+
context_line,
|
| 555 |
+
post_context,
|
| 556 |
+
) = self._get_lines_from_file(
|
| 557 |
+
filename,
|
| 558 |
+
lineno,
|
| 559 |
+
7,
|
| 560 |
+
loader,
|
| 561 |
+
module_name,
|
| 562 |
+
)
|
| 563 |
+
if pre_context_lineno is None:
|
| 564 |
+
pre_context_lineno = lineno
|
| 565 |
+
pre_context = []
|
| 566 |
+
context_line = "<source code not available>"
|
| 567 |
+
post_context = []
|
| 568 |
+
|
| 569 |
+
colno = tb_area_colno = ""
|
| 570 |
+
if PY311:
|
| 571 |
+
_, _, start_column, end_column = next(
|
| 572 |
+
itertools.islice(
|
| 573 |
+
tb.tb_frame.f_code.co_positions(), tb.tb_lasti // 2, None
|
| 574 |
+
)
|
| 575 |
+
)
|
| 576 |
+
if start_column and end_column:
|
| 577 |
+
underline = "^" * (end_column - start_column)
|
| 578 |
+
spaces = " " * (start_column + len(str(lineno + 1)) + 2)
|
| 579 |
+
colno = f"\n{spaces}{underline}"
|
| 580 |
+
tb_area_spaces = " " * (
|
| 581 |
+
4
|
| 582 |
+
+ start_column
|
| 583 |
+
- (len(context_line) - len(context_line.lstrip()))
|
| 584 |
+
)
|
| 585 |
+
tb_area_colno = f"\n{tb_area_spaces}{underline}"
|
| 586 |
+
yield {
|
| 587 |
+
"exc_cause": exc_cause,
|
| 588 |
+
"exc_cause_explicit": exc_cause_explicit,
|
| 589 |
+
"tb": tb,
|
| 590 |
+
"type": "django" if module_name.startswith("django.") else "user",
|
| 591 |
+
"filename": filename,
|
| 592 |
+
"function": function,
|
| 593 |
+
"lineno": lineno + 1,
|
| 594 |
+
"vars": self.filter.get_traceback_frame_variables(
|
| 595 |
+
self.request, tb.tb_frame
|
| 596 |
+
),
|
| 597 |
+
"id": id(tb),
|
| 598 |
+
"pre_context": pre_context,
|
| 599 |
+
"context_line": context_line,
|
| 600 |
+
"post_context": post_context,
|
| 601 |
+
"pre_context_lineno": pre_context_lineno + 1,
|
| 602 |
+
"colno": colno,
|
| 603 |
+
"tb_area_colno": tb_area_colno,
|
| 604 |
+
}
|
| 605 |
+
tb = tb.tb_next
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
def technical_404_response(request, exception):
|
| 609 |
+
"""Create a technical 404 error response. `exception` is the Http404."""
|
| 610 |
+
try:
|
| 611 |
+
error_url = exception.args[0]["path"]
|
| 612 |
+
except (IndexError, TypeError, KeyError):
|
| 613 |
+
error_url = request.path_info[1:] # Trim leading slash
|
| 614 |
+
|
| 615 |
+
try:
|
| 616 |
+
tried = exception.args[0]["tried"]
|
| 617 |
+
except (IndexError, TypeError, KeyError):
|
| 618 |
+
resolved = True
|
| 619 |
+
tried = request.resolver_match.tried if request.resolver_match else None
|
| 620 |
+
else:
|
| 621 |
+
resolved = False
|
| 622 |
+
if not tried or ( # empty URLconf
|
| 623 |
+
request.path == "/"
|
| 624 |
+
and len(tried) == 1
|
| 625 |
+
and len(tried[0]) == 1 # default URLconf
|
| 626 |
+
and getattr(tried[0][0], "app_name", "")
|
| 627 |
+
== getattr(tried[0][0], "namespace", "")
|
| 628 |
+
== "admin"
|
| 629 |
+
):
|
| 630 |
+
return default_urlconf(request)
|
| 631 |
+
|
| 632 |
+
urlconf = getattr(request, "urlconf", settings.ROOT_URLCONF)
|
| 633 |
+
if isinstance(urlconf, types.ModuleType):
|
| 634 |
+
urlconf = urlconf.__name__
|
| 635 |
+
|
| 636 |
+
with builtin_template_path("technical_404.html").open(encoding="utf-8") as fh:
|
| 637 |
+
t = DEBUG_ENGINE.from_string(fh.read())
|
| 638 |
+
reporter_filter = get_default_exception_reporter_filter()
|
| 639 |
+
c = Context(
|
| 640 |
+
{
|
| 641 |
+
"urlconf": urlconf,
|
| 642 |
+
"root_urlconf": settings.ROOT_URLCONF,
|
| 643 |
+
"request_path": error_url,
|
| 644 |
+
"urlpatterns": tried,
|
| 645 |
+
"resolved": resolved,
|
| 646 |
+
"reason": str(exception),
|
| 647 |
+
"request": request,
|
| 648 |
+
"settings": reporter_filter.get_safe_settings(),
|
| 649 |
+
"raising_view_name": get_caller(request),
|
| 650 |
+
}
|
| 651 |
+
)
|
| 652 |
+
return HttpResponseNotFound(t.render(c))
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
def default_urlconf(request):
|
| 656 |
+
"""Create an empty URLconf 404 error response."""
|
| 657 |
+
with builtin_template_path("default_urlconf.html").open(encoding="utf-8") as fh:
|
| 658 |
+
t = DEBUG_ENGINE.from_string(fh.read())
|
| 659 |
+
c = Context(
|
| 660 |
+
{
|
| 661 |
+
"version": get_docs_version(),
|
| 662 |
+
}
|
| 663 |
+
)
|
| 664 |
+
|
| 665 |
+
return HttpResponse(t.render(c))
|
testbed/django__django/django/views/decorators/clickjacking.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import wraps
|
| 2 |
+
|
| 3 |
+
from asgiref.sync import iscoroutinefunction
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def xframe_options_deny(view_func):
|
| 7 |
+
"""
|
| 8 |
+
Modify a view function so its response has the X-Frame-Options HTTP
|
| 9 |
+
header set to 'DENY' as long as the response doesn't already have that
|
| 10 |
+
header set. Usage:
|
| 11 |
+
|
| 12 |
+
@xframe_options_deny
|
| 13 |
+
def some_view(request):
|
| 14 |
+
...
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
if iscoroutinefunction(view_func):
|
| 18 |
+
|
| 19 |
+
async def _view_wrapper(*args, **kwargs):
|
| 20 |
+
response = await view_func(*args, **kwargs)
|
| 21 |
+
if response.get("X-Frame-Options") is None:
|
| 22 |
+
response["X-Frame-Options"] = "DENY"
|
| 23 |
+
return response
|
| 24 |
+
|
| 25 |
+
else:
|
| 26 |
+
|
| 27 |
+
def _view_wrapper(*args, **kwargs):
|
| 28 |
+
response = view_func(*args, **kwargs)
|
| 29 |
+
if response.get("X-Frame-Options") is None:
|
| 30 |
+
response["X-Frame-Options"] = "DENY"
|
| 31 |
+
return response
|
| 32 |
+
|
| 33 |
+
return wraps(view_func)(_view_wrapper)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def xframe_options_sameorigin(view_func):
|
| 37 |
+
"""
|
| 38 |
+
Modify a view function so its response has the X-Frame-Options HTTP
|
| 39 |
+
header set to 'SAMEORIGIN' as long as the response doesn't already have
|
| 40 |
+
that header set. Usage:
|
| 41 |
+
|
| 42 |
+
@xframe_options_sameorigin
|
| 43 |
+
def some_view(request):
|
| 44 |
+
...
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
if iscoroutinefunction(view_func):
|
| 48 |
+
|
| 49 |
+
async def _view_wrapper(*args, **kwargs):
|
| 50 |
+
response = await view_func(*args, **kwargs)
|
| 51 |
+
if response.get("X-Frame-Options") is None:
|
| 52 |
+
response["X-Frame-Options"] = "SAMEORIGIN"
|
| 53 |
+
return response
|
| 54 |
+
|
| 55 |
+
else:
|
| 56 |
+
|
| 57 |
+
def _view_wrapper(*args, **kwargs):
|
| 58 |
+
response = view_func(*args, **kwargs)
|
| 59 |
+
if response.get("X-Frame-Options") is None:
|
| 60 |
+
response["X-Frame-Options"] = "SAMEORIGIN"
|
| 61 |
+
return response
|
| 62 |
+
|
| 63 |
+
return wraps(view_func)(_view_wrapper)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def xframe_options_exempt(view_func):
|
| 67 |
+
"""
|
| 68 |
+
Modify a view function by setting a response variable that instructs
|
| 69 |
+
XFrameOptionsMiddleware to NOT set the X-Frame-Options HTTP header. Usage:
|
| 70 |
+
|
| 71 |
+
@xframe_options_exempt
|
| 72 |
+
def some_view(request):
|
| 73 |
+
...
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
if iscoroutinefunction(view_func):
|
| 77 |
+
|
| 78 |
+
async def _view_wrapper(*args, **kwargs):
|
| 79 |
+
response = await view_func(*args, **kwargs)
|
| 80 |
+
response.xframe_options_exempt = True
|
| 81 |
+
return response
|
| 82 |
+
|
| 83 |
+
else:
|
| 84 |
+
|
| 85 |
+
def _view_wrapper(*args, **kwargs):
|
| 86 |
+
response = view_func(*args, **kwargs)
|
| 87 |
+
response.xframe_options_exempt = True
|
| 88 |
+
return response
|
| 89 |
+
|
| 90 |
+
return wraps(view_func)(_view_wrapper)
|
testbed/django__django/django/views/decorators/debug.py
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
from functools import wraps
|
| 3 |
+
|
| 4 |
+
from asgiref.sync import iscoroutinefunction
|
| 5 |
+
|
| 6 |
+
from django.http import HttpRequest
|
| 7 |
+
|
| 8 |
+
coroutine_functions_to_sensitive_variables = {}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def sensitive_variables(*variables):
|
| 12 |
+
"""
|
| 13 |
+
Indicate which variables used in the decorated function are sensitive so
|
| 14 |
+
that those variables can later be treated in a special way, for example
|
| 15 |
+
by hiding them when logging unhandled exceptions.
|
| 16 |
+
|
| 17 |
+
Accept two forms:
|
| 18 |
+
|
| 19 |
+
* with specified variable names:
|
| 20 |
+
|
| 21 |
+
@sensitive_variables('user', 'password', 'credit_card')
|
| 22 |
+
def my_function(user):
|
| 23 |
+
password = user.pass_word
|
| 24 |
+
credit_card = user.credit_card_number
|
| 25 |
+
...
|
| 26 |
+
|
| 27 |
+
* without any specified variable names, in which case consider all
|
| 28 |
+
variables are sensitive:
|
| 29 |
+
|
| 30 |
+
@sensitive_variables()
|
| 31 |
+
def my_function()
|
| 32 |
+
...
|
| 33 |
+
"""
|
| 34 |
+
if len(variables) == 1 and callable(variables[0]):
|
| 35 |
+
raise TypeError(
|
| 36 |
+
"sensitive_variables() must be called to use it as a decorator, "
|
| 37 |
+
"e.g., use @sensitive_variables(), not @sensitive_variables."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
def decorator(func):
|
| 41 |
+
if iscoroutinefunction(func):
|
| 42 |
+
sensitive_variables_wrapper = func
|
| 43 |
+
|
| 44 |
+
wrapped_func = func
|
| 45 |
+
while getattr(wrapped_func, "__wrapped__", None) is not None:
|
| 46 |
+
wrapped_func = wrapped_func.__wrapped__
|
| 47 |
+
|
| 48 |
+
try:
|
| 49 |
+
file_path = inspect.getfile(wrapped_func)
|
| 50 |
+
_, first_file_line = inspect.getsourcelines(wrapped_func)
|
| 51 |
+
except TypeError: # Raises for builtins or native functions.
|
| 52 |
+
raise ValueError(
|
| 53 |
+
f"{func.__name__} cannot safely be wrapped by "
|
| 54 |
+
"@sensitive_variables, make it either non-async or defined in a "
|
| 55 |
+
"Python file (not a builtin or from a native extension)."
|
| 56 |
+
)
|
| 57 |
+
else:
|
| 58 |
+
key = hash(f"{file_path}:{first_file_line}")
|
| 59 |
+
|
| 60 |
+
if variables:
|
| 61 |
+
coroutine_functions_to_sensitive_variables[key] = variables
|
| 62 |
+
else:
|
| 63 |
+
coroutine_functions_to_sensitive_variables[key] = "__ALL__"
|
| 64 |
+
|
| 65 |
+
else:
|
| 66 |
+
|
| 67 |
+
@wraps(func)
|
| 68 |
+
def sensitive_variables_wrapper(*func_args, **func_kwargs):
|
| 69 |
+
if variables:
|
| 70 |
+
sensitive_variables_wrapper.sensitive_variables = variables
|
| 71 |
+
else:
|
| 72 |
+
sensitive_variables_wrapper.sensitive_variables = "__ALL__"
|
| 73 |
+
return func(*func_args, **func_kwargs)
|
| 74 |
+
|
| 75 |
+
return sensitive_variables_wrapper
|
| 76 |
+
|
| 77 |
+
return decorator
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def sensitive_post_parameters(*parameters):
|
| 81 |
+
"""
|
| 82 |
+
Indicate which POST parameters used in the decorated view are sensitive,
|
| 83 |
+
so that those parameters can later be treated in a special way, for example
|
| 84 |
+
by hiding them when logging unhandled exceptions.
|
| 85 |
+
|
| 86 |
+
Accept two forms:
|
| 87 |
+
|
| 88 |
+
* with specified parameters:
|
| 89 |
+
|
| 90 |
+
@sensitive_post_parameters('password', 'credit_card')
|
| 91 |
+
def my_view(request):
|
| 92 |
+
pw = request.POST['password']
|
| 93 |
+
cc = request.POST['credit_card']
|
| 94 |
+
...
|
| 95 |
+
|
| 96 |
+
* without any specified parameters, in which case consider all
|
| 97 |
+
variables are sensitive:
|
| 98 |
+
|
| 99 |
+
@sensitive_post_parameters()
|
| 100 |
+
def my_view(request)
|
| 101 |
+
...
|
| 102 |
+
"""
|
| 103 |
+
if len(parameters) == 1 and callable(parameters[0]):
|
| 104 |
+
raise TypeError(
|
| 105 |
+
"sensitive_post_parameters() must be called to use it as a "
|
| 106 |
+
"decorator, e.g., use @sensitive_post_parameters(), not "
|
| 107 |
+
"@sensitive_post_parameters."
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
def decorator(view):
|
| 111 |
+
if iscoroutinefunction(view):
|
| 112 |
+
|
| 113 |
+
@wraps(view)
|
| 114 |
+
async def sensitive_post_parameters_wrapper(request, *args, **kwargs):
|
| 115 |
+
if not isinstance(request, HttpRequest):
|
| 116 |
+
raise TypeError(
|
| 117 |
+
"sensitive_post_parameters didn't receive an HttpRequest "
|
| 118 |
+
"object. If you are decorating a classmethod, make sure to use "
|
| 119 |
+
"@method_decorator."
|
| 120 |
+
)
|
| 121 |
+
if parameters:
|
| 122 |
+
request.sensitive_post_parameters = parameters
|
| 123 |
+
else:
|
| 124 |
+
request.sensitive_post_parameters = "__ALL__"
|
| 125 |
+
return await view(request, *args, **kwargs)
|
| 126 |
+
|
| 127 |
+
else:
|
| 128 |
+
|
| 129 |
+
@wraps(view)
|
| 130 |
+
def sensitive_post_parameters_wrapper(request, *args, **kwargs):
|
| 131 |
+
if not isinstance(request, HttpRequest):
|
| 132 |
+
raise TypeError(
|
| 133 |
+
"sensitive_post_parameters didn't receive an HttpRequest "
|
| 134 |
+
"object. If you are decorating a classmethod, make sure to use "
|
| 135 |
+
"@method_decorator."
|
| 136 |
+
)
|
| 137 |
+
if parameters:
|
| 138 |
+
request.sensitive_post_parameters = parameters
|
| 139 |
+
else:
|
| 140 |
+
request.sensitive_post_parameters = "__ALL__"
|
| 141 |
+
return view(request, *args, **kwargs)
|
| 142 |
+
|
| 143 |
+
return sensitive_post_parameters_wrapper
|
| 144 |
+
|
| 145 |
+
return decorator
|
testbed/django__django/django/views/decorators/vary.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import wraps
|
| 2 |
+
|
| 3 |
+
from asgiref.sync import iscoroutinefunction
|
| 4 |
+
|
| 5 |
+
from django.utils.cache import patch_vary_headers
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def vary_on_headers(*headers):
|
| 9 |
+
"""
|
| 10 |
+
A view decorator that adds the specified headers to the Vary header of the
|
| 11 |
+
response. Usage:
|
| 12 |
+
|
| 13 |
+
@vary_on_headers('Cookie', 'Accept-language')
|
| 14 |
+
def index(request):
|
| 15 |
+
...
|
| 16 |
+
|
| 17 |
+
Note that the header names are not case-sensitive.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
def decorator(func):
|
| 21 |
+
if iscoroutinefunction(func):
|
| 22 |
+
|
| 23 |
+
async def _view_wrapper(request, *args, **kwargs):
|
| 24 |
+
response = await func(request, *args, **kwargs)
|
| 25 |
+
patch_vary_headers(response, headers)
|
| 26 |
+
return response
|
| 27 |
+
|
| 28 |
+
else:
|
| 29 |
+
|
| 30 |
+
def _view_wrapper(request, *args, **kwargs):
|
| 31 |
+
response = func(request, *args, **kwargs)
|
| 32 |
+
patch_vary_headers(response, headers)
|
| 33 |
+
return response
|
| 34 |
+
|
| 35 |
+
return wraps(func)(_view_wrapper)
|
| 36 |
+
|
| 37 |
+
return decorator
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
vary_on_cookie = vary_on_headers("Cookie")
|
| 41 |
+
vary_on_cookie.__doc__ = (
|
| 42 |
+
'A view decorator that adds "Cookie" to the Vary header of a response. This '
|
| 43 |
+
"indicates that a page's contents depends on cookies."
|
| 44 |
+
)
|
testbed/django__django/django/views/generic/__init__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.views.generic.base import RedirectView, TemplateView, View
|
| 2 |
+
from django.views.generic.dates import (
|
| 3 |
+
ArchiveIndexView,
|
| 4 |
+
DateDetailView,
|
| 5 |
+
DayArchiveView,
|
| 6 |
+
MonthArchiveView,
|
| 7 |
+
TodayArchiveView,
|
| 8 |
+
WeekArchiveView,
|
| 9 |
+
YearArchiveView,
|
| 10 |
+
)
|
| 11 |
+
from django.views.generic.detail import DetailView
|
| 12 |
+
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
|
| 13 |
+
from django.views.generic.list import ListView
|
| 14 |
+
|
| 15 |
+
__all__ = [
|
| 16 |
+
"View",
|
| 17 |
+
"TemplateView",
|
| 18 |
+
"RedirectView",
|
| 19 |
+
"ArchiveIndexView",
|
| 20 |
+
"YearArchiveView",
|
| 21 |
+
"MonthArchiveView",
|
| 22 |
+
"WeekArchiveView",
|
| 23 |
+
"DayArchiveView",
|
| 24 |
+
"TodayArchiveView",
|
| 25 |
+
"DateDetailView",
|
| 26 |
+
"DetailView",
|
| 27 |
+
"FormView",
|
| 28 |
+
"CreateView",
|
| 29 |
+
"UpdateView",
|
| 30 |
+
"DeleteView",
|
| 31 |
+
"ListView",
|
| 32 |
+
"GenericViewError",
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class GenericViewError(Exception):
|
| 37 |
+
"""A problem in a generic view."""
|
| 38 |
+
|
| 39 |
+
pass
|
testbed/django__django/django/views/generic/dates.py
ADDED
|
@@ -0,0 +1,795 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
|
| 3 |
+
from django.conf import settings
|
| 4 |
+
from django.core.exceptions import ImproperlyConfigured
|
| 5 |
+
from django.db import models
|
| 6 |
+
from django.http import Http404
|
| 7 |
+
from django.utils import timezone
|
| 8 |
+
from django.utils.functional import cached_property
|
| 9 |
+
from django.utils.translation import gettext as _
|
| 10 |
+
from django.views.generic.base import View
|
| 11 |
+
from django.views.generic.detail import (
|
| 12 |
+
BaseDetailView,
|
| 13 |
+
SingleObjectTemplateResponseMixin,
|
| 14 |
+
)
|
| 15 |
+
from django.views.generic.list import (
|
| 16 |
+
MultipleObjectMixin,
|
| 17 |
+
MultipleObjectTemplateResponseMixin,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class YearMixin:
|
| 22 |
+
"""Mixin for views manipulating year-based data."""
|
| 23 |
+
|
| 24 |
+
year_format = "%Y"
|
| 25 |
+
year = None
|
| 26 |
+
|
| 27 |
+
def get_year_format(self):
|
| 28 |
+
"""
|
| 29 |
+
Get a year format string in strptime syntax to be used to parse the
|
| 30 |
+
year from url variables.
|
| 31 |
+
"""
|
| 32 |
+
return self.year_format
|
| 33 |
+
|
| 34 |
+
def get_year(self):
|
| 35 |
+
"""Return the year for which this view should display data."""
|
| 36 |
+
year = self.year
|
| 37 |
+
if year is None:
|
| 38 |
+
try:
|
| 39 |
+
year = self.kwargs["year"]
|
| 40 |
+
except KeyError:
|
| 41 |
+
try:
|
| 42 |
+
year = self.request.GET["year"]
|
| 43 |
+
except KeyError:
|
| 44 |
+
raise Http404(_("No year specified"))
|
| 45 |
+
return year
|
| 46 |
+
|
| 47 |
+
def get_next_year(self, date):
|
| 48 |
+
"""Get the next valid year."""
|
| 49 |
+
return _get_next_prev(self, date, is_previous=False, period="year")
|
| 50 |
+
|
| 51 |
+
def get_previous_year(self, date):
|
| 52 |
+
"""Get the previous valid year."""
|
| 53 |
+
return _get_next_prev(self, date, is_previous=True, period="year")
|
| 54 |
+
|
| 55 |
+
def _get_next_year(self, date):
|
| 56 |
+
"""
|
| 57 |
+
Return the start date of the next interval.
|
| 58 |
+
|
| 59 |
+
The interval is defined by start date <= item date < next start date.
|
| 60 |
+
"""
|
| 61 |
+
try:
|
| 62 |
+
return date.replace(year=date.year + 1, month=1, day=1)
|
| 63 |
+
except ValueError:
|
| 64 |
+
raise Http404(_("Date out of range"))
|
| 65 |
+
|
| 66 |
+
def _get_current_year(self, date):
|
| 67 |
+
"""Return the start date of the current interval."""
|
| 68 |
+
return date.replace(month=1, day=1)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class MonthMixin:
|
| 72 |
+
"""Mixin for views manipulating month-based data."""
|
| 73 |
+
|
| 74 |
+
month_format = "%b"
|
| 75 |
+
month = None
|
| 76 |
+
|
| 77 |
+
def get_month_format(self):
|
| 78 |
+
"""
|
| 79 |
+
Get a month format string in strptime syntax to be used to parse the
|
| 80 |
+
month from url variables.
|
| 81 |
+
"""
|
| 82 |
+
return self.month_format
|
| 83 |
+
|
| 84 |
+
def get_month(self):
|
| 85 |
+
"""Return the month for which this view should display data."""
|
| 86 |
+
month = self.month
|
| 87 |
+
if month is None:
|
| 88 |
+
try:
|
| 89 |
+
month = self.kwargs["month"]
|
| 90 |
+
except KeyError:
|
| 91 |
+
try:
|
| 92 |
+
month = self.request.GET["month"]
|
| 93 |
+
except KeyError:
|
| 94 |
+
raise Http404(_("No month specified"))
|
| 95 |
+
return month
|
| 96 |
+
|
| 97 |
+
def get_next_month(self, date):
|
| 98 |
+
"""Get the next valid month."""
|
| 99 |
+
return _get_next_prev(self, date, is_previous=False, period="month")
|
| 100 |
+
|
| 101 |
+
def get_previous_month(self, date):
|
| 102 |
+
"""Get the previous valid month."""
|
| 103 |
+
return _get_next_prev(self, date, is_previous=True, period="month")
|
| 104 |
+
|
| 105 |
+
def _get_next_month(self, date):
|
| 106 |
+
"""
|
| 107 |
+
Return the start date of the next interval.
|
| 108 |
+
|
| 109 |
+
The interval is defined by start date <= item date < next start date.
|
| 110 |
+
"""
|
| 111 |
+
if date.month == 12:
|
| 112 |
+
try:
|
| 113 |
+
return date.replace(year=date.year + 1, month=1, day=1)
|
| 114 |
+
except ValueError:
|
| 115 |
+
raise Http404(_("Date out of range"))
|
| 116 |
+
else:
|
| 117 |
+
return date.replace(month=date.month + 1, day=1)
|
| 118 |
+
|
| 119 |
+
def _get_current_month(self, date):
|
| 120 |
+
"""Return the start date of the previous interval."""
|
| 121 |
+
return date.replace(day=1)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
class DayMixin:
|
| 125 |
+
"""Mixin for views manipulating day-based data."""
|
| 126 |
+
|
| 127 |
+
day_format = "%d"
|
| 128 |
+
day = None
|
| 129 |
+
|
| 130 |
+
def get_day_format(self):
|
| 131 |
+
"""
|
| 132 |
+
Get a day format string in strptime syntax to be used to parse the day
|
| 133 |
+
from url variables.
|
| 134 |
+
"""
|
| 135 |
+
return self.day_format
|
| 136 |
+
|
| 137 |
+
def get_day(self):
|
| 138 |
+
"""Return the day for which this view should display data."""
|
| 139 |
+
day = self.day
|
| 140 |
+
if day is None:
|
| 141 |
+
try:
|
| 142 |
+
day = self.kwargs["day"]
|
| 143 |
+
except KeyError:
|
| 144 |
+
try:
|
| 145 |
+
day = self.request.GET["day"]
|
| 146 |
+
except KeyError:
|
| 147 |
+
raise Http404(_("No day specified"))
|
| 148 |
+
return day
|
| 149 |
+
|
| 150 |
+
def get_next_day(self, date):
|
| 151 |
+
"""Get the next valid day."""
|
| 152 |
+
return _get_next_prev(self, date, is_previous=False, period="day")
|
| 153 |
+
|
| 154 |
+
def get_previous_day(self, date):
|
| 155 |
+
"""Get the previous valid day."""
|
| 156 |
+
return _get_next_prev(self, date, is_previous=True, period="day")
|
| 157 |
+
|
| 158 |
+
def _get_next_day(self, date):
|
| 159 |
+
"""
|
| 160 |
+
Return the start date of the next interval.
|
| 161 |
+
|
| 162 |
+
The interval is defined by start date <= item date < next start date.
|
| 163 |
+
"""
|
| 164 |
+
return date + datetime.timedelta(days=1)
|
| 165 |
+
|
| 166 |
+
def _get_current_day(self, date):
|
| 167 |
+
"""Return the start date of the current interval."""
|
| 168 |
+
return date
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class WeekMixin:
|
| 172 |
+
"""Mixin for views manipulating week-based data."""
|
| 173 |
+
|
| 174 |
+
week_format = "%U"
|
| 175 |
+
week = None
|
| 176 |
+
|
| 177 |
+
def get_week_format(self):
|
| 178 |
+
"""
|
| 179 |
+
Get a week format string in strptime syntax to be used to parse the
|
| 180 |
+
week from url variables.
|
| 181 |
+
"""
|
| 182 |
+
return self.week_format
|
| 183 |
+
|
| 184 |
+
def get_week(self):
|
| 185 |
+
"""Return the week for which this view should display data."""
|
| 186 |
+
week = self.week
|
| 187 |
+
if week is None:
|
| 188 |
+
try:
|
| 189 |
+
week = self.kwargs["week"]
|
| 190 |
+
except KeyError:
|
| 191 |
+
try:
|
| 192 |
+
week = self.request.GET["week"]
|
| 193 |
+
except KeyError:
|
| 194 |
+
raise Http404(_("No week specified"))
|
| 195 |
+
return week
|
| 196 |
+
|
| 197 |
+
def get_next_week(self, date):
|
| 198 |
+
"""Get the next valid week."""
|
| 199 |
+
return _get_next_prev(self, date, is_previous=False, period="week")
|
| 200 |
+
|
| 201 |
+
def get_previous_week(self, date):
|
| 202 |
+
"""Get the previous valid week."""
|
| 203 |
+
return _get_next_prev(self, date, is_previous=True, period="week")
|
| 204 |
+
|
| 205 |
+
def _get_next_week(self, date):
|
| 206 |
+
"""
|
| 207 |
+
Return the start date of the next interval.
|
| 208 |
+
|
| 209 |
+
The interval is defined by start date <= item date < next start date.
|
| 210 |
+
"""
|
| 211 |
+
try:
|
| 212 |
+
return date + datetime.timedelta(days=7 - self._get_weekday(date))
|
| 213 |
+
except OverflowError:
|
| 214 |
+
raise Http404(_("Date out of range"))
|
| 215 |
+
|
| 216 |
+
def _get_current_week(self, date):
|
| 217 |
+
"""Return the start date of the current interval."""
|
| 218 |
+
return date - datetime.timedelta(self._get_weekday(date))
|
| 219 |
+
|
| 220 |
+
def _get_weekday(self, date):
|
| 221 |
+
"""
|
| 222 |
+
Return the weekday for a given date.
|
| 223 |
+
|
| 224 |
+
The first day according to the week format is 0 and the last day is 6.
|
| 225 |
+
"""
|
| 226 |
+
week_format = self.get_week_format()
|
| 227 |
+
if week_format in {"%W", "%V"}: # week starts on Monday
|
| 228 |
+
return date.weekday()
|
| 229 |
+
elif week_format == "%U": # week starts on Sunday
|
| 230 |
+
return (date.weekday() + 1) % 7
|
| 231 |
+
else:
|
| 232 |
+
raise ValueError("unknown week format: %s" % week_format)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
class DateMixin:
|
| 236 |
+
"""Mixin class for views manipulating date-based data."""
|
| 237 |
+
|
| 238 |
+
date_field = None
|
| 239 |
+
allow_future = False
|
| 240 |
+
|
| 241 |
+
def get_date_field(self):
|
| 242 |
+
"""Get the name of the date field to be used to filter by."""
|
| 243 |
+
if self.date_field is None:
|
| 244 |
+
raise ImproperlyConfigured(
|
| 245 |
+
"%s.date_field is required." % self.__class__.__name__
|
| 246 |
+
)
|
| 247 |
+
return self.date_field
|
| 248 |
+
|
| 249 |
+
def get_allow_future(self):
|
| 250 |
+
"""
|
| 251 |
+
Return `True` if the view should be allowed to display objects from
|
| 252 |
+
the future.
|
| 253 |
+
"""
|
| 254 |
+
return self.allow_future
|
| 255 |
+
|
| 256 |
+
# Note: the following three methods only work in subclasses that also
|
| 257 |
+
# inherit SingleObjectMixin or MultipleObjectMixin.
|
| 258 |
+
|
| 259 |
+
@cached_property
|
| 260 |
+
def uses_datetime_field(self):
|
| 261 |
+
"""
|
| 262 |
+
Return `True` if the date field is a `DateTimeField` and `False`
|
| 263 |
+
if it's a `DateField`.
|
| 264 |
+
"""
|
| 265 |
+
model = self.get_queryset().model if self.model is None else self.model
|
| 266 |
+
field = model._meta.get_field(self.get_date_field())
|
| 267 |
+
return isinstance(field, models.DateTimeField)
|
| 268 |
+
|
| 269 |
+
def _make_date_lookup_arg(self, value):
|
| 270 |
+
"""
|
| 271 |
+
Convert a date into a datetime when the date field is a DateTimeField.
|
| 272 |
+
|
| 273 |
+
When time zone support is enabled, `date` is assumed to be in the
|
| 274 |
+
current time zone, so that displayed items are consistent with the URL.
|
| 275 |
+
"""
|
| 276 |
+
if self.uses_datetime_field:
|
| 277 |
+
value = datetime.datetime.combine(value, datetime.time.min)
|
| 278 |
+
if settings.USE_TZ:
|
| 279 |
+
value = timezone.make_aware(value)
|
| 280 |
+
return value
|
| 281 |
+
|
| 282 |
+
def _make_single_date_lookup(self, date):
|
| 283 |
+
"""
|
| 284 |
+
Get the lookup kwargs for filtering on a single date.
|
| 285 |
+
|
| 286 |
+
If the date field is a DateTimeField, we can't just filter on
|
| 287 |
+
date_field=date because that doesn't take the time into account.
|
| 288 |
+
"""
|
| 289 |
+
date_field = self.get_date_field()
|
| 290 |
+
if self.uses_datetime_field:
|
| 291 |
+
since = self._make_date_lookup_arg(date)
|
| 292 |
+
until = self._make_date_lookup_arg(date + datetime.timedelta(days=1))
|
| 293 |
+
return {
|
| 294 |
+
"%s__gte" % date_field: since,
|
| 295 |
+
"%s__lt" % date_field: until,
|
| 296 |
+
}
|
| 297 |
+
else:
|
| 298 |
+
# Skip self._make_date_lookup_arg, it's a no-op in this branch.
|
| 299 |
+
return {date_field: date}
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
class BaseDateListView(MultipleObjectMixin, DateMixin, View):
|
| 303 |
+
"""Abstract base class for date-based views displaying a list of objects."""
|
| 304 |
+
|
| 305 |
+
allow_empty = False
|
| 306 |
+
date_list_period = "year"
|
| 307 |
+
|
| 308 |
+
def get(self, request, *args, **kwargs):
|
| 309 |
+
self.date_list, self.object_list, extra_context = self.get_dated_items()
|
| 310 |
+
context = self.get_context_data(
|
| 311 |
+
object_list=self.object_list, date_list=self.date_list, **extra_context
|
| 312 |
+
)
|
| 313 |
+
return self.render_to_response(context)
|
| 314 |
+
|
| 315 |
+
def get_dated_items(self):
|
| 316 |
+
"""Obtain the list of dates and items."""
|
| 317 |
+
raise NotImplementedError(
|
| 318 |
+
"A DateView must provide an implementation of get_dated_items()"
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
def get_ordering(self):
|
| 322 |
+
"""
|
| 323 |
+
Return the field or fields to use for ordering the queryset; use the
|
| 324 |
+
date field by default.
|
| 325 |
+
"""
|
| 326 |
+
return "-%s" % self.get_date_field() if self.ordering is None else self.ordering
|
| 327 |
+
|
| 328 |
+
def get_dated_queryset(self, **lookup):
|
| 329 |
+
"""
|
| 330 |
+
Get a queryset properly filtered according to `allow_future` and any
|
| 331 |
+
extra lookup kwargs.
|
| 332 |
+
"""
|
| 333 |
+
qs = self.get_queryset().filter(**lookup)
|
| 334 |
+
date_field = self.get_date_field()
|
| 335 |
+
allow_future = self.get_allow_future()
|
| 336 |
+
allow_empty = self.get_allow_empty()
|
| 337 |
+
paginate_by = self.get_paginate_by(qs)
|
| 338 |
+
|
| 339 |
+
if not allow_future:
|
| 340 |
+
now = timezone.now() if self.uses_datetime_field else timezone_today()
|
| 341 |
+
qs = qs.filter(**{"%s__lte" % date_field: now})
|
| 342 |
+
|
| 343 |
+
if not allow_empty:
|
| 344 |
+
# When pagination is enabled, it's better to do a cheap query
|
| 345 |
+
# than to load the unpaginated queryset in memory.
|
| 346 |
+
is_empty = not qs if paginate_by is None else not qs.exists()
|
| 347 |
+
if is_empty:
|
| 348 |
+
raise Http404(
|
| 349 |
+
_("No %(verbose_name_plural)s available")
|
| 350 |
+
% {
|
| 351 |
+
"verbose_name_plural": qs.model._meta.verbose_name_plural,
|
| 352 |
+
}
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
return qs
|
| 356 |
+
|
| 357 |
+
def get_date_list_period(self):
|
| 358 |
+
"""
|
| 359 |
+
Get the aggregation period for the list of dates: 'year', 'month', or
|
| 360 |
+
'day'.
|
| 361 |
+
"""
|
| 362 |
+
return self.date_list_period
|
| 363 |
+
|
| 364 |
+
def get_date_list(self, queryset, date_type=None, ordering="ASC"):
|
| 365 |
+
"""
|
| 366 |
+
Get a date list by calling `queryset.dates/datetimes()`, checking
|
| 367 |
+
along the way for empty lists that aren't allowed.
|
| 368 |
+
"""
|
| 369 |
+
date_field = self.get_date_field()
|
| 370 |
+
allow_empty = self.get_allow_empty()
|
| 371 |
+
if date_type is None:
|
| 372 |
+
date_type = self.get_date_list_period()
|
| 373 |
+
|
| 374 |
+
if self.uses_datetime_field:
|
| 375 |
+
date_list = queryset.datetimes(date_field, date_type, ordering)
|
| 376 |
+
else:
|
| 377 |
+
date_list = queryset.dates(date_field, date_type, ordering)
|
| 378 |
+
if date_list is not None and not date_list and not allow_empty:
|
| 379 |
+
raise Http404(
|
| 380 |
+
_("No %(verbose_name_plural)s available")
|
| 381 |
+
% {
|
| 382 |
+
"verbose_name_plural": queryset.model._meta.verbose_name_plural,
|
| 383 |
+
}
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
return date_list
|
| 387 |
+
|
| 388 |
+
|
| 389 |
+
class BaseArchiveIndexView(BaseDateListView):
|
| 390 |
+
"""
|
| 391 |
+
Base class for archives of date-based items. Requires a response mixin.
|
| 392 |
+
"""
|
| 393 |
+
|
| 394 |
+
context_object_name = "latest"
|
| 395 |
+
|
| 396 |
+
def get_dated_items(self):
|
| 397 |
+
"""Return (date_list, items, extra_context) for this request."""
|
| 398 |
+
qs = self.get_dated_queryset()
|
| 399 |
+
date_list = self.get_date_list(qs, ordering="DESC")
|
| 400 |
+
|
| 401 |
+
if not date_list:
|
| 402 |
+
qs = qs.none()
|
| 403 |
+
|
| 404 |
+
return (date_list, qs, {})
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
class ArchiveIndexView(MultipleObjectTemplateResponseMixin, BaseArchiveIndexView):
|
| 408 |
+
"""Top-level archive of date-based items."""
|
| 409 |
+
|
| 410 |
+
template_name_suffix = "_archive"
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
class BaseYearArchiveView(YearMixin, BaseDateListView):
|
| 414 |
+
"""List of objects published in a given year."""
|
| 415 |
+
|
| 416 |
+
date_list_period = "month"
|
| 417 |
+
make_object_list = False
|
| 418 |
+
|
| 419 |
+
def get_dated_items(self):
|
| 420 |
+
"""Return (date_list, items, extra_context) for this request."""
|
| 421 |
+
year = self.get_year()
|
| 422 |
+
|
| 423 |
+
date_field = self.get_date_field()
|
| 424 |
+
date = _date_from_string(year, self.get_year_format())
|
| 425 |
+
|
| 426 |
+
since = self._make_date_lookup_arg(date)
|
| 427 |
+
until = self._make_date_lookup_arg(self._get_next_year(date))
|
| 428 |
+
lookup_kwargs = {
|
| 429 |
+
"%s__gte" % date_field: since,
|
| 430 |
+
"%s__lt" % date_field: until,
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
qs = self.get_dated_queryset(**lookup_kwargs)
|
| 434 |
+
date_list = self.get_date_list(qs)
|
| 435 |
+
|
| 436 |
+
if not self.get_make_object_list():
|
| 437 |
+
# We need this to be a queryset since parent classes introspect it
|
| 438 |
+
# to find information about the model.
|
| 439 |
+
qs = qs.none()
|
| 440 |
+
|
| 441 |
+
return (
|
| 442 |
+
date_list,
|
| 443 |
+
qs,
|
| 444 |
+
{
|
| 445 |
+
"year": date,
|
| 446 |
+
"next_year": self.get_next_year(date),
|
| 447 |
+
"previous_year": self.get_previous_year(date),
|
| 448 |
+
},
|
| 449 |
+
)
|
| 450 |
+
|
| 451 |
+
def get_make_object_list(self):
|
| 452 |
+
"""
|
| 453 |
+
Return `True` if this view should contain the full list of objects in
|
| 454 |
+
the given year.
|
| 455 |
+
"""
|
| 456 |
+
return self.make_object_list
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
class YearArchiveView(MultipleObjectTemplateResponseMixin, BaseYearArchiveView):
|
| 460 |
+
"""List of objects published in a given year."""
|
| 461 |
+
|
| 462 |
+
template_name_suffix = "_archive_year"
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
class BaseMonthArchiveView(YearMixin, MonthMixin, BaseDateListView):
|
| 466 |
+
"""List of objects published in a given month."""
|
| 467 |
+
|
| 468 |
+
date_list_period = "day"
|
| 469 |
+
|
| 470 |
+
def get_dated_items(self):
|
| 471 |
+
"""Return (date_list, items, extra_context) for this request."""
|
| 472 |
+
year = self.get_year()
|
| 473 |
+
month = self.get_month()
|
| 474 |
+
|
| 475 |
+
date_field = self.get_date_field()
|
| 476 |
+
date = _date_from_string(
|
| 477 |
+
year, self.get_year_format(), month, self.get_month_format()
|
| 478 |
+
)
|
| 479 |
+
|
| 480 |
+
since = self._make_date_lookup_arg(date)
|
| 481 |
+
until = self._make_date_lookup_arg(self._get_next_month(date))
|
| 482 |
+
lookup_kwargs = {
|
| 483 |
+
"%s__gte" % date_field: since,
|
| 484 |
+
"%s__lt" % date_field: until,
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
qs = self.get_dated_queryset(**lookup_kwargs)
|
| 488 |
+
date_list = self.get_date_list(qs)
|
| 489 |
+
|
| 490 |
+
return (
|
| 491 |
+
date_list,
|
| 492 |
+
qs,
|
| 493 |
+
{
|
| 494 |
+
"month": date,
|
| 495 |
+
"next_month": self.get_next_month(date),
|
| 496 |
+
"previous_month": self.get_previous_month(date),
|
| 497 |
+
},
|
| 498 |
+
)
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
class MonthArchiveView(MultipleObjectTemplateResponseMixin, BaseMonthArchiveView):
|
| 502 |
+
"""List of objects published in a given month."""
|
| 503 |
+
|
| 504 |
+
template_name_suffix = "_archive_month"
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
class BaseWeekArchiveView(YearMixin, WeekMixin, BaseDateListView):
|
| 508 |
+
"""List of objects published in a given week."""
|
| 509 |
+
|
| 510 |
+
def get_dated_items(self):
|
| 511 |
+
"""Return (date_list, items, extra_context) for this request."""
|
| 512 |
+
year = self.get_year()
|
| 513 |
+
week = self.get_week()
|
| 514 |
+
|
| 515 |
+
date_field = self.get_date_field()
|
| 516 |
+
week_format = self.get_week_format()
|
| 517 |
+
week_choices = {"%W": "1", "%U": "0", "%V": "1"}
|
| 518 |
+
try:
|
| 519 |
+
week_start = week_choices[week_format]
|
| 520 |
+
except KeyError:
|
| 521 |
+
raise ValueError(
|
| 522 |
+
"Unknown week format %r. Choices are: %s"
|
| 523 |
+
% (
|
| 524 |
+
week_format,
|
| 525 |
+
", ".join(sorted(week_choices)),
|
| 526 |
+
)
|
| 527 |
+
)
|
| 528 |
+
year_format = self.get_year_format()
|
| 529 |
+
if week_format == "%V" and year_format != "%G":
|
| 530 |
+
raise ValueError(
|
| 531 |
+
"ISO week directive '%s' is incompatible with the year "
|
| 532 |
+
"directive '%s'. Use the ISO year '%%G' instead."
|
| 533 |
+
% (
|
| 534 |
+
week_format,
|
| 535 |
+
year_format,
|
| 536 |
+
)
|
| 537 |
+
)
|
| 538 |
+
date = _date_from_string(year, year_format, week_start, "%w", week, week_format)
|
| 539 |
+
since = self._make_date_lookup_arg(date)
|
| 540 |
+
until = self._make_date_lookup_arg(self._get_next_week(date))
|
| 541 |
+
lookup_kwargs = {
|
| 542 |
+
"%s__gte" % date_field: since,
|
| 543 |
+
"%s__lt" % date_field: until,
|
| 544 |
+
}
|
| 545 |
+
|
| 546 |
+
qs = self.get_dated_queryset(**lookup_kwargs)
|
| 547 |
+
|
| 548 |
+
return (
|
| 549 |
+
None,
|
| 550 |
+
qs,
|
| 551 |
+
{
|
| 552 |
+
"week": date,
|
| 553 |
+
"next_week": self.get_next_week(date),
|
| 554 |
+
"previous_week": self.get_previous_week(date),
|
| 555 |
+
},
|
| 556 |
+
)
|
| 557 |
+
|
| 558 |
+
|
| 559 |
+
class WeekArchiveView(MultipleObjectTemplateResponseMixin, BaseWeekArchiveView):
|
| 560 |
+
"""List of objects published in a given week."""
|
| 561 |
+
|
| 562 |
+
template_name_suffix = "_archive_week"
|
| 563 |
+
|
| 564 |
+
|
| 565 |
+
class BaseDayArchiveView(YearMixin, MonthMixin, DayMixin, BaseDateListView):
|
| 566 |
+
"""List of objects published on a given day."""
|
| 567 |
+
|
| 568 |
+
def get_dated_items(self):
|
| 569 |
+
"""Return (date_list, items, extra_context) for this request."""
|
| 570 |
+
year = self.get_year()
|
| 571 |
+
month = self.get_month()
|
| 572 |
+
day = self.get_day()
|
| 573 |
+
|
| 574 |
+
date = _date_from_string(
|
| 575 |
+
year,
|
| 576 |
+
self.get_year_format(),
|
| 577 |
+
month,
|
| 578 |
+
self.get_month_format(),
|
| 579 |
+
day,
|
| 580 |
+
self.get_day_format(),
|
| 581 |
+
)
|
| 582 |
+
|
| 583 |
+
return self._get_dated_items(date)
|
| 584 |
+
|
| 585 |
+
def _get_dated_items(self, date):
|
| 586 |
+
"""
|
| 587 |
+
Do the actual heavy lifting of getting the dated items; this accepts a
|
| 588 |
+
date object so that TodayArchiveView can be trivial.
|
| 589 |
+
"""
|
| 590 |
+
lookup_kwargs = self._make_single_date_lookup(date)
|
| 591 |
+
qs = self.get_dated_queryset(**lookup_kwargs)
|
| 592 |
+
|
| 593 |
+
return (
|
| 594 |
+
None,
|
| 595 |
+
qs,
|
| 596 |
+
{
|
| 597 |
+
"day": date,
|
| 598 |
+
"previous_day": self.get_previous_day(date),
|
| 599 |
+
"next_day": self.get_next_day(date),
|
| 600 |
+
"previous_month": self.get_previous_month(date),
|
| 601 |
+
"next_month": self.get_next_month(date),
|
| 602 |
+
},
|
| 603 |
+
)
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
class DayArchiveView(MultipleObjectTemplateResponseMixin, BaseDayArchiveView):
|
| 607 |
+
"""List of objects published on a given day."""
|
| 608 |
+
|
| 609 |
+
template_name_suffix = "_archive_day"
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
class BaseTodayArchiveView(BaseDayArchiveView):
|
| 613 |
+
"""List of objects published today."""
|
| 614 |
+
|
| 615 |
+
def get_dated_items(self):
|
| 616 |
+
"""Return (date_list, items, extra_context) for this request."""
|
| 617 |
+
return self._get_dated_items(datetime.date.today())
|
| 618 |
+
|
| 619 |
+
|
| 620 |
+
class TodayArchiveView(MultipleObjectTemplateResponseMixin, BaseTodayArchiveView):
|
| 621 |
+
"""List of objects published today."""
|
| 622 |
+
|
| 623 |
+
template_name_suffix = "_archive_day"
|
| 624 |
+
|
| 625 |
+
|
| 626 |
+
class BaseDateDetailView(YearMixin, MonthMixin, DayMixin, DateMixin, BaseDetailView):
|
| 627 |
+
"""
|
| 628 |
+
Detail view of a single object on a single date; this differs from the
|
| 629 |
+
standard DetailView by accepting a year/month/day in the URL.
|
| 630 |
+
"""
|
| 631 |
+
|
| 632 |
+
def get_object(self, queryset=None):
|
| 633 |
+
"""Get the object this request displays."""
|
| 634 |
+
year = self.get_year()
|
| 635 |
+
month = self.get_month()
|
| 636 |
+
day = self.get_day()
|
| 637 |
+
date = _date_from_string(
|
| 638 |
+
year,
|
| 639 |
+
self.get_year_format(),
|
| 640 |
+
month,
|
| 641 |
+
self.get_month_format(),
|
| 642 |
+
day,
|
| 643 |
+
self.get_day_format(),
|
| 644 |
+
)
|
| 645 |
+
|
| 646 |
+
# Use a custom queryset if provided
|
| 647 |
+
qs = self.get_queryset() if queryset is None else queryset
|
| 648 |
+
|
| 649 |
+
if not self.get_allow_future() and date > datetime.date.today():
|
| 650 |
+
raise Http404(
|
| 651 |
+
_(
|
| 652 |
+
"Future %(verbose_name_plural)s not available because "
|
| 653 |
+
"%(class_name)s.allow_future is False."
|
| 654 |
+
)
|
| 655 |
+
% {
|
| 656 |
+
"verbose_name_plural": qs.model._meta.verbose_name_plural,
|
| 657 |
+
"class_name": self.__class__.__name__,
|
| 658 |
+
}
|
| 659 |
+
)
|
| 660 |
+
|
| 661 |
+
# Filter down a queryset from self.queryset using the date from the
|
| 662 |
+
# URL. This'll get passed as the queryset to DetailView.get_object,
|
| 663 |
+
# which'll handle the 404
|
| 664 |
+
lookup_kwargs = self._make_single_date_lookup(date)
|
| 665 |
+
qs = qs.filter(**lookup_kwargs)
|
| 666 |
+
|
| 667 |
+
return super().get_object(queryset=qs)
|
| 668 |
+
|
| 669 |
+
|
| 670 |
+
class DateDetailView(SingleObjectTemplateResponseMixin, BaseDateDetailView):
|
| 671 |
+
"""
|
| 672 |
+
Detail view of a single object on a single date; this differs from the
|
| 673 |
+
standard DetailView by accepting a year/month/day in the URL.
|
| 674 |
+
"""
|
| 675 |
+
|
| 676 |
+
template_name_suffix = "_detail"
|
| 677 |
+
|
| 678 |
+
|
| 679 |
+
def _date_from_string(
|
| 680 |
+
year, year_format, month="", month_format="", day="", day_format="", delim="__"
|
| 681 |
+
):
|
| 682 |
+
"""
|
| 683 |
+
Get a datetime.date object given a format string and a year, month, and day
|
| 684 |
+
(only year is mandatory). Raise a 404 for an invalid date.
|
| 685 |
+
"""
|
| 686 |
+
format = year_format + delim + month_format + delim + day_format
|
| 687 |
+
datestr = str(year) + delim + str(month) + delim + str(day)
|
| 688 |
+
try:
|
| 689 |
+
return datetime.datetime.strptime(datestr, format).date()
|
| 690 |
+
except ValueError:
|
| 691 |
+
raise Http404(
|
| 692 |
+
_("Invalid date string “%(datestr)s” given format “%(format)s”")
|
| 693 |
+
% {
|
| 694 |
+
"datestr": datestr,
|
| 695 |
+
"format": format,
|
| 696 |
+
}
|
| 697 |
+
)
|
| 698 |
+
|
| 699 |
+
|
| 700 |
+
def _get_next_prev(generic_view, date, is_previous, period):
|
| 701 |
+
"""
|
| 702 |
+
Get the next or the previous valid date. The idea is to allow links on
|
| 703 |
+
month/day views to never be 404s by never providing a date that'll be
|
| 704 |
+
invalid for the given view.
|
| 705 |
+
|
| 706 |
+
This is a bit complicated since it handles different intervals of time,
|
| 707 |
+
hence the coupling to generic_view.
|
| 708 |
+
|
| 709 |
+
However in essence the logic comes down to:
|
| 710 |
+
|
| 711 |
+
* If allow_empty and allow_future are both true, this is easy: just
|
| 712 |
+
return the naive result (just the next/previous day/week/month,
|
| 713 |
+
regardless of object existence.)
|
| 714 |
+
|
| 715 |
+
* If allow_empty is true, allow_future is false, and the naive result
|
| 716 |
+
isn't in the future, then return it; otherwise return None.
|
| 717 |
+
|
| 718 |
+
* If allow_empty is false and allow_future is true, return the next
|
| 719 |
+
date *that contains a valid object*, even if it's in the future. If
|
| 720 |
+
there are no next objects, return None.
|
| 721 |
+
|
| 722 |
+
* If allow_empty is false and allow_future is false, return the next
|
| 723 |
+
date that contains a valid object. If that date is in the future, or
|
| 724 |
+
if there are no next objects, return None.
|
| 725 |
+
"""
|
| 726 |
+
date_field = generic_view.get_date_field()
|
| 727 |
+
allow_empty = generic_view.get_allow_empty()
|
| 728 |
+
allow_future = generic_view.get_allow_future()
|
| 729 |
+
|
| 730 |
+
get_current = getattr(generic_view, "_get_current_%s" % period)
|
| 731 |
+
get_next = getattr(generic_view, "_get_next_%s" % period)
|
| 732 |
+
|
| 733 |
+
# Bounds of the current interval
|
| 734 |
+
start, end = get_current(date), get_next(date)
|
| 735 |
+
|
| 736 |
+
# If allow_empty is True, the naive result will be valid
|
| 737 |
+
if allow_empty:
|
| 738 |
+
if is_previous:
|
| 739 |
+
result = get_current(start - datetime.timedelta(days=1))
|
| 740 |
+
else:
|
| 741 |
+
result = end
|
| 742 |
+
|
| 743 |
+
if allow_future or result <= timezone_today():
|
| 744 |
+
return result
|
| 745 |
+
else:
|
| 746 |
+
return None
|
| 747 |
+
|
| 748 |
+
# Otherwise, we'll need to go to the database to look for an object
|
| 749 |
+
# whose date_field is at least (greater than/less than) the given
|
| 750 |
+
# naive result
|
| 751 |
+
else:
|
| 752 |
+
# Construct a lookup and an ordering depending on whether we're doing
|
| 753 |
+
# a previous date or a next date lookup.
|
| 754 |
+
if is_previous:
|
| 755 |
+
lookup = {"%s__lt" % date_field: generic_view._make_date_lookup_arg(start)}
|
| 756 |
+
ordering = "-%s" % date_field
|
| 757 |
+
else:
|
| 758 |
+
lookup = {"%s__gte" % date_field: generic_view._make_date_lookup_arg(end)}
|
| 759 |
+
ordering = date_field
|
| 760 |
+
|
| 761 |
+
# Filter out objects in the future if appropriate.
|
| 762 |
+
if not allow_future:
|
| 763 |
+
# Fortunately, to match the implementation of allow_future,
|
| 764 |
+
# we need __lte, which doesn't conflict with __lt above.
|
| 765 |
+
if generic_view.uses_datetime_field:
|
| 766 |
+
now = timezone.now()
|
| 767 |
+
else:
|
| 768 |
+
now = timezone_today()
|
| 769 |
+
lookup["%s__lte" % date_field] = now
|
| 770 |
+
|
| 771 |
+
qs = generic_view.get_queryset().filter(**lookup).order_by(ordering)
|
| 772 |
+
|
| 773 |
+
# Snag the first object from the queryset; if it doesn't exist that
|
| 774 |
+
# means there's no next/previous link available.
|
| 775 |
+
try:
|
| 776 |
+
result = getattr(qs[0], date_field)
|
| 777 |
+
except IndexError:
|
| 778 |
+
return None
|
| 779 |
+
|
| 780 |
+
# Convert datetimes to dates in the current time zone.
|
| 781 |
+
if generic_view.uses_datetime_field:
|
| 782 |
+
if settings.USE_TZ:
|
| 783 |
+
result = timezone.localtime(result)
|
| 784 |
+
result = result.date()
|
| 785 |
+
|
| 786 |
+
# Return the first day of the period.
|
| 787 |
+
return get_current(result)
|
| 788 |
+
|
| 789 |
+
|
| 790 |
+
def timezone_today():
|
| 791 |
+
"""Return the current date in the current time zone."""
|
| 792 |
+
if settings.USE_TZ:
|
| 793 |
+
return timezone.localdate()
|
| 794 |
+
else:
|
| 795 |
+
return datetime.date.today()
|
testbed/django__django/django/views/generic/edit.py
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.core.exceptions import ImproperlyConfigured
|
| 2 |
+
from django.forms import Form
|
| 3 |
+
from django.forms import models as model_forms
|
| 4 |
+
from django.http import HttpResponseRedirect
|
| 5 |
+
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
|
| 6 |
+
from django.views.generic.detail import (
|
| 7 |
+
BaseDetailView,
|
| 8 |
+
SingleObjectMixin,
|
| 9 |
+
SingleObjectTemplateResponseMixin,
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class FormMixin(ContextMixin):
|
| 14 |
+
"""Provide a way to show and handle a form in a request."""
|
| 15 |
+
|
| 16 |
+
initial = {}
|
| 17 |
+
form_class = None
|
| 18 |
+
success_url = None
|
| 19 |
+
prefix = None
|
| 20 |
+
|
| 21 |
+
def get_initial(self):
|
| 22 |
+
"""Return the initial data to use for forms on this view."""
|
| 23 |
+
return self.initial.copy()
|
| 24 |
+
|
| 25 |
+
def get_prefix(self):
|
| 26 |
+
"""Return the prefix to use for forms."""
|
| 27 |
+
return self.prefix
|
| 28 |
+
|
| 29 |
+
def get_form_class(self):
|
| 30 |
+
"""Return the form class to use."""
|
| 31 |
+
return self.form_class
|
| 32 |
+
|
| 33 |
+
def get_form(self, form_class=None):
|
| 34 |
+
"""Return an instance of the form to be used in this view."""
|
| 35 |
+
if form_class is None:
|
| 36 |
+
form_class = self.get_form_class()
|
| 37 |
+
return form_class(**self.get_form_kwargs())
|
| 38 |
+
|
| 39 |
+
def get_form_kwargs(self):
|
| 40 |
+
"""Return the keyword arguments for instantiating the form."""
|
| 41 |
+
kwargs = {
|
| 42 |
+
"initial": self.get_initial(),
|
| 43 |
+
"prefix": self.get_prefix(),
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
if self.request.method in ("POST", "PUT"):
|
| 47 |
+
kwargs.update(
|
| 48 |
+
{
|
| 49 |
+
"data": self.request.POST,
|
| 50 |
+
"files": self.request.FILES,
|
| 51 |
+
}
|
| 52 |
+
)
|
| 53 |
+
return kwargs
|
| 54 |
+
|
| 55 |
+
def get_success_url(self):
|
| 56 |
+
"""Return the URL to redirect to after processing a valid form."""
|
| 57 |
+
if not self.success_url:
|
| 58 |
+
raise ImproperlyConfigured("No URL to redirect to. Provide a success_url.")
|
| 59 |
+
return str(self.success_url) # success_url may be lazy
|
| 60 |
+
|
| 61 |
+
def form_valid(self, form):
|
| 62 |
+
"""If the form is valid, redirect to the supplied URL."""
|
| 63 |
+
return HttpResponseRedirect(self.get_success_url())
|
| 64 |
+
|
| 65 |
+
def form_invalid(self, form):
|
| 66 |
+
"""If the form is invalid, render the invalid form."""
|
| 67 |
+
return self.render_to_response(self.get_context_data(form=form))
|
| 68 |
+
|
| 69 |
+
def get_context_data(self, **kwargs):
|
| 70 |
+
"""Insert the form into the context dict."""
|
| 71 |
+
if "form" not in kwargs:
|
| 72 |
+
kwargs["form"] = self.get_form()
|
| 73 |
+
return super().get_context_data(**kwargs)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
class ModelFormMixin(FormMixin, SingleObjectMixin):
|
| 77 |
+
"""Provide a way to show and handle a ModelForm in a request."""
|
| 78 |
+
|
| 79 |
+
fields = None
|
| 80 |
+
|
| 81 |
+
def get_form_class(self):
|
| 82 |
+
"""Return the form class to use in this view."""
|
| 83 |
+
if self.fields is not None and self.form_class:
|
| 84 |
+
raise ImproperlyConfigured(
|
| 85 |
+
"Specifying both 'fields' and 'form_class' is not permitted."
|
| 86 |
+
)
|
| 87 |
+
if self.form_class:
|
| 88 |
+
return self.form_class
|
| 89 |
+
else:
|
| 90 |
+
if self.model is not None:
|
| 91 |
+
# If a model has been explicitly provided, use it
|
| 92 |
+
model = self.model
|
| 93 |
+
elif getattr(self, "object", None) is not None:
|
| 94 |
+
# If this view is operating on a single object, use
|
| 95 |
+
# the class of that object
|
| 96 |
+
model = self.object.__class__
|
| 97 |
+
else:
|
| 98 |
+
# Try to get a queryset and extract the model class
|
| 99 |
+
# from that
|
| 100 |
+
model = self.get_queryset().model
|
| 101 |
+
|
| 102 |
+
if self.fields is None:
|
| 103 |
+
raise ImproperlyConfigured(
|
| 104 |
+
"Using ModelFormMixin (base class of %s) without "
|
| 105 |
+
"the 'fields' attribute is prohibited." % self.__class__.__name__
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
return model_forms.modelform_factory(model, fields=self.fields)
|
| 109 |
+
|
| 110 |
+
def get_form_kwargs(self):
|
| 111 |
+
"""Return the keyword arguments for instantiating the form."""
|
| 112 |
+
kwargs = super().get_form_kwargs()
|
| 113 |
+
if hasattr(self, "object"):
|
| 114 |
+
kwargs.update({"instance": self.object})
|
| 115 |
+
return kwargs
|
| 116 |
+
|
| 117 |
+
def get_success_url(self):
|
| 118 |
+
"""Return the URL to redirect to after processing a valid form."""
|
| 119 |
+
if self.success_url:
|
| 120 |
+
url = self.success_url.format(**self.object.__dict__)
|
| 121 |
+
else:
|
| 122 |
+
try:
|
| 123 |
+
url = self.object.get_absolute_url()
|
| 124 |
+
except AttributeError:
|
| 125 |
+
raise ImproperlyConfigured(
|
| 126 |
+
"No URL to redirect to. Either provide a url or define"
|
| 127 |
+
" a get_absolute_url method on the Model."
|
| 128 |
+
)
|
| 129 |
+
return url
|
| 130 |
+
|
| 131 |
+
def form_valid(self, form):
|
| 132 |
+
"""If the form is valid, save the associated model."""
|
| 133 |
+
self.object = form.save()
|
| 134 |
+
return super().form_valid(form)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
class ProcessFormView(View):
|
| 138 |
+
"""Render a form on GET and processes it on POST."""
|
| 139 |
+
|
| 140 |
+
def get(self, request, *args, **kwargs):
|
| 141 |
+
"""Handle GET requests: instantiate a blank version of the form."""
|
| 142 |
+
return self.render_to_response(self.get_context_data())
|
| 143 |
+
|
| 144 |
+
def post(self, request, *args, **kwargs):
|
| 145 |
+
"""
|
| 146 |
+
Handle POST requests: instantiate a form instance with the passed
|
| 147 |
+
POST variables and then check if it's valid.
|
| 148 |
+
"""
|
| 149 |
+
form = self.get_form()
|
| 150 |
+
if form.is_valid():
|
| 151 |
+
return self.form_valid(form)
|
| 152 |
+
else:
|
| 153 |
+
return self.form_invalid(form)
|
| 154 |
+
|
| 155 |
+
# PUT is a valid HTTP verb for creating (with a known URL) or editing an
|
| 156 |
+
# object, note that browsers only support POST for now.
|
| 157 |
+
def put(self, *args, **kwargs):
|
| 158 |
+
return self.post(*args, **kwargs)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class BaseFormView(FormMixin, ProcessFormView):
|
| 162 |
+
"""A base view for displaying a form."""
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class FormView(TemplateResponseMixin, BaseFormView):
|
| 166 |
+
"""A view for displaying a form and rendering a template response."""
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
class BaseCreateView(ModelFormMixin, ProcessFormView):
|
| 170 |
+
"""
|
| 171 |
+
Base view for creating a new object instance.
|
| 172 |
+
|
| 173 |
+
Using this base class requires subclassing to provide a response mixin.
|
| 174 |
+
"""
|
| 175 |
+
|
| 176 |
+
def get(self, request, *args, **kwargs):
|
| 177 |
+
self.object = None
|
| 178 |
+
return super().get(request, *args, **kwargs)
|
| 179 |
+
|
| 180 |
+
def post(self, request, *args, **kwargs):
|
| 181 |
+
self.object = None
|
| 182 |
+
return super().post(request, *args, **kwargs)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
class CreateView(SingleObjectTemplateResponseMixin, BaseCreateView):
|
| 186 |
+
"""
|
| 187 |
+
View for creating a new object, with a response rendered by a template.
|
| 188 |
+
"""
|
| 189 |
+
|
| 190 |
+
template_name_suffix = "_form"
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
class BaseUpdateView(ModelFormMixin, ProcessFormView):
|
| 194 |
+
"""
|
| 195 |
+
Base view for updating an existing object.
|
| 196 |
+
|
| 197 |
+
Using this base class requires subclassing to provide a response mixin.
|
| 198 |
+
"""
|
| 199 |
+
|
| 200 |
+
def get(self, request, *args, **kwargs):
|
| 201 |
+
self.object = self.get_object()
|
| 202 |
+
return super().get(request, *args, **kwargs)
|
| 203 |
+
|
| 204 |
+
def post(self, request, *args, **kwargs):
|
| 205 |
+
self.object = self.get_object()
|
| 206 |
+
return super().post(request, *args, **kwargs)
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
class UpdateView(SingleObjectTemplateResponseMixin, BaseUpdateView):
|
| 210 |
+
"""View for updating an object, with a response rendered by a template."""
|
| 211 |
+
|
| 212 |
+
template_name_suffix = "_form"
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
class DeletionMixin:
|
| 216 |
+
"""Provide the ability to delete objects."""
|
| 217 |
+
|
| 218 |
+
success_url = None
|
| 219 |
+
|
| 220 |
+
def delete(self, request, *args, **kwargs):
|
| 221 |
+
"""
|
| 222 |
+
Call the delete() method on the fetched object and then redirect to the
|
| 223 |
+
success URL.
|
| 224 |
+
"""
|
| 225 |
+
self.object = self.get_object()
|
| 226 |
+
success_url = self.get_success_url()
|
| 227 |
+
self.object.delete()
|
| 228 |
+
return HttpResponseRedirect(success_url)
|
| 229 |
+
|
| 230 |
+
# Add support for browsers which only accept GET and POST for now.
|
| 231 |
+
def post(self, request, *args, **kwargs):
|
| 232 |
+
return self.delete(request, *args, **kwargs)
|
| 233 |
+
|
| 234 |
+
def get_success_url(self):
|
| 235 |
+
if self.success_url:
|
| 236 |
+
return self.success_url.format(**self.object.__dict__)
|
| 237 |
+
else:
|
| 238 |
+
raise ImproperlyConfigured("No URL to redirect to. Provide a success_url.")
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
class BaseDeleteView(DeletionMixin, FormMixin, BaseDetailView):
|
| 242 |
+
"""
|
| 243 |
+
Base view for deleting an object.
|
| 244 |
+
|
| 245 |
+
Using this base class requires subclassing to provide a response mixin.
|
| 246 |
+
"""
|
| 247 |
+
|
| 248 |
+
form_class = Form
|
| 249 |
+
|
| 250 |
+
def post(self, request, *args, **kwargs):
|
| 251 |
+
# Set self.object before the usual form processing flow.
|
| 252 |
+
# Inlined because having DeletionMixin as the first base, for
|
| 253 |
+
# get_success_url(), makes leveraging super() with ProcessFormView
|
| 254 |
+
# overly complex.
|
| 255 |
+
self.object = self.get_object()
|
| 256 |
+
form = self.get_form()
|
| 257 |
+
if form.is_valid():
|
| 258 |
+
return self.form_valid(form)
|
| 259 |
+
else:
|
| 260 |
+
return self.form_invalid(form)
|
| 261 |
+
|
| 262 |
+
def form_valid(self, form):
|
| 263 |
+
success_url = self.get_success_url()
|
| 264 |
+
self.object.delete()
|
| 265 |
+
return HttpResponseRedirect(success_url)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
class DeleteView(SingleObjectTemplateResponseMixin, BaseDeleteView):
|
| 269 |
+
"""
|
| 270 |
+
View for deleting an object retrieved with self.get_object(), with a
|
| 271 |
+
response rendered by a template.
|
| 272 |
+
"""
|
| 273 |
+
|
| 274 |
+
template_name_suffix = "_confirm_delete"
|
testbed/django__django/django/views/generic/list.py
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.core.exceptions import ImproperlyConfigured
|
| 2 |
+
from django.core.paginator import InvalidPage, Paginator
|
| 3 |
+
from django.db.models import QuerySet
|
| 4 |
+
from django.http import Http404
|
| 5 |
+
from django.utils.translation import gettext as _
|
| 6 |
+
from django.views.generic.base import ContextMixin, TemplateResponseMixin, View
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class MultipleObjectMixin(ContextMixin):
|
| 10 |
+
"""A mixin for views manipulating multiple objects."""
|
| 11 |
+
|
| 12 |
+
allow_empty = True
|
| 13 |
+
queryset = None
|
| 14 |
+
model = None
|
| 15 |
+
paginate_by = None
|
| 16 |
+
paginate_orphans = 0
|
| 17 |
+
context_object_name = None
|
| 18 |
+
paginator_class = Paginator
|
| 19 |
+
page_kwarg = "page"
|
| 20 |
+
ordering = None
|
| 21 |
+
|
| 22 |
+
def get_queryset(self):
|
| 23 |
+
"""
|
| 24 |
+
Return the list of items for this view.
|
| 25 |
+
|
| 26 |
+
The return value must be an iterable and may be an instance of
|
| 27 |
+
`QuerySet` in which case `QuerySet` specific behavior will be enabled.
|
| 28 |
+
"""
|
| 29 |
+
if self.queryset is not None:
|
| 30 |
+
queryset = self.queryset
|
| 31 |
+
if isinstance(queryset, QuerySet):
|
| 32 |
+
queryset = queryset.all()
|
| 33 |
+
elif self.model is not None:
|
| 34 |
+
queryset = self.model._default_manager.all()
|
| 35 |
+
else:
|
| 36 |
+
raise ImproperlyConfigured(
|
| 37 |
+
"%(cls)s is missing a QuerySet. Define "
|
| 38 |
+
"%(cls)s.model, %(cls)s.queryset, or override "
|
| 39 |
+
"%(cls)s.get_queryset()." % {"cls": self.__class__.__name__}
|
| 40 |
+
)
|
| 41 |
+
ordering = self.get_ordering()
|
| 42 |
+
if ordering:
|
| 43 |
+
if isinstance(ordering, str):
|
| 44 |
+
ordering = (ordering,)
|
| 45 |
+
queryset = queryset.order_by(*ordering)
|
| 46 |
+
|
| 47 |
+
return queryset
|
| 48 |
+
|
| 49 |
+
def get_ordering(self):
|
| 50 |
+
"""Return the field or fields to use for ordering the queryset."""
|
| 51 |
+
return self.ordering
|
| 52 |
+
|
| 53 |
+
def paginate_queryset(self, queryset, page_size):
|
| 54 |
+
"""Paginate the queryset, if needed."""
|
| 55 |
+
paginator = self.get_paginator(
|
| 56 |
+
queryset,
|
| 57 |
+
page_size,
|
| 58 |
+
orphans=self.get_paginate_orphans(),
|
| 59 |
+
allow_empty_first_page=self.get_allow_empty(),
|
| 60 |
+
)
|
| 61 |
+
page_kwarg = self.page_kwarg
|
| 62 |
+
page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1
|
| 63 |
+
try:
|
| 64 |
+
page_number = int(page)
|
| 65 |
+
except ValueError:
|
| 66 |
+
if page == "last":
|
| 67 |
+
page_number = paginator.num_pages
|
| 68 |
+
else:
|
| 69 |
+
raise Http404(
|
| 70 |
+
_("Page is not “last”, nor can it be converted to an int.")
|
| 71 |
+
)
|
| 72 |
+
try:
|
| 73 |
+
page = paginator.page(page_number)
|
| 74 |
+
return (paginator, page, page.object_list, page.has_other_pages())
|
| 75 |
+
except InvalidPage as e:
|
| 76 |
+
raise Http404(
|
| 77 |
+
_("Invalid page (%(page_number)s): %(message)s")
|
| 78 |
+
% {"page_number": page_number, "message": str(e)}
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
def get_paginate_by(self, queryset):
|
| 82 |
+
"""
|
| 83 |
+
Get the number of items to paginate by, or ``None`` for no pagination.
|
| 84 |
+
"""
|
| 85 |
+
return self.paginate_by
|
| 86 |
+
|
| 87 |
+
def get_paginator(
|
| 88 |
+
self, queryset, per_page, orphans=0, allow_empty_first_page=True, **kwargs
|
| 89 |
+
):
|
| 90 |
+
"""Return an instance of the paginator for this view."""
|
| 91 |
+
return self.paginator_class(
|
| 92 |
+
queryset,
|
| 93 |
+
per_page,
|
| 94 |
+
orphans=orphans,
|
| 95 |
+
allow_empty_first_page=allow_empty_first_page,
|
| 96 |
+
**kwargs,
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
def get_paginate_orphans(self):
|
| 100 |
+
"""
|
| 101 |
+
Return the maximum number of orphans extend the last page by when
|
| 102 |
+
paginating.
|
| 103 |
+
"""
|
| 104 |
+
return self.paginate_orphans
|
| 105 |
+
|
| 106 |
+
def get_allow_empty(self):
|
| 107 |
+
"""
|
| 108 |
+
Return ``True`` if the view should display empty lists and ``False``
|
| 109 |
+
if a 404 should be raised instead.
|
| 110 |
+
"""
|
| 111 |
+
return self.allow_empty
|
| 112 |
+
|
| 113 |
+
def get_context_object_name(self, object_list):
|
| 114 |
+
"""Get the name of the item to be used in the context."""
|
| 115 |
+
if self.context_object_name:
|
| 116 |
+
return self.context_object_name
|
| 117 |
+
elif hasattr(object_list, "model"):
|
| 118 |
+
return "%s_list" % object_list.model._meta.model_name
|
| 119 |
+
else:
|
| 120 |
+
return None
|
| 121 |
+
|
| 122 |
+
def get_context_data(self, *, object_list=None, **kwargs):
|
| 123 |
+
"""Get the context for this view."""
|
| 124 |
+
queryset = object_list if object_list is not None else self.object_list
|
| 125 |
+
page_size = self.get_paginate_by(queryset)
|
| 126 |
+
context_object_name = self.get_context_object_name(queryset)
|
| 127 |
+
if page_size:
|
| 128 |
+
paginator, page, queryset, is_paginated = self.paginate_queryset(
|
| 129 |
+
queryset, page_size
|
| 130 |
+
)
|
| 131 |
+
context = {
|
| 132 |
+
"paginator": paginator,
|
| 133 |
+
"page_obj": page,
|
| 134 |
+
"is_paginated": is_paginated,
|
| 135 |
+
"object_list": queryset,
|
| 136 |
+
}
|
| 137 |
+
else:
|
| 138 |
+
context = {
|
| 139 |
+
"paginator": None,
|
| 140 |
+
"page_obj": None,
|
| 141 |
+
"is_paginated": False,
|
| 142 |
+
"object_list": queryset,
|
| 143 |
+
}
|
| 144 |
+
if context_object_name is not None:
|
| 145 |
+
context[context_object_name] = queryset
|
| 146 |
+
context.update(kwargs)
|
| 147 |
+
return super().get_context_data(**context)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
class BaseListView(MultipleObjectMixin, View):
|
| 151 |
+
"""A base view for displaying a list of objects."""
|
| 152 |
+
|
| 153 |
+
def get(self, request, *args, **kwargs):
|
| 154 |
+
self.object_list = self.get_queryset()
|
| 155 |
+
allow_empty = self.get_allow_empty()
|
| 156 |
+
|
| 157 |
+
if not allow_empty:
|
| 158 |
+
# When pagination is enabled and object_list is a queryset,
|
| 159 |
+
# it's better to do a cheap query than to load the unpaginated
|
| 160 |
+
# queryset in memory.
|
| 161 |
+
if self.get_paginate_by(self.object_list) is not None and hasattr(
|
| 162 |
+
self.object_list, "exists"
|
| 163 |
+
):
|
| 164 |
+
is_empty = not self.object_list.exists()
|
| 165 |
+
else:
|
| 166 |
+
is_empty = not self.object_list
|
| 167 |
+
if is_empty:
|
| 168 |
+
raise Http404(
|
| 169 |
+
_("Empty list and “%(class_name)s.allow_empty” is False.")
|
| 170 |
+
% {
|
| 171 |
+
"class_name": self.__class__.__name__,
|
| 172 |
+
}
|
| 173 |
+
)
|
| 174 |
+
context = self.get_context_data()
|
| 175 |
+
return self.render_to_response(context)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
class MultipleObjectTemplateResponseMixin(TemplateResponseMixin):
|
| 179 |
+
"""Mixin for responding with a template and list of objects."""
|
| 180 |
+
|
| 181 |
+
template_name_suffix = "_list"
|
| 182 |
+
|
| 183 |
+
def get_template_names(self):
|
| 184 |
+
"""
|
| 185 |
+
Return a list of template names to be used for the request. Must return
|
| 186 |
+
a list. May not be called if render_to_response is overridden.
|
| 187 |
+
"""
|
| 188 |
+
try:
|
| 189 |
+
names = super().get_template_names()
|
| 190 |
+
except ImproperlyConfigured:
|
| 191 |
+
# If template_name isn't specified, it's not a problem --
|
| 192 |
+
# we just start with an empty list.
|
| 193 |
+
names = []
|
| 194 |
+
|
| 195 |
+
# If the list is a queryset, we'll invent a template name based on the
|
| 196 |
+
# app and model name. This name gets put at the end of the template
|
| 197 |
+
# name list so that user-supplied names override the automatically-
|
| 198 |
+
# generated ones.
|
| 199 |
+
if hasattr(self.object_list, "model"):
|
| 200 |
+
opts = self.object_list.model._meta
|
| 201 |
+
names.append(
|
| 202 |
+
"%s/%s%s.html"
|
| 203 |
+
% (opts.app_label, opts.model_name, self.template_name_suffix)
|
| 204 |
+
)
|
| 205 |
+
elif not names:
|
| 206 |
+
raise ImproperlyConfigured(
|
| 207 |
+
"%(cls)s requires either a 'template_name' attribute "
|
| 208 |
+
"or a get_queryset() method that returns a QuerySet."
|
| 209 |
+
% {
|
| 210 |
+
"cls": self.__class__.__name__,
|
| 211 |
+
}
|
| 212 |
+
)
|
| 213 |
+
return names
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
class ListView(MultipleObjectTemplateResponseMixin, BaseListView):
|
| 217 |
+
"""
|
| 218 |
+
Render some list of objects, set by `self.model` or `self.queryset`.
|
| 219 |
+
`self.queryset` can actually be any iterable of items, not just a queryset.
|
| 220 |
+
"""
|
testbed/django__django/django/views/i18n.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import re
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
from django.apps import apps
|
| 7 |
+
from django.conf import settings
|
| 8 |
+
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
|
| 9 |
+
from django.template import Context, Engine
|
| 10 |
+
from django.urls import translate_url
|
| 11 |
+
from django.utils.formats import get_format
|
| 12 |
+
from django.utils.http import url_has_allowed_host_and_scheme
|
| 13 |
+
from django.utils.translation import check_for_language, get_language
|
| 14 |
+
from django.utils.translation.trans_real import DjangoTranslation
|
| 15 |
+
from django.views.generic import View
|
| 16 |
+
|
| 17 |
+
LANGUAGE_QUERY_PARAMETER = "language"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def builtin_template_path(name):
|
| 21 |
+
"""
|
| 22 |
+
Return a path to a builtin template.
|
| 23 |
+
|
| 24 |
+
Avoid calling this function at the module level or in a class-definition
|
| 25 |
+
because __file__ may not exist, e.g. in frozen environments.
|
| 26 |
+
"""
|
| 27 |
+
return Path(__file__).parent / "templates" / name
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def set_language(request):
|
| 31 |
+
"""
|
| 32 |
+
Redirect to a given URL while setting the chosen language in the session
|
| 33 |
+
(if enabled) and in a cookie. The URL and the language code need to be
|
| 34 |
+
specified in the request parameters.
|
| 35 |
+
|
| 36 |
+
Since this view changes how the user will see the rest of the site, it must
|
| 37 |
+
only be accessed as a POST request. If called as a GET request, it will
|
| 38 |
+
redirect to the page in the request (the 'next' parameter) without changing
|
| 39 |
+
any state.
|
| 40 |
+
"""
|
| 41 |
+
next_url = request.POST.get("next", request.GET.get("next"))
|
| 42 |
+
if (
|
| 43 |
+
next_url or request.accepts("text/html")
|
| 44 |
+
) and not url_has_allowed_host_and_scheme(
|
| 45 |
+
url=next_url,
|
| 46 |
+
allowed_hosts={request.get_host()},
|
| 47 |
+
require_https=request.is_secure(),
|
| 48 |
+
):
|
| 49 |
+
next_url = request.META.get("HTTP_REFERER")
|
| 50 |
+
if not url_has_allowed_host_and_scheme(
|
| 51 |
+
url=next_url,
|
| 52 |
+
allowed_hosts={request.get_host()},
|
| 53 |
+
require_https=request.is_secure(),
|
| 54 |
+
):
|
| 55 |
+
next_url = "/"
|
| 56 |
+
response = HttpResponseRedirect(next_url) if next_url else HttpResponse(status=204)
|
| 57 |
+
if request.method == "POST":
|
| 58 |
+
lang_code = request.POST.get(LANGUAGE_QUERY_PARAMETER)
|
| 59 |
+
if lang_code and check_for_language(lang_code):
|
| 60 |
+
if next_url:
|
| 61 |
+
next_trans = translate_url(next_url, lang_code)
|
| 62 |
+
if next_trans != next_url:
|
| 63 |
+
response = HttpResponseRedirect(next_trans)
|
| 64 |
+
response.set_cookie(
|
| 65 |
+
settings.LANGUAGE_COOKIE_NAME,
|
| 66 |
+
lang_code,
|
| 67 |
+
max_age=settings.LANGUAGE_COOKIE_AGE,
|
| 68 |
+
path=settings.LANGUAGE_COOKIE_PATH,
|
| 69 |
+
domain=settings.LANGUAGE_COOKIE_DOMAIN,
|
| 70 |
+
secure=settings.LANGUAGE_COOKIE_SECURE,
|
| 71 |
+
httponly=settings.LANGUAGE_COOKIE_HTTPONLY,
|
| 72 |
+
samesite=settings.LANGUAGE_COOKIE_SAMESITE,
|
| 73 |
+
)
|
| 74 |
+
return response
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def get_formats():
|
| 78 |
+
"""Return all formats strings required for i18n to work."""
|
| 79 |
+
FORMAT_SETTINGS = (
|
| 80 |
+
"DATE_FORMAT",
|
| 81 |
+
"DATETIME_FORMAT",
|
| 82 |
+
"TIME_FORMAT",
|
| 83 |
+
"YEAR_MONTH_FORMAT",
|
| 84 |
+
"MONTH_DAY_FORMAT",
|
| 85 |
+
"SHORT_DATE_FORMAT",
|
| 86 |
+
"SHORT_DATETIME_FORMAT",
|
| 87 |
+
"FIRST_DAY_OF_WEEK",
|
| 88 |
+
"DECIMAL_SEPARATOR",
|
| 89 |
+
"THOUSAND_SEPARATOR",
|
| 90 |
+
"NUMBER_GROUPING",
|
| 91 |
+
"DATE_INPUT_FORMATS",
|
| 92 |
+
"TIME_INPUT_FORMATS",
|
| 93 |
+
"DATETIME_INPUT_FORMATS",
|
| 94 |
+
)
|
| 95 |
+
return {attr: get_format(attr) for attr in FORMAT_SETTINGS}
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class JavaScriptCatalog(View):
|
| 99 |
+
"""
|
| 100 |
+
Return the selected language catalog as a JavaScript library.
|
| 101 |
+
|
| 102 |
+
Receive the list of packages to check for translations in the `packages`
|
| 103 |
+
kwarg either from the extra dictionary passed to the path() function or as
|
| 104 |
+
a plus-sign delimited string from the request. Default is 'django.conf'.
|
| 105 |
+
|
| 106 |
+
You can override the gettext domain for this view, but usually you don't
|
| 107 |
+
want to do that as JavaScript messages go to the djangojs domain. This
|
| 108 |
+
might be needed if you deliver your JavaScript source from Django templates.
|
| 109 |
+
"""
|
| 110 |
+
|
| 111 |
+
domain = "djangojs"
|
| 112 |
+
packages = None
|
| 113 |
+
|
| 114 |
+
def get(self, request, *args, **kwargs):
|
| 115 |
+
locale = get_language()
|
| 116 |
+
domain = kwargs.get("domain", self.domain)
|
| 117 |
+
# If packages are not provided, default to all installed packages, as
|
| 118 |
+
# DjangoTranslation without localedirs harvests them all.
|
| 119 |
+
packages = kwargs.get("packages", "")
|
| 120 |
+
packages = packages.split("+") if packages else self.packages
|
| 121 |
+
paths = self.get_paths(packages) if packages else None
|
| 122 |
+
self.translation = DjangoTranslation(locale, domain=domain, localedirs=paths)
|
| 123 |
+
context = self.get_context_data(**kwargs)
|
| 124 |
+
return self.render_to_response(context)
|
| 125 |
+
|
| 126 |
+
def get_paths(self, packages):
|
| 127 |
+
allowable_packages = {
|
| 128 |
+
app_config.name: app_config for app_config in apps.get_app_configs()
|
| 129 |
+
}
|
| 130 |
+
app_configs = [
|
| 131 |
+
allowable_packages[p] for p in packages if p in allowable_packages
|
| 132 |
+
]
|
| 133 |
+
if len(app_configs) < len(packages):
|
| 134 |
+
excluded = [p for p in packages if p not in allowable_packages]
|
| 135 |
+
raise ValueError(
|
| 136 |
+
"Invalid package(s) provided to JavaScriptCatalog: %s"
|
| 137 |
+
% ",".join(excluded)
|
| 138 |
+
)
|
| 139 |
+
# paths of requested packages
|
| 140 |
+
return [os.path.join(app.path, "locale") for app in app_configs]
|
| 141 |
+
|
| 142 |
+
@property
|
| 143 |
+
def _num_plurals(self):
|
| 144 |
+
"""
|
| 145 |
+
Return the number of plurals for this catalog language, or 2 if no
|
| 146 |
+
plural string is available.
|
| 147 |
+
"""
|
| 148 |
+
match = re.search(r"nplurals=\s*(\d+)", self._plural_string or "")
|
| 149 |
+
if match:
|
| 150 |
+
return int(match[1])
|
| 151 |
+
return 2
|
| 152 |
+
|
| 153 |
+
@property
|
| 154 |
+
def _plural_string(self):
|
| 155 |
+
"""
|
| 156 |
+
Return the plural string (including nplurals) for this catalog language,
|
| 157 |
+
or None if no plural string is available.
|
| 158 |
+
"""
|
| 159 |
+
if "" in self.translation._catalog:
|
| 160 |
+
for line in self.translation._catalog[""].split("\n"):
|
| 161 |
+
if line.startswith("Plural-Forms:"):
|
| 162 |
+
return line.split(":", 1)[1].strip()
|
| 163 |
+
return None
|
| 164 |
+
|
| 165 |
+
def get_plural(self):
|
| 166 |
+
plural = self._plural_string
|
| 167 |
+
if plural is not None:
|
| 168 |
+
# This should be a compiled function of a typical plural-form:
|
| 169 |
+
# Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 :
|
| 170 |
+
# n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
|
| 171 |
+
plural = [
|
| 172 |
+
el.strip()
|
| 173 |
+
for el in plural.split(";")
|
| 174 |
+
if el.strip().startswith("plural=")
|
| 175 |
+
][0].split("=", 1)[1]
|
| 176 |
+
return plural
|
| 177 |
+
|
| 178 |
+
def get_catalog(self):
|
| 179 |
+
pdict = {}
|
| 180 |
+
catalog = {}
|
| 181 |
+
translation = self.translation
|
| 182 |
+
seen_keys = set()
|
| 183 |
+
while True:
|
| 184 |
+
for key, value in translation._catalog.items():
|
| 185 |
+
if key == "" or key in seen_keys:
|
| 186 |
+
continue
|
| 187 |
+
if isinstance(key, str):
|
| 188 |
+
catalog[key] = value
|
| 189 |
+
elif isinstance(key, tuple):
|
| 190 |
+
msgid, cnt = key
|
| 191 |
+
pdict.setdefault(msgid, {})[cnt] = value
|
| 192 |
+
else:
|
| 193 |
+
raise TypeError(key)
|
| 194 |
+
seen_keys.add(key)
|
| 195 |
+
if translation._fallback:
|
| 196 |
+
translation = translation._fallback
|
| 197 |
+
else:
|
| 198 |
+
break
|
| 199 |
+
|
| 200 |
+
num_plurals = self._num_plurals
|
| 201 |
+
for k, v in pdict.items():
|
| 202 |
+
catalog[k] = [v.get(i, "") for i in range(num_plurals)]
|
| 203 |
+
return catalog
|
| 204 |
+
|
| 205 |
+
def get_context_data(self, **kwargs):
|
| 206 |
+
return {
|
| 207 |
+
"catalog": self.get_catalog(),
|
| 208 |
+
"formats": get_formats(),
|
| 209 |
+
"plural": self.get_plural(),
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
def render_to_response(self, context, **response_kwargs):
|
| 213 |
+
def indent(s):
|
| 214 |
+
return s.replace("\n", "\n ")
|
| 215 |
+
|
| 216 |
+
with builtin_template_path("i18n_catalog.js").open(encoding="utf-8") as fh:
|
| 217 |
+
template = Engine().from_string(fh.read())
|
| 218 |
+
context["catalog_str"] = (
|
| 219 |
+
indent(json.dumps(context["catalog"], sort_keys=True, indent=2))
|
| 220 |
+
if context["catalog"]
|
| 221 |
+
else None
|
| 222 |
+
)
|
| 223 |
+
context["formats_str"] = indent(
|
| 224 |
+
json.dumps(context["formats"], sort_keys=True, indent=2)
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
return HttpResponse(
|
| 228 |
+
template.render(Context(context)), 'text/javascript; charset="utf-8"'
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
class JSONCatalog(JavaScriptCatalog):
|
| 233 |
+
"""
|
| 234 |
+
Return the selected language catalog as a JSON object.
|
| 235 |
+
|
| 236 |
+
Receive the same parameters as JavaScriptCatalog and return a response
|
| 237 |
+
with a JSON object of the following format:
|
| 238 |
+
|
| 239 |
+
{
|
| 240 |
+
"catalog": {
|
| 241 |
+
# Translations catalog
|
| 242 |
+
},
|
| 243 |
+
"formats": {
|
| 244 |
+
# Language formats for date, time, etc.
|
| 245 |
+
},
|
| 246 |
+
"plural": '...' # Expression for plural forms, or null.
|
| 247 |
+
}
|
| 248 |
+
"""
|
| 249 |
+
|
| 250 |
+
def render_to_response(self, context, **response_kwargs):
|
| 251 |
+
return JsonResponse(context)
|
testbed/django__django/django/views/static.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Views and functions for serving static files. These are only to be used
|
| 3 |
+
during development, and SHOULD NOT be used in a production setting.
|
| 4 |
+
"""
|
| 5 |
+
import mimetypes
|
| 6 |
+
import posixpath
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
from django.http import FileResponse, Http404, HttpResponse, HttpResponseNotModified
|
| 10 |
+
from django.template import Context, Engine, TemplateDoesNotExist, loader
|
| 11 |
+
from django.utils._os import safe_join
|
| 12 |
+
from django.utils.http import http_date, parse_http_date
|
| 13 |
+
from django.utils.translation import gettext as _
|
| 14 |
+
from django.utils.translation import gettext_lazy
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def builtin_template_path(name):
|
| 18 |
+
"""
|
| 19 |
+
Return a path to a builtin template.
|
| 20 |
+
|
| 21 |
+
Avoid calling this function at the module level or in a class-definition
|
| 22 |
+
because __file__ may not exist, e.g. in frozen environments.
|
| 23 |
+
"""
|
| 24 |
+
return Path(__file__).parent / "templates" / name
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def serve(request, path, document_root=None, show_indexes=False):
|
| 28 |
+
"""
|
| 29 |
+
Serve static files below a given point in the directory structure.
|
| 30 |
+
|
| 31 |
+
To use, put a URL pattern such as::
|
| 32 |
+
|
| 33 |
+
from django.views.static import serve
|
| 34 |
+
|
| 35 |
+
path('<path:path>', serve, {'document_root': '/path/to/my/files/'})
|
| 36 |
+
|
| 37 |
+
in your URLconf. You must provide the ``document_root`` param. You may
|
| 38 |
+
also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
|
| 39 |
+
of the directory. This index view will use the template hardcoded below,
|
| 40 |
+
but if you'd like to override it, you can create a template called
|
| 41 |
+
``static/directory_index.html``.
|
| 42 |
+
"""
|
| 43 |
+
path = posixpath.normpath(path).lstrip("/")
|
| 44 |
+
fullpath = Path(safe_join(document_root, path))
|
| 45 |
+
if fullpath.is_dir():
|
| 46 |
+
if show_indexes:
|
| 47 |
+
return directory_index(path, fullpath)
|
| 48 |
+
raise Http404(_("Directory indexes are not allowed here."))
|
| 49 |
+
if not fullpath.exists():
|
| 50 |
+
raise Http404(_("“%(path)s” does not exist") % {"path": fullpath})
|
| 51 |
+
# Respect the If-Modified-Since header.
|
| 52 |
+
statobj = fullpath.stat()
|
| 53 |
+
if not was_modified_since(
|
| 54 |
+
request.META.get("HTTP_IF_MODIFIED_SINCE"), statobj.st_mtime
|
| 55 |
+
):
|
| 56 |
+
return HttpResponseNotModified()
|
| 57 |
+
content_type, encoding = mimetypes.guess_type(str(fullpath))
|
| 58 |
+
content_type = content_type or "application/octet-stream"
|
| 59 |
+
response = FileResponse(fullpath.open("rb"), content_type=content_type)
|
| 60 |
+
response.headers["Last-Modified"] = http_date(statobj.st_mtime)
|
| 61 |
+
if encoding:
|
| 62 |
+
response.headers["Content-Encoding"] = encoding
|
| 63 |
+
return response
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# Translatable string for static directory index template title.
|
| 67 |
+
template_translatable = gettext_lazy("Index of %(directory)s")
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def directory_index(path, fullpath):
|
| 71 |
+
try:
|
| 72 |
+
t = loader.select_template(
|
| 73 |
+
[
|
| 74 |
+
"static/directory_index.html",
|
| 75 |
+
"static/directory_index",
|
| 76 |
+
]
|
| 77 |
+
)
|
| 78 |
+
except TemplateDoesNotExist:
|
| 79 |
+
with builtin_template_path("directory_index.html").open(encoding="utf-8") as fh:
|
| 80 |
+
t = Engine(libraries={"i18n": "django.templatetags.i18n"}).from_string(
|
| 81 |
+
fh.read()
|
| 82 |
+
)
|
| 83 |
+
c = Context()
|
| 84 |
+
else:
|
| 85 |
+
c = {}
|
| 86 |
+
files = []
|
| 87 |
+
for f in fullpath.iterdir():
|
| 88 |
+
if not f.name.startswith("."):
|
| 89 |
+
url = str(f.relative_to(fullpath))
|
| 90 |
+
if f.is_dir():
|
| 91 |
+
url += "/"
|
| 92 |
+
files.append(url)
|
| 93 |
+
c.update(
|
| 94 |
+
{
|
| 95 |
+
"directory": path + "/",
|
| 96 |
+
"file_list": files,
|
| 97 |
+
}
|
| 98 |
+
)
|
| 99 |
+
return HttpResponse(t.render(c))
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def was_modified_since(header=None, mtime=0):
|
| 103 |
+
"""
|
| 104 |
+
Was something modified since the user last downloaded it?
|
| 105 |
+
|
| 106 |
+
header
|
| 107 |
+
This is the value of the If-Modified-Since header. If this is None,
|
| 108 |
+
I'll just return True.
|
| 109 |
+
|
| 110 |
+
mtime
|
| 111 |
+
This is the modification time of the item we're talking about.
|
| 112 |
+
"""
|
| 113 |
+
try:
|
| 114 |
+
if header is None:
|
| 115 |
+
raise ValueError
|
| 116 |
+
header_mtime = parse_http_date(header)
|
| 117 |
+
if int(mtime) > header_mtime:
|
| 118 |
+
raise ValueError
|
| 119 |
+
except (ValueError, OverflowError):
|
| 120 |
+
return True
|
| 121 |
+
return False
|
testbed/django__django/django/views/templates/csrf_403.html
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
| 5 |
+
<meta name="robots" content="NONE,NOARCHIVE">
|
| 6 |
+
<title>403 Forbidden</title>
|
| 7 |
+
<style type="text/css">
|
| 8 |
+
html * { padding:0; margin:0; }
|
| 9 |
+
body * { padding:10px 20px; }
|
| 10 |
+
body * * { padding:0; }
|
| 11 |
+
body { font:small sans-serif; background:#eee; color:#000; }
|
| 12 |
+
body>div { border-bottom:1px solid #ddd; }
|
| 13 |
+
h1 { font-weight:normal; margin-bottom:.4em; }
|
| 14 |
+
h1 span { font-size:60%; color:#666; font-weight:normal; }
|
| 15 |
+
#info { background:#f6f6f6; }
|
| 16 |
+
#info ul { margin: 0.5em 4em; }
|
| 17 |
+
#info p, #summary p { padding-top:10px; }
|
| 18 |
+
#summary { background: #ffc; }
|
| 19 |
+
#explanation { background:#eee; border-bottom: 0px none; }
|
| 20 |
+
</style>
|
| 21 |
+
</head>
|
| 22 |
+
<body>
|
| 23 |
+
<div id="summary">
|
| 24 |
+
<h1>{{ title }} <span>(403)</span></h1>
|
| 25 |
+
<p>{{ main }}</p>
|
| 26 |
+
{% if no_referer %}
|
| 27 |
+
<p>{{ no_referer1 }}</p>
|
| 28 |
+
<p>{{ no_referer2 }}</p>
|
| 29 |
+
<p>{{ no_referer3 }}</p>
|
| 30 |
+
{% endif %}
|
| 31 |
+
{% if no_cookie %}
|
| 32 |
+
<p>{{ no_cookie1 }}</p>
|
| 33 |
+
<p>{{ no_cookie2 }}</p>
|
| 34 |
+
{% endif %}
|
| 35 |
+
</div>
|
| 36 |
+
{% if DEBUG %}
|
| 37 |
+
<div id="info">
|
| 38 |
+
<h2>Help</h2>
|
| 39 |
+
{% if reason %}
|
| 40 |
+
<p>Reason given for failure:</p>
|
| 41 |
+
<pre>
|
| 42 |
+
{{ reason }}
|
| 43 |
+
</pre>
|
| 44 |
+
{% endif %}
|
| 45 |
+
|
| 46 |
+
<p>In general, this can occur when there is a genuine Cross Site Request Forgery, or when
|
| 47 |
+
<a
|
| 48 |
+
href="https://docs.djangoproject.com/en/{{ docs_version }}/ref/csrf/">Django’s
|
| 49 |
+
CSRF mechanism</a> has not been used correctly. For POST forms, you need to
|
| 50 |
+
ensure:</p>
|
| 51 |
+
|
| 52 |
+
<ul>
|
| 53 |
+
<li>Your browser is accepting cookies.</li>
|
| 54 |
+
|
| 55 |
+
<li>The view function passes a <code>request</code> to the template’s <a
|
| 56 |
+
href="https://docs.djangoproject.com/en/dev/topics/templates/#django.template.backends.base.Template.render"><code>render</code></a>
|
| 57 |
+
method.</li>
|
| 58 |
+
|
| 59 |
+
<li>In the template, there is a <code>{% templatetag openblock %} csrf_token
|
| 60 |
+
{% templatetag closeblock %}</code> template tag inside each POST form that
|
| 61 |
+
targets an internal URL.</li>
|
| 62 |
+
|
| 63 |
+
<li>If you are not using <code>CsrfViewMiddleware</code>, then you must use
|
| 64 |
+
<code>csrf_protect</code> on any views that use the <code>csrf_token</code>
|
| 65 |
+
template tag, as well as those that accept the POST data.</li>
|
| 66 |
+
|
| 67 |
+
<li>The form has a valid CSRF token. After logging in in another browser
|
| 68 |
+
tab or hitting the back button after a login, you may need to reload the
|
| 69 |
+
page with the form, because the token is rotated after a login.</li>
|
| 70 |
+
</ul>
|
| 71 |
+
|
| 72 |
+
<p>You’re seeing the help section of this page because you have <code>DEBUG =
|
| 73 |
+
True</code> in your Django settings file. Change that to <code>False</code>,
|
| 74 |
+
and only the initial error message will be displayed. </p>
|
| 75 |
+
|
| 76 |
+
<p>You can customize this page using the CSRF_FAILURE_VIEW setting.</p>
|
| 77 |
+
</div>
|
| 78 |
+
{% else %}
|
| 79 |
+
<div id="explanation">
|
| 80 |
+
<p><small>{{ more }}</small></p>
|
| 81 |
+
</div>
|
| 82 |
+
{% endif %}
|
| 83 |
+
</body>
|
| 84 |
+
</html>
|
testbed/django__django/django/views/templates/directory_index.html
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% load i18n %}
|
| 2 |
+
<!DOCTYPE html>
|
| 3 |
+
<html lang="en">
|
| 4 |
+
<head>
|
| 5 |
+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
| 6 |
+
<meta http-equiv="Content-Language" content="en-us">
|
| 7 |
+
<meta name="robots" content="NONE,NOARCHIVE">
|
| 8 |
+
<title>{% blocktranslate %}Index of {{ directory }}{% endblocktranslate %}</title>
|
| 9 |
+
</head>
|
| 10 |
+
<body>
|
| 11 |
+
<h1>{% blocktranslate %}Index of {{ directory }}{% endblocktranslate %}</h1>
|
| 12 |
+
<ul>
|
| 13 |
+
{% if directory != "/" %}
|
| 14 |
+
<li><a href="../">../</a></li>
|
| 15 |
+
{% endif %}
|
| 16 |
+
{% for f in file_list %}
|
| 17 |
+
<li><a href="{{ f|urlencode }}">{{ f }}</a></li>
|
| 18 |
+
{% endfor %}
|
| 19 |
+
</ul>
|
| 20 |
+
</body>
|
| 21 |
+
</html>
|
testbed/django__django/django/views/templates/technical_404.html
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
| 5 |
+
<title>Page not found at {{ request.path_info }}</title>
|
| 6 |
+
<meta name="robots" content="NONE,NOARCHIVE">
|
| 7 |
+
<style type="text/css">
|
| 8 |
+
html * { padding:0; margin:0; }
|
| 9 |
+
body * { padding:10px 20px; }
|
| 10 |
+
body * * { padding:0; }
|
| 11 |
+
body { font:small sans-serif; background:#eee; color:#000; }
|
| 12 |
+
body>div { border-bottom:1px solid #ddd; }
|
| 13 |
+
h1 { font-weight:normal; margin-bottom:.4em; }
|
| 14 |
+
h1 span { font-size:60%; color:#666; font-weight:normal; }
|
| 15 |
+
table { border:none; border-collapse: collapse; width:100%; }
|
| 16 |
+
td, th { vertical-align:top; padding:2px 3px; }
|
| 17 |
+
th { width:12em; text-align:right; color:#666; padding-right:.5em; }
|
| 18 |
+
#info { background:#f6f6f6; }
|
| 19 |
+
#info ol { margin: 0.5em 4em; }
|
| 20 |
+
#info ol li { font-family: monospace; }
|
| 21 |
+
#summary { background: #ffc; }
|
| 22 |
+
#explanation { background:#eee; border-bottom: 0px none; }
|
| 23 |
+
pre.exception_value { font-family: sans-serif; color: #575757; font-size: 1.5em; margin: 10px 0 10px 0; }
|
| 24 |
+
</style>
|
| 25 |
+
</head>
|
| 26 |
+
<body>
|
| 27 |
+
<div id="summary">
|
| 28 |
+
<h1>Page not found <span>(404)</span></h1>
|
| 29 |
+
{% if reason and resolved %}<pre class="exception_value">{{ reason }}</pre>{% endif %}
|
| 30 |
+
<table class="meta">
|
| 31 |
+
<tr>
|
| 32 |
+
<th>Request Method:</th>
|
| 33 |
+
<td>{{ request.META.REQUEST_METHOD }}</td>
|
| 34 |
+
</tr>
|
| 35 |
+
<tr>
|
| 36 |
+
<th>Request URL:</th>
|
| 37 |
+
<td>{{ request.build_absolute_uri }}</td>
|
| 38 |
+
</tr>
|
| 39 |
+
{% if raising_view_name %}
|
| 40 |
+
<tr>
|
| 41 |
+
<th>Raised by:</th>
|
| 42 |
+
<td>{{ raising_view_name }}</td>
|
| 43 |
+
</tr>
|
| 44 |
+
{% endif %}
|
| 45 |
+
</table>
|
| 46 |
+
</div>
|
| 47 |
+
<div id="info">
|
| 48 |
+
{% if urlpatterns %}
|
| 49 |
+
<p>
|
| 50 |
+
Using the URLconf defined in <code>{{ urlconf }}</code>,
|
| 51 |
+
Django tried these URL patterns, in this order:
|
| 52 |
+
</p>
|
| 53 |
+
<ol>
|
| 54 |
+
{% for pattern in urlpatterns %}
|
| 55 |
+
<li>
|
| 56 |
+
{% for pat in pattern %}
|
| 57 |
+
{{ pat.pattern }}
|
| 58 |
+
{% if forloop.last and pat.name %}[name='{{ pat.name }}']{% endif %}
|
| 59 |
+
{% endfor %}
|
| 60 |
+
</li>
|
| 61 |
+
{% endfor %}
|
| 62 |
+
</ol>
|
| 63 |
+
<p>
|
| 64 |
+
{% if request_path %}
|
| 65 |
+
The current path, <code>{{ request_path }}</code>,
|
| 66 |
+
{% else %}
|
| 67 |
+
The empty path
|
| 68 |
+
{% endif %}
|
| 69 |
+
{% if resolved %}matched the last one.{% else %}didn’t match any of these.{% endif %}
|
| 70 |
+
</p>
|
| 71 |
+
{% endif %}
|
| 72 |
+
</div>
|
| 73 |
+
|
| 74 |
+
<div id="explanation">
|
| 75 |
+
<p>
|
| 76 |
+
You’re seeing this error because you have <code>DEBUG = True</code> in
|
| 77 |
+
your Django settings file. Change that to <code>False</code>, and Django
|
| 78 |
+
will display a standard 404 page.
|
| 79 |
+
</p>
|
| 80 |
+
</div>
|
| 81 |
+
</body>
|
| 82 |
+
</html>
|
testbed/django__django/django/views/templates/technical_500.html
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
| 5 |
+
<meta name="robots" content="NONE,NOARCHIVE">
|
| 6 |
+
<title>{% if exception_type %}{{ exception_type }}{% else %}Report{% endif %}
|
| 7 |
+
{% if request %} at {{ request.path_info }}{% endif %}</title>
|
| 8 |
+
<style type="text/css">
|
| 9 |
+
html * { padding:0; margin:0; }
|
| 10 |
+
body * { padding:10px 20px; }
|
| 11 |
+
body * * { padding:0; }
|
| 12 |
+
body { font:small sans-serif; background-color:#fff; color:#000; }
|
| 13 |
+
body>div { border-bottom:1px solid #ddd; }
|
| 14 |
+
h1 { font-weight:normal; }
|
| 15 |
+
h2 { margin-bottom:.8em; }
|
| 16 |
+
h3 { margin:1em 0 .5em 0; }
|
| 17 |
+
h4 { margin:0 0 .5em 0; font-weight: normal; }
|
| 18 |
+
code, pre { font-size: 100%; white-space: pre-wrap; word-break: break-word; }
|
| 19 |
+
summary { cursor: pointer; }
|
| 20 |
+
table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
|
| 21 |
+
tbody td, tbody th { vertical-align:top; padding:2px 3px; }
|
| 22 |
+
thead th {
|
| 23 |
+
padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
|
| 24 |
+
font-weight:normal; font-size:11px; border:1px solid #ddd;
|
| 25 |
+
}
|
| 26 |
+
tbody th { width:12em; text-align:right; color:#666; padding-right:.5em; }
|
| 27 |
+
table.vars { margin:5px 10px 2px 40px; width: auto; }
|
| 28 |
+
table.vars td, table.req td { font-family:monospace; }
|
| 29 |
+
table td.code { width:100%; }
|
| 30 |
+
table td.code pre { overflow:hidden; }
|
| 31 |
+
table.source th { color:#666; }
|
| 32 |
+
table.source td { font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
|
| 33 |
+
ul.traceback { list-style-type:none; color: #222; }
|
| 34 |
+
ul.traceback li.cause { word-break: break-word; }
|
| 35 |
+
ul.traceback li.frame { padding-bottom:1em; color:#4f4f4f; }
|
| 36 |
+
ul.traceback li.user { background-color:#e0e0e0; color:#000 }
|
| 37 |
+
div.context { padding:10px 0; overflow:hidden; }
|
| 38 |
+
div.context ol { padding-left:30px; margin:0 10px; list-style-position: inside; }
|
| 39 |
+
div.context ol li { font-family:monospace; white-space:pre; color:#777; cursor:pointer; padding-left: 2px; }
|
| 40 |
+
div.context ol li pre { display:inline; }
|
| 41 |
+
div.context ol.context-line li { color:#464646; background-color:#dfdfdf; padding: 3px 2px; }
|
| 42 |
+
div.context ol.context-line li span { position:absolute; right:32px; }
|
| 43 |
+
.user div.context ol.context-line li { background-color:#bbb; color:#000; }
|
| 44 |
+
.user div.context ol li { color:#666; }
|
| 45 |
+
div.commands, summary.commands { margin-left: 40px; }
|
| 46 |
+
div.commands a, summary.commands { color:#555; text-decoration:none; }
|
| 47 |
+
.user div.commands a { color: black; }
|
| 48 |
+
#summary { background: #ffc; }
|
| 49 |
+
#summary h2 { font-weight: normal; color: #666; }
|
| 50 |
+
#explanation { background:#eee; }
|
| 51 |
+
#template, #template-not-exist { background:#f6f6f6; }
|
| 52 |
+
#template-not-exist ul { margin: 0 0 10px 20px; }
|
| 53 |
+
#template-not-exist .postmortem-section { margin-bottom: 3px; }
|
| 54 |
+
#unicode-hint { background:#eee; }
|
| 55 |
+
#traceback { background:#eee; }
|
| 56 |
+
#requestinfo { background:#f6f6f6; padding-left:120px; }
|
| 57 |
+
#summary table { border:none; background:transparent; }
|
| 58 |
+
#requestinfo h2, #requestinfo h3 { position:relative; margin-left:-100px; }
|
| 59 |
+
#requestinfo h3 { margin-bottom:-1em; }
|
| 60 |
+
.error { background: #ffc; }
|
| 61 |
+
.specific { color:#cc3300; font-weight:bold; }
|
| 62 |
+
h2 span.commands { font-size:.7em; font-weight:normal; }
|
| 63 |
+
span.commands a:link {color:#5E5694;}
|
| 64 |
+
pre.exception_value { font-family: sans-serif; color: #575757; font-size: 1.5em; margin: 10px 0 10px 0; }
|
| 65 |
+
.append-bottom { margin-bottom: 10px; }
|
| 66 |
+
.fname { user-select: all; }
|
| 67 |
+
</style>
|
| 68 |
+
{% if not is_email %}
|
| 69 |
+
<script>
|
| 70 |
+
function hideAll(elems) {
|
| 71 |
+
for (var e = 0; e < elems.length; e++) {
|
| 72 |
+
elems[e].style.display = 'none';
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
window.onload = function() {
|
| 76 |
+
hideAll(document.querySelectorAll('ol.pre-context'));
|
| 77 |
+
hideAll(document.querySelectorAll('ol.post-context'));
|
| 78 |
+
hideAll(document.querySelectorAll('div.pastebin'));
|
| 79 |
+
}
|
| 80 |
+
function toggle() {
|
| 81 |
+
for (var i = 0; i < arguments.length; i++) {
|
| 82 |
+
var e = document.getElementById(arguments[i]);
|
| 83 |
+
if (e) {
|
| 84 |
+
e.style.display = e.style.display == 'none' ? 'block': 'none';
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
return false;
|
| 88 |
+
}
|
| 89 |
+
function switchPastebinFriendly(link) {
|
| 90 |
+
s1 = "Switch to copy-and-paste view";
|
| 91 |
+
s2 = "Switch back to interactive view";
|
| 92 |
+
link.textContent = link.textContent.trim() == s1 ? s2: s1;
|
| 93 |
+
toggle('browserTraceback', 'pastebinTraceback');
|
| 94 |
+
return false;
|
| 95 |
+
}
|
| 96 |
+
</script>
|
| 97 |
+
{% endif %}
|
| 98 |
+
</head>
|
| 99 |
+
<body>
|
| 100 |
+
<div id="summary">
|
| 101 |
+
<h1>{% if exception_type %}{{ exception_type }}{% else %}Report{% endif %}
|
| 102 |
+
{% if request %} at {{ request.path_info }}{% endif %}</h1>
|
| 103 |
+
<pre class="exception_value">{% if exception_value %}{{ exception_value|force_escape }}{% if exception_notes %}{{ exception_notes }}{% endif %}{% else %}No exception message supplied{% endif %}</pre>
|
| 104 |
+
<table class="meta">
|
| 105 |
+
{% if request %}
|
| 106 |
+
<tr>
|
| 107 |
+
<th>Request Method:</th>
|
| 108 |
+
<td>{{ request.META.REQUEST_METHOD }}</td>
|
| 109 |
+
</tr>
|
| 110 |
+
<tr>
|
| 111 |
+
<th>Request URL:</th>
|
| 112 |
+
<td>{{ request_insecure_uri }}</td>
|
| 113 |
+
</tr>
|
| 114 |
+
{% endif %}
|
| 115 |
+
<tr>
|
| 116 |
+
<th>Django Version:</th>
|
| 117 |
+
<td>{{ django_version_info }}</td>
|
| 118 |
+
</tr>
|
| 119 |
+
{% if exception_type %}
|
| 120 |
+
<tr>
|
| 121 |
+
<th>Exception Type:</th>
|
| 122 |
+
<td>{{ exception_type }}</td>
|
| 123 |
+
</tr>
|
| 124 |
+
{% endif %}
|
| 125 |
+
{% if exception_type and exception_value %}
|
| 126 |
+
<tr>
|
| 127 |
+
<th>Exception Value:</th>
|
| 128 |
+
<td><pre>{{ exception_value|force_escape }}</pre></td>
|
| 129 |
+
</tr>
|
| 130 |
+
{% endif %}
|
| 131 |
+
{% if lastframe %}
|
| 132 |
+
<tr>
|
| 133 |
+
<th>Exception Location:</th>
|
| 134 |
+
<td><span class="fname">{{ lastframe.filename }}</span>, line {{ lastframe.lineno }}, in {{ lastframe.function }}</td>
|
| 135 |
+
</tr>
|
| 136 |
+
{% endif %}
|
| 137 |
+
{% if raising_view_name %}
|
| 138 |
+
<tr>
|
| 139 |
+
<th>Raised during:</th>
|
| 140 |
+
<td>{{ raising_view_name }}</td>
|
| 141 |
+
</tr>
|
| 142 |
+
{% endif %}
|
| 143 |
+
<tr>
|
| 144 |
+
<th>Python Executable:</th>
|
| 145 |
+
<td>{{ sys_executable }}</td>
|
| 146 |
+
</tr>
|
| 147 |
+
<tr>
|
| 148 |
+
<th>Python Version:</th>
|
| 149 |
+
<td>{{ sys_version_info }}</td>
|
| 150 |
+
</tr>
|
| 151 |
+
<tr>
|
| 152 |
+
<th>Python Path:</th>
|
| 153 |
+
<td><pre>{{ sys_path|pprint }}</pre></td>
|
| 154 |
+
</tr>
|
| 155 |
+
<tr>
|
| 156 |
+
<th>Server time:</th>
|
| 157 |
+
<td>{{server_time|date:"r"}}</td>
|
| 158 |
+
</tr>
|
| 159 |
+
</table>
|
| 160 |
+
</div>
|
| 161 |
+
{% if unicode_hint %}
|
| 162 |
+
<div id="unicode-hint">
|
| 163 |
+
<h2>Unicode error hint</h2>
|
| 164 |
+
<p>The string that could not be encoded/decoded was: <strong>{{ unicode_hint }}</strong></p>
|
| 165 |
+
</div>
|
| 166 |
+
{% endif %}
|
| 167 |
+
{% if template_does_not_exist %}
|
| 168 |
+
<div id="template-not-exist">
|
| 169 |
+
<h2>Template-loader postmortem</h2>
|
| 170 |
+
{% if postmortem %}
|
| 171 |
+
<p class="append-bottom">Django tried loading these templates, in this order:</p>
|
| 172 |
+
{% for entry in postmortem %}
|
| 173 |
+
<p class="postmortem-section">Using engine <code>{{ entry.backend.name }}</code>:</p>
|
| 174 |
+
<ul>
|
| 175 |
+
{% if entry.tried %}
|
| 176 |
+
{% for attempt in entry.tried %}
|
| 177 |
+
<li><code>{{ attempt.0.loader_name }}</code>: {{ attempt.0.name }} ({{ attempt.1 }})</li>
|
| 178 |
+
{% endfor %}
|
| 179 |
+
{% else %}
|
| 180 |
+
<li>This engine did not provide a list of tried templates.</li>
|
| 181 |
+
{% endif %}
|
| 182 |
+
</ul>
|
| 183 |
+
{% endfor %}
|
| 184 |
+
{% else %}
|
| 185 |
+
<p>No templates were found because your 'TEMPLATES' setting is not configured.</p>
|
| 186 |
+
{% endif %}
|
| 187 |
+
</div>
|
| 188 |
+
{% endif %}
|
| 189 |
+
{% if template_info %}
|
| 190 |
+
<div id="template">
|
| 191 |
+
<h2>Error during template rendering</h2>
|
| 192 |
+
<p>In template <code>{{ template_info.name }}</code>, error at line <strong>{{ template_info.line }}</strong></p>
|
| 193 |
+
<h3>{{ template_info.message|force_escape }}</h3>
|
| 194 |
+
<table class="source{% if template_info.top %} cut-top{% endif %}
|
| 195 |
+
{% if template_info.bottom != template_info.total %} cut-bottom{% endif %}">
|
| 196 |
+
{% for source_line in template_info.source_lines %}
|
| 197 |
+
{% if source_line.0 == template_info.line %}
|
| 198 |
+
<tr class="error"><th>{{ source_line.0 }}</th>
|
| 199 |
+
<td>{{ template_info.before }}<span class="specific">{{ template_info.during }}</span>{{ template_info.after }}</td>
|
| 200 |
+
</tr>
|
| 201 |
+
{% else %}
|
| 202 |
+
<tr><th>{{ source_line.0 }}</th>
|
| 203 |
+
<td>{{ source_line.1 }}</td></tr>
|
| 204 |
+
{% endif %}
|
| 205 |
+
{% endfor %}
|
| 206 |
+
</table>
|
| 207 |
+
</div>
|
| 208 |
+
{% endif %}
|
| 209 |
+
{% if frames %}
|
| 210 |
+
<div id="traceback">
|
| 211 |
+
<h2>Traceback{% if not is_email %} <span class="commands"><a href="#" onclick="return switchPastebinFriendly(this);">
|
| 212 |
+
Switch to copy-and-paste view</a></span>{% endif %}
|
| 213 |
+
</h2>
|
| 214 |
+
<div id="browserTraceback">
|
| 215 |
+
<ul class="traceback">
|
| 216 |
+
{% for frame in frames %}
|
| 217 |
+
{% ifchanged frame.exc_cause %}{% if frame.exc_cause %}
|
| 218 |
+
<li class="cause"><h3>
|
| 219 |
+
{% if frame.exc_cause_explicit %}
|
| 220 |
+
The above exception ({{ frame.exc_cause|force_escape }}) was the direct cause of the following exception:
|
| 221 |
+
{% else %}
|
| 222 |
+
During handling of the above exception ({{ frame.exc_cause|force_escape }}), another exception occurred:
|
| 223 |
+
{% endif %}
|
| 224 |
+
</h3></li>
|
| 225 |
+
{% endif %}{% endifchanged %}
|
| 226 |
+
<li class="frame {{ frame.type }}">
|
| 227 |
+
{% if frame.tb %}
|
| 228 |
+
<code class="fname">{{ frame.filename }}</code>, line {{ frame.lineno }}, in {{ frame.function }}
|
| 229 |
+
{% elif forloop.first %}
|
| 230 |
+
None
|
| 231 |
+
{% else %}
|
| 232 |
+
Traceback: None
|
| 233 |
+
{% endif %}
|
| 234 |
+
|
| 235 |
+
{% if frame.context_line %}
|
| 236 |
+
<div class="context" id="c{{ frame.id }}">
|
| 237 |
+
{% if frame.pre_context and not is_email %}
|
| 238 |
+
<ol start="{{ frame.pre_context_lineno }}" class="pre-context" id="pre{{ frame.id }}">
|
| 239 |
+
{% for line in frame.pre_context %}
|
| 240 |
+
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ line }}</pre></li>
|
| 241 |
+
{% endfor %}
|
| 242 |
+
</ol>
|
| 243 |
+
{% endif %}
|
| 244 |
+
<ol start="{{ frame.lineno }}" class="context-line">
|
| 245 |
+
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ frame.context_line }}{{ frame.colno }}</pre>{% if not is_email %} <span>…</span>{% endif %}</li>
|
| 246 |
+
</ol>
|
| 247 |
+
{% if frame.post_context and not is_email %}
|
| 248 |
+
<ol start='{{ frame.lineno|add:"1" }}' class="post-context" id="post{{ frame.id }}">
|
| 249 |
+
{% for line in frame.post_context %}
|
| 250 |
+
<li onclick="toggle('pre{{ frame.id }}', 'post{{ frame.id }}')"><pre>{{ line }}</pre></li>
|
| 251 |
+
{% endfor %}
|
| 252 |
+
</ol>
|
| 253 |
+
{% endif %}
|
| 254 |
+
</div>
|
| 255 |
+
{% endif %}
|
| 256 |
+
|
| 257 |
+
{% if frame.vars %}
|
| 258 |
+
{% if is_email %}
|
| 259 |
+
<div class="commands">
|
| 260 |
+
<h2>Local Vars</h2>
|
| 261 |
+
</div>
|
| 262 |
+
{% else %}
|
| 263 |
+
<details>
|
| 264 |
+
<summary class="commands">Local vars</summary>
|
| 265 |
+
{% endif %}
|
| 266 |
+
<table class="vars" id="v{{ frame.id }}">
|
| 267 |
+
<thead>
|
| 268 |
+
<tr>
|
| 269 |
+
<th>Variable</th>
|
| 270 |
+
<th>Value</th>
|
| 271 |
+
</tr>
|
| 272 |
+
</thead>
|
| 273 |
+
<tbody>
|
| 274 |
+
{% for var in frame.vars|dictsort:0 %}
|
| 275 |
+
<tr>
|
| 276 |
+
<td>{{ var.0 }}</td>
|
| 277 |
+
<td class="code"><pre>{{ var.1 }}</pre></td>
|
| 278 |
+
</tr>
|
| 279 |
+
{% endfor %}
|
| 280 |
+
</tbody>
|
| 281 |
+
</table>
|
| 282 |
+
{% if not is_email %}</details>{% endif %}
|
| 283 |
+
{% endif %}
|
| 284 |
+
</li>
|
| 285 |
+
{% endfor %}
|
| 286 |
+
</ul>
|
| 287 |
+
</div>
|
| 288 |
+
{% if not is_email %}
|
| 289 |
+
<form action="https://dpaste.com/" name="pasteform" id="pasteform" method="post">
|
| 290 |
+
<div id="pastebinTraceback" class="pastebin">
|
| 291 |
+
<input type="hidden" name="language" value="PythonConsole">
|
| 292 |
+
<input type="hidden" name="title"
|
| 293 |
+
value="{{ exception_type }}{% if request %} at {{ request.path_info }}{% endif %}">
|
| 294 |
+
<input type="hidden" name="source" value="Django Dpaste Agent">
|
| 295 |
+
<input type="hidden" name="poster" value="Django">
|
| 296 |
+
<textarea name="content" id="traceback_area" cols="140" rows="25">
|
| 297 |
+
Environment:
|
| 298 |
+
|
| 299 |
+
{% if request %}
|
| 300 |
+
Request Method: {{ request.META.REQUEST_METHOD }}
|
| 301 |
+
Request URL: {{ request_insecure_uri }}
|
| 302 |
+
{% endif %}
|
| 303 |
+
Django Version: {{ django_version_info }}
|
| 304 |
+
Python Version: {{ sys_version_info }}
|
| 305 |
+
Installed Applications:
|
| 306 |
+
{{ settings.INSTALLED_APPS|pprint }}
|
| 307 |
+
Installed Middleware:
|
| 308 |
+
{{ settings.MIDDLEWARE|pprint }}
|
| 309 |
+
|
| 310 |
+
{% if template_does_not_exist %}Template loader postmortem
|
| 311 |
+
{% if postmortem %}Django tried loading these templates, in this order:
|
| 312 |
+
{% for entry in postmortem %}
|
| 313 |
+
Using engine {{ entry.backend.name }}:
|
| 314 |
+
{% if entry.tried %}{% for attempt in entry.tried %} * {{ attempt.0.loader_name }}: {{ attempt.0.name }} ({{ attempt.1 }})
|
| 315 |
+
{% endfor %}{% else %} This engine did not provide a list of tried templates.
|
| 316 |
+
{% endif %}{% endfor %}
|
| 317 |
+
{% else %}No templates were found because your 'TEMPLATES' setting is not configured.
|
| 318 |
+
{% endif %}{% endif %}{% if template_info %}
|
| 319 |
+
Template error:
|
| 320 |
+
In template {{ template_info.name }}, error at line {{ template_info.line }}
|
| 321 |
+
{{ template_info.message|force_escape }}
|
| 322 |
+
{% for source_line in template_info.source_lines %}{% if source_line.0 == template_info.line %} {{ source_line.0 }} : {{ template_info.before }} {{ template_info.during }} {{ template_info.after }}{% else %} {{ source_line.0 }} : {{ source_line.1 }}{% endif %}{% endfor %}{% endif %}
|
| 323 |
+
|
| 324 |
+
Traceback (most recent call last):{% for frame in frames %}
|
| 325 |
+
{% ifchanged frame.exc_cause %}{% if frame.exc_cause %}{% if frame.exc_cause_explicit %}
|
| 326 |
+
The above exception ({{ frame.exc_cause|force_escape }}) was the direct cause of the following exception:
|
| 327 |
+
{% else %}
|
| 328 |
+
During handling of the above exception ({{ frame.exc_cause|force_escape }}), another exception occurred:
|
| 329 |
+
{% endif %}{% endif %}{% endifchanged %} {% if frame.tb %}File "{{ frame.filename }}"{% if frame.context_line %}, line {{ frame.lineno }}{% endif %}, in {{ frame.function }}
|
| 330 |
+
{% if frame.context_line %} {% spaceless %}{{ frame.context_line }}{% endspaceless %}{{ frame.tb_area_colno }}{% endif %}{% elif forloop.first %}None{% else %}Traceback: None{% endif %}{% endfor %}
|
| 331 |
+
|
| 332 |
+
Exception Type: {{ exception_type }}{% if request %} at {{ request.path_info }}{% endif %}
|
| 333 |
+
Exception Value: {{ exception_value|force_escape }}{% if exception_notes %}{{ exception_notes }}{% endif %}
|
| 334 |
+
</textarea>
|
| 335 |
+
<br><br>
|
| 336 |
+
<input type="submit" value="Share this traceback on a public website">
|
| 337 |
+
</div>
|
| 338 |
+
</form>
|
| 339 |
+
{% endif %}
|
| 340 |
+
</div>
|
| 341 |
+
{% endif %}
|
| 342 |
+
|
| 343 |
+
<div id="requestinfo">
|
| 344 |
+
<h2>Request information</h2>
|
| 345 |
+
|
| 346 |
+
{% if request %}
|
| 347 |
+
{% if user_str %}
|
| 348 |
+
<h3 id="user-info">USER</h3>
|
| 349 |
+
<p>{{ user_str }}</p>
|
| 350 |
+
{% endif %}
|
| 351 |
+
|
| 352 |
+
<h3 id="get-info">GET</h3>
|
| 353 |
+
{% if request.GET %}
|
| 354 |
+
<table class="req">
|
| 355 |
+
<thead>
|
| 356 |
+
<tr>
|
| 357 |
+
<th>Variable</th>
|
| 358 |
+
<th>Value</th>
|
| 359 |
+
</tr>
|
| 360 |
+
</thead>
|
| 361 |
+
<tbody>
|
| 362 |
+
{% for k, v in request_GET_items %}
|
| 363 |
+
<tr>
|
| 364 |
+
<td>{{ k }}</td>
|
| 365 |
+
<td class="code"><pre>{{ v|pprint }}</pre></td>
|
| 366 |
+
</tr>
|
| 367 |
+
{% endfor %}
|
| 368 |
+
</tbody>
|
| 369 |
+
</table>
|
| 370 |
+
{% else %}
|
| 371 |
+
<p>No GET data</p>
|
| 372 |
+
{% endif %}
|
| 373 |
+
|
| 374 |
+
<h3 id="post-info">POST</h3>
|
| 375 |
+
{% if filtered_POST_items %}
|
| 376 |
+
<table class="req">
|
| 377 |
+
<thead>
|
| 378 |
+
<tr>
|
| 379 |
+
<th>Variable</th>
|
| 380 |
+
<th>Value</th>
|
| 381 |
+
</tr>
|
| 382 |
+
</thead>
|
| 383 |
+
<tbody>
|
| 384 |
+
{% for k, v in filtered_POST_items %}
|
| 385 |
+
<tr>
|
| 386 |
+
<td>{{ k }}</td>
|
| 387 |
+
<td class="code"><pre>{{ v|pprint }}</pre></td>
|
| 388 |
+
</tr>
|
| 389 |
+
{% endfor %}
|
| 390 |
+
</tbody>
|
| 391 |
+
</table>
|
| 392 |
+
{% else %}
|
| 393 |
+
<p>No POST data</p>
|
| 394 |
+
{% endif %}
|
| 395 |
+
|
| 396 |
+
<h3 id="files-info">FILES</h3>
|
| 397 |
+
{% if request.FILES %}
|
| 398 |
+
<table class="req">
|
| 399 |
+
<thead>
|
| 400 |
+
<tr>
|
| 401 |
+
<th>Variable</th>
|
| 402 |
+
<th>Value</th>
|
| 403 |
+
</tr>
|
| 404 |
+
</thead>
|
| 405 |
+
<tbody>
|
| 406 |
+
{% for k, v in request_FILES_items %}
|
| 407 |
+
<tr>
|
| 408 |
+
<td>{{ k }}</td>
|
| 409 |
+
<td class="code"><pre>{{ v|pprint }}</pre></td>
|
| 410 |
+
</tr>
|
| 411 |
+
{% endfor %}
|
| 412 |
+
</tbody>
|
| 413 |
+
</table>
|
| 414 |
+
{% else %}
|
| 415 |
+
<p>No FILES data</p>
|
| 416 |
+
{% endif %}
|
| 417 |
+
|
| 418 |
+
<h3 id="cookie-info">COOKIES</h3>
|
| 419 |
+
{% if request.COOKIES %}
|
| 420 |
+
<table class="req">
|
| 421 |
+
<thead>
|
| 422 |
+
<tr>
|
| 423 |
+
<th>Variable</th>
|
| 424 |
+
<th>Value</th>
|
| 425 |
+
</tr>
|
| 426 |
+
</thead>
|
| 427 |
+
<tbody>
|
| 428 |
+
{% for k, v in request_COOKIES_items %}
|
| 429 |
+
<tr>
|
| 430 |
+
<td>{{ k }}</td>
|
| 431 |
+
<td class="code"><pre>{{ v|pprint }}</pre></td>
|
| 432 |
+
</tr>
|
| 433 |
+
{% endfor %}
|
| 434 |
+
</tbody>
|
| 435 |
+
</table>
|
| 436 |
+
{% else %}
|
| 437 |
+
<p>No cookie data</p>
|
| 438 |
+
{% endif %}
|
| 439 |
+
|
| 440 |
+
<h3 id="meta-info">META</h3>
|
| 441 |
+
<table class="req">
|
| 442 |
+
<thead>
|
| 443 |
+
<tr>
|
| 444 |
+
<th>Variable</th>
|
| 445 |
+
<th>Value</th>
|
| 446 |
+
</tr>
|
| 447 |
+
</thead>
|
| 448 |
+
<tbody>
|
| 449 |
+
{% for k, v in request_meta.items|dictsort:0 %}
|
| 450 |
+
<tr>
|
| 451 |
+
<td>{{ k }}</td>
|
| 452 |
+
<td class="code"><pre>{{ v|pprint }}</pre></td>
|
| 453 |
+
</tr>
|
| 454 |
+
{% endfor %}
|
| 455 |
+
</tbody>
|
| 456 |
+
</table>
|
| 457 |
+
{% else %}
|
| 458 |
+
<p>Request data not supplied</p>
|
| 459 |
+
{% endif %}
|
| 460 |
+
|
| 461 |
+
<h3 id="settings-info">Settings</h3>
|
| 462 |
+
<h4>Using settings module <code>{{ settings.SETTINGS_MODULE }}</code></h4>
|
| 463 |
+
<table class="req">
|
| 464 |
+
<thead>
|
| 465 |
+
<tr>
|
| 466 |
+
<th>Setting</th>
|
| 467 |
+
<th>Value</th>
|
| 468 |
+
</tr>
|
| 469 |
+
</thead>
|
| 470 |
+
<tbody>
|
| 471 |
+
{% for k, v in settings.items|dictsort:0 %}
|
| 472 |
+
<tr>
|
| 473 |
+
<td>{{ k }}</td>
|
| 474 |
+
<td class="code"><pre>{{ v|pprint }}</pre></td>
|
| 475 |
+
</tr>
|
| 476 |
+
{% endfor %}
|
| 477 |
+
</tbody>
|
| 478 |
+
</table>
|
| 479 |
+
|
| 480 |
+
</div>
|
| 481 |
+
{% if not is_email %}
|
| 482 |
+
<div id="explanation">
|
| 483 |
+
<p>
|
| 484 |
+
You’re seeing this error because you have <code>DEBUG = True</code> in your
|
| 485 |
+
Django settings file. Change that to <code>False</code>, and Django will
|
| 486 |
+
display a standard page generated by the handler for this status code.
|
| 487 |
+
</p>
|
| 488 |
+
</div>
|
| 489 |
+
{% endif %}
|
| 490 |
+
</body>
|
| 491 |
+
</html>
|
testbed/django__django/django/views/templates/technical_500.txt
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% firstof exception_type 'Report' %}{% if request %} at {{ request.path_info }}{% endif %}
|
| 2 |
+
{% firstof exception_value 'No exception message supplied' %}
|
| 3 |
+
{% if request %}
|
| 4 |
+
Request Method: {{ request.META.REQUEST_METHOD }}
|
| 5 |
+
Request URL: {{ request_insecure_uri }}{% endif %}
|
| 6 |
+
Django Version: {{ django_version_info }}
|
| 7 |
+
Python Executable: {{ sys_executable }}
|
| 8 |
+
Python Version: {{ sys_version_info }}
|
| 9 |
+
Python Path: {{ sys_path }}
|
| 10 |
+
Server time: {{server_time|date:"r"}}
|
| 11 |
+
Installed Applications:
|
| 12 |
+
{{ settings.INSTALLED_APPS|pprint }}
|
| 13 |
+
Installed Middleware:
|
| 14 |
+
{{ settings.MIDDLEWARE|pprint }}
|
| 15 |
+
{% if template_does_not_exist %}Template loader postmortem
|
| 16 |
+
{% if postmortem %}Django tried loading these templates, in this order:
|
| 17 |
+
{% for entry in postmortem %}
|
| 18 |
+
Using engine {{ entry.backend.name }}:
|
| 19 |
+
{% if entry.tried %}{% for attempt in entry.tried %} * {{ attempt.0.loader_name }}: {{ attempt.0.name }} ({{ attempt.1 }})
|
| 20 |
+
{% endfor %}{% else %} This engine did not provide a list of tried templates.
|
| 21 |
+
{% endif %}{% endfor %}
|
| 22 |
+
{% else %}No templates were found because your 'TEMPLATES' setting is not configured.
|
| 23 |
+
{% endif %}
|
| 24 |
+
{% endif %}{% if template_info %}
|
| 25 |
+
Template error:
|
| 26 |
+
In template {{ template_info.name }}, error at line {{ template_info.line }}
|
| 27 |
+
{{ template_info.message }}
|
| 28 |
+
{% for source_line in template_info.source_lines %}{% if source_line.0 == template_info.line %} {{ source_line.0 }} : {{ template_info.before }} {{ template_info.during }} {{ template_info.after }}{% else %} {{ source_line.0 }} : {{ source_line.1 }}{% endif %}{% endfor %}{% endif %}{% if frames %}
|
| 29 |
+
|
| 30 |
+
Traceback (most recent call last):
|
| 31 |
+
{% for frame in frames %}{% ifchanged frame.exc_cause %}{% if frame.exc_cause %}
|
| 32 |
+
{% if frame.exc_cause_explicit %}The above exception ({{ frame.exc_cause }}) was the direct cause of the following exception:{% else %}During handling of the above exception ({{ frame.exc_cause }}), another exception occurred:{% endif %}
|
| 33 |
+
{% endif %}{% endifchanged %} {% if frame.tb %}File "{{ frame.filename }}"{% if frame.context_line %}, line {{ frame.lineno }}{% endif %}, in {{ frame.function }}
|
| 34 |
+
{% if frame.context_line %} {% spaceless %}{{ frame.context_line }}{% endspaceless %}{{ frame.tb_area_colno }}{% endif %}{% elif forloop.first %}None{% else %}Traceback: None{% endif %}
|
| 35 |
+
{% endfor %}
|
| 36 |
+
{% if exception_type %}Exception Type: {{ exception_type }}{% if request %} at {{ request.path_info }}{% endif %}
|
| 37 |
+
{% if exception_value %}Exception Value: {{ exception_value }}{% endif %}{% if exception_notes %}{{ exception_notes }}{% endif %}{% endif %}{% endif %}
|
| 38 |
+
{% if raising_view_name %}Raised during: {{ raising_view_name }}{% endif %}
|
| 39 |
+
{% if request %}Request information:
|
| 40 |
+
{% if user_str %}USER: {{ user_str }}{% endif %}
|
| 41 |
+
|
| 42 |
+
GET:{% for k, v in request_GET_items %}
|
| 43 |
+
{{ k }} = {{ v|stringformat:"r" }}{% empty %} No GET data{% endfor %}
|
| 44 |
+
|
| 45 |
+
POST:{% for k, v in filtered_POST_items %}
|
| 46 |
+
{{ k }} = {{ v|stringformat:"r" }}{% empty %} No POST data{% endfor %}
|
| 47 |
+
|
| 48 |
+
FILES:{% for k, v in request_FILES_items %}
|
| 49 |
+
{{ k }} = {{ v|stringformat:"r" }}{% empty %} No FILES data{% endfor %}
|
| 50 |
+
|
| 51 |
+
COOKIES:{% for k, v in request_COOKIES_items %}
|
| 52 |
+
{{ k }} = {{ v|stringformat:"r" }}{% empty %} No cookie data{% endfor %}
|
| 53 |
+
|
| 54 |
+
META:{% for k, v in request_meta.items|dictsort:0 %}
|
| 55 |
+
{{ k }} = {{ v|stringformat:"r" }}{% endfor %}
|
| 56 |
+
{% else %}Request data not supplied
|
| 57 |
+
{% endif %}
|
| 58 |
+
Settings:
|
| 59 |
+
Using settings module {{ settings.SETTINGS_MODULE }}{% for k, v in settings.items|dictsort:0 %}
|
| 60 |
+
{{ k }} = {{ v|stringformat:"r" }}{% endfor %}
|
| 61 |
+
|
| 62 |
+
{% if not is_email %}
|
| 63 |
+
You’re seeing this error because you have DEBUG = True in your
|
| 64 |
+
Django settings file. Change that to False, and Django will
|
| 65 |
+
display a standard page generated by the handler for this status code.
|
| 66 |
+
{% endif %}
|
testbed/django__django/docs/_ext/djangodocs.py
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Sphinx plugins for Django documentation.
|
| 3 |
+
"""
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
from docutils import nodes
|
| 9 |
+
from docutils.parsers.rst import Directive
|
| 10 |
+
from docutils.statemachine import ViewList
|
| 11 |
+
from sphinx import addnodes
|
| 12 |
+
from sphinx.builders.html import StandaloneHTMLBuilder
|
| 13 |
+
from sphinx.directives.code import CodeBlock
|
| 14 |
+
from sphinx.domains.std import Cmdoption
|
| 15 |
+
from sphinx.errors import ExtensionError
|
| 16 |
+
from sphinx.util import logging
|
| 17 |
+
from sphinx.util.console import bold
|
| 18 |
+
from sphinx.writers.html import HTMLTranslator
|
| 19 |
+
|
| 20 |
+
logger = logging.getLogger(__name__)
|
| 21 |
+
# RE for option descriptions without a '--' prefix
|
| 22 |
+
simple_option_desc_re = re.compile(r"([-_a-zA-Z0-9]+)(\s*.*?)(?=,\s+(?:/|-|--)|$)")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def setup(app):
|
| 26 |
+
app.add_crossref_type(
|
| 27 |
+
directivename="setting",
|
| 28 |
+
rolename="setting",
|
| 29 |
+
indextemplate="pair: %s; setting",
|
| 30 |
+
)
|
| 31 |
+
app.add_crossref_type(
|
| 32 |
+
directivename="templatetag",
|
| 33 |
+
rolename="ttag",
|
| 34 |
+
indextemplate="pair: %s; template tag",
|
| 35 |
+
)
|
| 36 |
+
app.add_crossref_type(
|
| 37 |
+
directivename="templatefilter",
|
| 38 |
+
rolename="tfilter",
|
| 39 |
+
indextemplate="pair: %s; template filter",
|
| 40 |
+
)
|
| 41 |
+
app.add_crossref_type(
|
| 42 |
+
directivename="fieldlookup",
|
| 43 |
+
rolename="lookup",
|
| 44 |
+
indextemplate="pair: %s; field lookup type",
|
| 45 |
+
)
|
| 46 |
+
app.add_object_type(
|
| 47 |
+
directivename="django-admin",
|
| 48 |
+
rolename="djadmin",
|
| 49 |
+
indextemplate="pair: %s; django-admin command",
|
| 50 |
+
parse_node=parse_django_admin_node,
|
| 51 |
+
)
|
| 52 |
+
app.add_directive("django-admin-option", Cmdoption)
|
| 53 |
+
app.add_config_value("django_next_version", "0.0", True)
|
| 54 |
+
app.add_directive("versionadded", VersionDirective)
|
| 55 |
+
app.add_directive("versionchanged", VersionDirective)
|
| 56 |
+
app.add_builder(DjangoStandaloneHTMLBuilder)
|
| 57 |
+
app.set_translator("djangohtml", DjangoHTMLTranslator)
|
| 58 |
+
app.set_translator("json", DjangoHTMLTranslator)
|
| 59 |
+
app.add_node(
|
| 60 |
+
ConsoleNode,
|
| 61 |
+
html=(visit_console_html, None),
|
| 62 |
+
latex=(visit_console_dummy, depart_console_dummy),
|
| 63 |
+
man=(visit_console_dummy, depart_console_dummy),
|
| 64 |
+
text=(visit_console_dummy, depart_console_dummy),
|
| 65 |
+
texinfo=(visit_console_dummy, depart_console_dummy),
|
| 66 |
+
)
|
| 67 |
+
app.add_directive("console", ConsoleDirective)
|
| 68 |
+
app.connect("html-page-context", html_page_context_hook)
|
| 69 |
+
app.add_role("default-role-error", default_role_error)
|
| 70 |
+
return {"parallel_read_safe": True}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class VersionDirective(Directive):
|
| 74 |
+
has_content = True
|
| 75 |
+
required_arguments = 1
|
| 76 |
+
optional_arguments = 1
|
| 77 |
+
final_argument_whitespace = True
|
| 78 |
+
option_spec = {}
|
| 79 |
+
|
| 80 |
+
def run(self):
|
| 81 |
+
if len(self.arguments) > 1:
|
| 82 |
+
msg = """Only one argument accepted for directive '{directive_name}::'.
|
| 83 |
+
Comments should be provided as content,
|
| 84 |
+
not as an extra argument.""".format(
|
| 85 |
+
directive_name=self.name
|
| 86 |
+
)
|
| 87 |
+
raise self.error(msg)
|
| 88 |
+
|
| 89 |
+
env = self.state.document.settings.env
|
| 90 |
+
ret = []
|
| 91 |
+
node = addnodes.versionmodified()
|
| 92 |
+
ret.append(node)
|
| 93 |
+
|
| 94 |
+
if self.arguments[0] == env.config.django_next_version:
|
| 95 |
+
node["version"] = "Development version"
|
| 96 |
+
else:
|
| 97 |
+
node["version"] = self.arguments[0]
|
| 98 |
+
|
| 99 |
+
node["type"] = self.name
|
| 100 |
+
if self.content:
|
| 101 |
+
self.state.nested_parse(self.content, self.content_offset, node)
|
| 102 |
+
try:
|
| 103 |
+
env.get_domain("changeset").note_changeset(node)
|
| 104 |
+
except ExtensionError:
|
| 105 |
+
# Sphinx < 1.8: Domain 'changeset' is not registered
|
| 106 |
+
env.note_versionchange(node["type"], node["version"], node, self.lineno)
|
| 107 |
+
return ret
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
class DjangoHTMLTranslator(HTMLTranslator):
|
| 111 |
+
"""
|
| 112 |
+
Django-specific reST to HTML tweaks.
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
# Don't use border=1, which docutils does by default.
|
| 116 |
+
def visit_table(self, node):
|
| 117 |
+
self.context.append(self.compact_p)
|
| 118 |
+
self.compact_p = True
|
| 119 |
+
# Needed by Sphinx.
|
| 120 |
+
self._table_row_indices.append(0)
|
| 121 |
+
self.body.append(self.starttag(node, "table", CLASS="docutils"))
|
| 122 |
+
|
| 123 |
+
def depart_table(self, node):
|
| 124 |
+
self.compact_p = self.context.pop()
|
| 125 |
+
self._table_row_indices.pop()
|
| 126 |
+
self.body.append("</table>\n")
|
| 127 |
+
|
| 128 |
+
def visit_desc_parameterlist(self, node):
|
| 129 |
+
self.body.append("(") # by default sphinx puts <big> around the "("
|
| 130 |
+
self.first_param = 1
|
| 131 |
+
self.optional_param_level = 0
|
| 132 |
+
self.param_separator = node.child_text_separator
|
| 133 |
+
self.required_params_left = sum(
|
| 134 |
+
isinstance(c, addnodes.desc_parameter) for c in node.children
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
def depart_desc_parameterlist(self, node):
|
| 138 |
+
self.body.append(")")
|
| 139 |
+
|
| 140 |
+
#
|
| 141 |
+
# Turn the "new in version" stuff (versionadded/versionchanged) into a
|
| 142 |
+
# better callout -- the Sphinx default is just a little span,
|
| 143 |
+
# which is a bit less obvious that I'd like.
|
| 144 |
+
#
|
| 145 |
+
# FIXME: these messages are all hardcoded in English. We need to change
|
| 146 |
+
# that to accommodate other language docs, but I can't work out how to make
|
| 147 |
+
# that work.
|
| 148 |
+
#
|
| 149 |
+
version_text = {
|
| 150 |
+
"versionchanged": "Changed in Django %s",
|
| 151 |
+
"versionadded": "New in Django %s",
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
def visit_versionmodified(self, node):
|
| 155 |
+
self.body.append(self.starttag(node, "div", CLASS=node["type"]))
|
| 156 |
+
version_text = self.version_text.get(node["type"])
|
| 157 |
+
if version_text:
|
| 158 |
+
title = "%s%s" % (version_text % node["version"], ":" if len(node) else ".")
|
| 159 |
+
self.body.append('<span class="title">%s</span> ' % title)
|
| 160 |
+
|
| 161 |
+
def depart_versionmodified(self, node):
|
| 162 |
+
self.body.append("</div>\n")
|
| 163 |
+
|
| 164 |
+
# Give each section a unique ID -- nice for custom CSS hooks
|
| 165 |
+
def visit_section(self, node):
|
| 166 |
+
old_ids = node.get("ids", [])
|
| 167 |
+
node["ids"] = ["s-" + i for i in old_ids]
|
| 168 |
+
node["ids"].extend(old_ids)
|
| 169 |
+
super().visit_section(node)
|
| 170 |
+
node["ids"] = old_ids
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def parse_django_admin_node(env, sig, signode):
|
| 174 |
+
command = sig.split(" ")[0]
|
| 175 |
+
env.ref_context["std:program"] = command
|
| 176 |
+
title = "django-admin %s" % sig
|
| 177 |
+
signode += addnodes.desc_name(title, title)
|
| 178 |
+
return command
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
class DjangoStandaloneHTMLBuilder(StandaloneHTMLBuilder):
|
| 182 |
+
"""
|
| 183 |
+
Subclass to add some extra things we need.
|
| 184 |
+
"""
|
| 185 |
+
|
| 186 |
+
name = "djangohtml"
|
| 187 |
+
|
| 188 |
+
def finish(self):
|
| 189 |
+
super().finish()
|
| 190 |
+
logger.info(bold("writing templatebuiltins.js..."))
|
| 191 |
+
xrefs = self.env.domaindata["std"]["objects"]
|
| 192 |
+
templatebuiltins = {
|
| 193 |
+
"ttags": [
|
| 194 |
+
n
|
| 195 |
+
for ((t, n), (k, a)) in xrefs.items()
|
| 196 |
+
if t == "templatetag" and k == "ref/templates/builtins"
|
| 197 |
+
],
|
| 198 |
+
"tfilters": [
|
| 199 |
+
n
|
| 200 |
+
for ((t, n), (k, a)) in xrefs.items()
|
| 201 |
+
if t == "templatefilter" and k == "ref/templates/builtins"
|
| 202 |
+
],
|
| 203 |
+
}
|
| 204 |
+
outfilename = os.path.join(self.outdir, "templatebuiltins.js")
|
| 205 |
+
with open(outfilename, "w") as fp:
|
| 206 |
+
fp.write("var django_template_builtins = ")
|
| 207 |
+
json.dump(templatebuiltins, fp)
|
| 208 |
+
fp.write(";\n")
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
class ConsoleNode(nodes.literal_block):
|
| 212 |
+
"""
|
| 213 |
+
Custom node to override the visit/depart event handlers at registration
|
| 214 |
+
time. Wrap a literal_block object and defer to it.
|
| 215 |
+
"""
|
| 216 |
+
|
| 217 |
+
tagname = "ConsoleNode"
|
| 218 |
+
|
| 219 |
+
def __init__(self, litblk_obj):
|
| 220 |
+
self.wrapped = litblk_obj
|
| 221 |
+
|
| 222 |
+
def __getattr__(self, attr):
|
| 223 |
+
if attr == "wrapped":
|
| 224 |
+
return self.__dict__.wrapped
|
| 225 |
+
return getattr(self.wrapped, attr)
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def visit_console_dummy(self, node):
|
| 229 |
+
"""Defer to the corresponding parent's handler."""
|
| 230 |
+
self.visit_literal_block(node)
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def depart_console_dummy(self, node):
|
| 234 |
+
"""Defer to the corresponding parent's handler."""
|
| 235 |
+
self.depart_literal_block(node)
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def visit_console_html(self, node):
|
| 239 |
+
"""Generate HTML for the console directive."""
|
| 240 |
+
if self.builder.name in ("djangohtml", "json") and node["win_console_text"]:
|
| 241 |
+
# Put a mark on the document object signaling the fact the directive
|
| 242 |
+
# has been used on it.
|
| 243 |
+
self.document._console_directive_used_flag = True
|
| 244 |
+
uid = node["uid"]
|
| 245 |
+
self.body.append(
|
| 246 |
+
"""\
|
| 247 |
+
<div class="console-block" id="console-block-%(id)s">
|
| 248 |
+
<input class="c-tab-unix" id="c-tab-%(id)s-unix" type="radio" name="console-%(id)s" \
|
| 249 |
+
checked>
|
| 250 |
+
<label for="c-tab-%(id)s-unix" title="Linux/macOS">/</label>
|
| 251 |
+
<input class="c-tab-win" id="c-tab-%(id)s-win" type="radio" name="console-%(id)s">
|
| 252 |
+
<label for="c-tab-%(id)s-win" title="Windows"></label>
|
| 253 |
+
<section class="c-content-unix" id="c-content-%(id)s-unix">\n"""
|
| 254 |
+
% {"id": uid}
|
| 255 |
+
)
|
| 256 |
+
try:
|
| 257 |
+
self.visit_literal_block(node)
|
| 258 |
+
except nodes.SkipNode:
|
| 259 |
+
pass
|
| 260 |
+
self.body.append("</section>\n")
|
| 261 |
+
|
| 262 |
+
self.body.append(
|
| 263 |
+
'<section class="c-content-win" id="c-content-%(id)s-win">\n' % {"id": uid}
|
| 264 |
+
)
|
| 265 |
+
win_text = node["win_console_text"]
|
| 266 |
+
highlight_args = {"force": True}
|
| 267 |
+
linenos = node.get("linenos", False)
|
| 268 |
+
|
| 269 |
+
def warner(msg):
|
| 270 |
+
self.builder.warn(msg, (self.builder.current_docname, node.line))
|
| 271 |
+
|
| 272 |
+
highlighted = self.highlighter.highlight_block(
|
| 273 |
+
win_text, "doscon", warn=warner, linenos=linenos, **highlight_args
|
| 274 |
+
)
|
| 275 |
+
self.body.append(highlighted)
|
| 276 |
+
self.body.append("</section>\n")
|
| 277 |
+
self.body.append("</div>\n")
|
| 278 |
+
raise nodes.SkipNode
|
| 279 |
+
else:
|
| 280 |
+
self.visit_literal_block(node)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
class ConsoleDirective(CodeBlock):
|
| 284 |
+
"""
|
| 285 |
+
A reStructuredText directive which renders a two-tab code block in which
|
| 286 |
+
the second tab shows a Windows command line equivalent of the usual
|
| 287 |
+
Unix-oriented examples.
|
| 288 |
+
"""
|
| 289 |
+
|
| 290 |
+
required_arguments = 0
|
| 291 |
+
# The 'doscon' Pygments formatter needs a prompt like this. '>' alone
|
| 292 |
+
# won't do it because then it simply paints the whole command line as a
|
| 293 |
+
# gray comment with no highlighting at all.
|
| 294 |
+
WIN_PROMPT = r"...\> "
|
| 295 |
+
|
| 296 |
+
def run(self):
|
| 297 |
+
def args_to_win(cmdline):
|
| 298 |
+
changed = False
|
| 299 |
+
out = []
|
| 300 |
+
for token in cmdline.split():
|
| 301 |
+
if token[:2] == "./":
|
| 302 |
+
token = token[2:]
|
| 303 |
+
changed = True
|
| 304 |
+
elif token[:2] == "~/":
|
| 305 |
+
token = "%HOMEPATH%\\" + token[2:]
|
| 306 |
+
changed = True
|
| 307 |
+
elif token == "make":
|
| 308 |
+
token = "make.bat"
|
| 309 |
+
changed = True
|
| 310 |
+
if "://" not in token and "git" not in cmdline:
|
| 311 |
+
out.append(token.replace("/", "\\"))
|
| 312 |
+
changed = True
|
| 313 |
+
else:
|
| 314 |
+
out.append(token)
|
| 315 |
+
if changed:
|
| 316 |
+
return " ".join(out)
|
| 317 |
+
return cmdline
|
| 318 |
+
|
| 319 |
+
def cmdline_to_win(line):
|
| 320 |
+
if line.startswith("# "):
|
| 321 |
+
return "REM " + args_to_win(line[2:])
|
| 322 |
+
if line.startswith("$ # "):
|
| 323 |
+
return "REM " + args_to_win(line[4:])
|
| 324 |
+
if line.startswith("$ ./manage.py"):
|
| 325 |
+
return "manage.py " + args_to_win(line[13:])
|
| 326 |
+
if line.startswith("$ manage.py"):
|
| 327 |
+
return "manage.py " + args_to_win(line[11:])
|
| 328 |
+
if line.startswith("$ ./runtests.py"):
|
| 329 |
+
return "runtests.py " + args_to_win(line[15:])
|
| 330 |
+
if line.startswith("$ ./"):
|
| 331 |
+
return args_to_win(line[4:])
|
| 332 |
+
if line.startswith("$ python3"):
|
| 333 |
+
return "py " + args_to_win(line[9:])
|
| 334 |
+
if line.startswith("$ python"):
|
| 335 |
+
return "py " + args_to_win(line[8:])
|
| 336 |
+
if line.startswith("$ "):
|
| 337 |
+
return args_to_win(line[2:])
|
| 338 |
+
return None
|
| 339 |
+
|
| 340 |
+
def code_block_to_win(content):
|
| 341 |
+
bchanged = False
|
| 342 |
+
lines = []
|
| 343 |
+
for line in content:
|
| 344 |
+
modline = cmdline_to_win(line)
|
| 345 |
+
if modline is None:
|
| 346 |
+
lines.append(line)
|
| 347 |
+
else:
|
| 348 |
+
lines.append(self.WIN_PROMPT + modline)
|
| 349 |
+
bchanged = True
|
| 350 |
+
if bchanged:
|
| 351 |
+
return ViewList(lines)
|
| 352 |
+
return None
|
| 353 |
+
|
| 354 |
+
env = self.state.document.settings.env
|
| 355 |
+
self.arguments = ["console"]
|
| 356 |
+
lit_blk_obj = super().run()[0]
|
| 357 |
+
|
| 358 |
+
# Only do work when the djangohtml HTML Sphinx builder is being used,
|
| 359 |
+
# invoke the default behavior for the rest.
|
| 360 |
+
if env.app.builder.name not in ("djangohtml", "json"):
|
| 361 |
+
return [lit_blk_obj]
|
| 362 |
+
|
| 363 |
+
lit_blk_obj["uid"] = str(env.new_serialno("console"))
|
| 364 |
+
# Only add the tabbed UI if there is actually a Windows-specific
|
| 365 |
+
# version of the CLI example.
|
| 366 |
+
win_content = code_block_to_win(self.content)
|
| 367 |
+
if win_content is None:
|
| 368 |
+
lit_blk_obj["win_console_text"] = None
|
| 369 |
+
else:
|
| 370 |
+
self.content = win_content
|
| 371 |
+
lit_blk_obj["win_console_text"] = super().run()[0].rawsource
|
| 372 |
+
|
| 373 |
+
# Replace the literal_node object returned by Sphinx's CodeBlock with
|
| 374 |
+
# the ConsoleNode wrapper.
|
| 375 |
+
return [ConsoleNode(lit_blk_obj)]
|
| 376 |
+
|
| 377 |
+
|
| 378 |
+
def html_page_context_hook(app, pagename, templatename, context, doctree):
|
| 379 |
+
# Put a bool on the context used to render the template. It's used to
|
| 380 |
+
# control inclusion of console-tabs.css and activation of the JavaScript.
|
| 381 |
+
# This way it's include only from HTML files rendered from reST files where
|
| 382 |
+
# the ConsoleDirective is used.
|
| 383 |
+
context["include_console_assets"] = getattr(
|
| 384 |
+
doctree, "_console_directive_used_flag", False
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
def default_role_error(
|
| 389 |
+
name, rawtext, text, lineno, inliner, options=None, content=None
|
| 390 |
+
):
|
| 391 |
+
msg = (
|
| 392 |
+
"Default role used (`single backticks`): %s. Did you mean to use two "
|
| 393 |
+
"backticks for ``code``, or miss an underscore for a `link`_ ?" % rawtext
|
| 394 |
+
)
|
| 395 |
+
logger.warning(msg, location=(inliner.document.current_source, lineno))
|
| 396 |
+
return [nodes.Text(text)], []
|
testbed/django__django/docs/_theme/djangodocs-epub/epub-cover.html
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- extends "epub/epub-cover.html" %}
|
| 2 |
+
|
| 3 |
+
{% block content %}
|
| 4 |
+
<div class="epub-cover">
|
| 5 |
+
<h1>Django Documentation</h1>
|
| 6 |
+
<h2><em>Release {{ release }}</em></h2>
|
| 7 |
+
<h3>{{ copyright }}</h3>
|
| 8 |
+
<p>{{ last_updated }}</p>
|
| 9 |
+
</div>
|
| 10 |
+
{% endblock %}
|
testbed/django__django/docs/_theme/djangodocs-epub/static/epub.css
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
h1 { margin-top: 0; }
|
| 2 |
+
|
| 3 |
+
/* Keep lists a bit narrow to maximize page estate regarding width. */
|
| 4 |
+
ol, ul {
|
| 5 |
+
margin: 0;
|
| 6 |
+
padding: 0 0 0 1.3em;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
/* Images should never exceed the width of the page. */
|
| 10 |
+
img { max-width: 100%; }
|
| 11 |
+
|
| 12 |
+
/* Don't display URL after links, this is not print. */
|
| 13 |
+
.link-target { display: none; }
|
| 14 |
+
|
| 15 |
+
/* This is the front cover page of the book. */
|
| 16 |
+
.epub-cover { text-align: center; }
|
| 17 |
+
.epub-cover h1 { margin: 4em 0 0 0; }
|
| 18 |
+
.epub-cover h2 { margin: 1em 0; }
|
| 19 |
+
.epub-cover h3 { margin: 3em 0 2em 0; }
|
| 20 |
+
|
| 21 |
+
/* Code examples should never exceed the width of the page, so wrap instead. */
|
| 22 |
+
pre, span.pre { white-space: pre-wrap; }
|
| 23 |
+
|
| 24 |
+
pre {
|
| 25 |
+
background-color: #f6f6f6;
|
| 26 |
+
border: 0;
|
| 27 |
+
padding: 0.5em;
|
| 28 |
+
font-size: 90%;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
/* Header for some code blocks. */
|
| 32 |
+
.code-block-caption {
|
| 33 |
+
background-color: #393939;
|
| 34 |
+
color: white;
|
| 35 |
+
margin: 0;
|
| 36 |
+
padding: 0.5em;
|
| 37 |
+
font: bold 90% monospace;
|
| 38 |
+
}
|
| 39 |
+
.literal-block-wrapper pre {
|
| 40 |
+
margin-top: 0;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
a:link, a:visited { color: #396623; }
|
| 44 |
+
a:hover { color: #1d3311; }
|
| 45 |
+
|
| 46 |
+
/* Use special styled note boxes from the default theme, but with the left side
|
| 47 |
+
fitted after the icon, to allow text resizing with breaking. */
|
| 48 |
+
.note, .admonition {
|
| 49 |
+
background-position: 9px 0.8em;
|
| 50 |
+
background-repeat: no-repeat;
|
| 51 |
+
padding: 0.8em 1em 0.8em 65px;
|
| 52 |
+
margin: 1em 0;
|
| 53 |
+
border: 0.01em solid black;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.note, .admonition { background-image: url(docicons-note.png); }
|
| 57 |
+
div.admonition-philosophy { background-image: url(docicons-philosophy.png); }
|
| 58 |
+
div.admonition-behind-the-scenes { background-image: url(docicons-behindscenes.png); }
|
| 59 |
+
.admonition.warning { background-image: url(docicons-warning.png); }
|
| 60 |
+
|
| 61 |
+
.admonition-title {
|
| 62 |
+
font-weight: bold;
|
| 63 |
+
margin: 0;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.admonition .last { margin-bottom: 0; }
|
testbed/django__django/docs/_theme/djangodocs-epub/theme.conf
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[theme]
|
| 2 |
+
inherit = epub
|
| 3 |
+
stylesheet = epub.css
|
| 4 |
+
pygments_style = trac
|
| 5 |
+
|
| 6 |
+
[options]
|
| 7 |
+
relbar1 = false
|
| 8 |
+
footer = false
|
testbed/django__django/docs/_theme/djangodocs/genindex.html
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "basic/genindex.html" %}
|
| 2 |
+
|
| 3 |
+
{% block bodyclass %}{% endblock %}
|
| 4 |
+
{% block sidebarwrapper %}{% endblock %}
|
testbed/django__django/docs/_theme/djangodocs/layout.html
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "basic/layout.html" %}
|
| 2 |
+
|
| 3 |
+
{%- macro secondnav() %}
|
| 4 |
+
{%- if prev %}
|
| 5 |
+
« <a href="{{ prev.link|e }}" title="{{ prev.title|e }}">previous</a>
|
| 6 |
+
{{ reldelim2 }}
|
| 7 |
+
{%- endif %}
|
| 8 |
+
{%- if parents %}
|
| 9 |
+
<a href="{{ parents.0.link|e }}" title="{{ parents.0.title|e }}" accesskey="U">up</a>
|
| 10 |
+
{%- else %}
|
| 11 |
+
<a title="{{ docstitle }}" href="{{ pathto('index') }}" accesskey="U">up</a>
|
| 12 |
+
{%- endif %}
|
| 13 |
+
{%- if next %}
|
| 14 |
+
{{ reldelim2 }}
|
| 15 |
+
<a href="{{ next.link|e }}" title="{{ next.title|e }}">next</a> »
|
| 16 |
+
{%- endif %}
|
| 17 |
+
{%- endmacro %}
|
| 18 |
+
|
| 19 |
+
{% block extrahead %}
|
| 20 |
+
{# When building htmlhelp (CHM format) disable jQuery inclusion, #}
|
| 21 |
+
{# as it causes problems in compiled CHM files. #}
|
| 22 |
+
{% if builder != "htmlhelp" %}
|
| 23 |
+
{{ super() }}
|
| 24 |
+
<script src="{{ pathto('templatebuiltins.js', 1) }}"></script>
|
| 25 |
+
<script>
|
| 26 |
+
(function($) {
|
| 27 |
+
if (!django_template_builtins) {
|
| 28 |
+
// templatebuiltins.js missing, do nothing.
|
| 29 |
+
return;
|
| 30 |
+
}
|
| 31 |
+
$(document).ready(function() {
|
| 32 |
+
// Hyperlink Django template tags and filters
|
| 33 |
+
var base = "{{ pathto('ref/templates/builtins') }}";
|
| 34 |
+
if (base == "#") {
|
| 35 |
+
// Special case for builtins.html itself
|
| 36 |
+
base = "";
|
| 37 |
+
}
|
| 38 |
+
// Tags are keywords, class '.k'
|
| 39 |
+
$("div.highlight\\-html\\+django span.k").each(function(i, elem) {
|
| 40 |
+
var tagname = $(elem).text();
|
| 41 |
+
if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
|
| 42 |
+
var fragment = tagname.replace(/_/, '-');
|
| 43 |
+
$(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
|
| 44 |
+
}
|
| 45 |
+
});
|
| 46 |
+
// Filters are functions, class '.nf'
|
| 47 |
+
$("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
|
| 48 |
+
var filtername = $(elem).text();
|
| 49 |
+
if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
|
| 50 |
+
var fragment = filtername.replace(/_/, '-');
|
| 51 |
+
$(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
|
| 52 |
+
}
|
| 53 |
+
});
|
| 54 |
+
});
|
| 55 |
+
})(jQuery);
|
| 56 |
+
{%- if include_console_assets -%}
|
| 57 |
+
(function($) {
|
| 58 |
+
$(document).ready(function() {
|
| 59 |
+
$(".c-tab-unix").on("click", function() {
|
| 60 |
+
$("section.c-content-unix").show();
|
| 61 |
+
$("section.c-content-win").hide();
|
| 62 |
+
$(".c-tab-unix").prop("checked", true);
|
| 63 |
+
});
|
| 64 |
+
$(".c-tab-win").on("click", function() {
|
| 65 |
+
$("section.c-content-win").show();
|
| 66 |
+
$("section.c-content-unix").hide();
|
| 67 |
+
$(".c-tab-win").prop("checked", true);
|
| 68 |
+
});
|
| 69 |
+
});
|
| 70 |
+
})(jQuery);
|
| 71 |
+
{%- endif -%}
|
| 72 |
+
</script>
|
| 73 |
+
{% endif %}
|
| 74 |
+
{%- if include_console_assets -%}
|
| 75 |
+
<link rel="stylesheet" href="{{ pathto('_static/console-tabs.css', 1) }}">
|
| 76 |
+
{%- endif -%}
|
| 77 |
+
{% endblock %}
|
| 78 |
+
|
| 79 |
+
{% block document %}
|
| 80 |
+
<div id="custom-doc" class="{% block bodyclass %}{{ 'yui-t6' if pagename != 'index' else '' }}{% endblock %}">
|
| 81 |
+
<div id="hd">
|
| 82 |
+
<h1><a href="{{ pathto('index') }}">{{ docstitle }}</a></h1>
|
| 83 |
+
<div id="global-nav">
|
| 84 |
+
<a title="Home page" href="{{ pathto('index') }}">Home</a> {{ reldelim2 }}
|
| 85 |
+
<a title="Table of contents" href="{{ pathto('contents') }}">Table of contents</a> {{ reldelim2 }}
|
| 86 |
+
<a title="Global index" href="{{ pathto('genindex') }}">Index</a> {{ reldelim2 }}
|
| 87 |
+
<a title="Module index" href="{{ pathto('py-modindex') }}">Modules</a>
|
| 88 |
+
</div>
|
| 89 |
+
<div class="nav">{{ secondnav() }}</div>
|
| 90 |
+
</div>
|
| 91 |
+
|
| 92 |
+
<div id="bd">
|
| 93 |
+
<div id="yui-main">
|
| 94 |
+
<div class="yui-b">
|
| 95 |
+
<div class="yui-g" id="{{ pagename|replace('/', '-') }}">
|
| 96 |
+
{% block body %}{% endblock %}
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
{% block sidebarwrapper %}
|
| 101 |
+
{% if pagename != 'index' %}
|
| 102 |
+
<div class="yui-b" id="sidebar">
|
| 103 |
+
{{ sidebar() }}
|
| 104 |
+
{%- if last_updated %}
|
| 105 |
+
<h3>Last update:</h3>
|
| 106 |
+
<p class="topless">{{ last_updated }}</p>
|
| 107 |
+
{%- endif %}
|
| 108 |
+
</div>
|
| 109 |
+
{% endif %}
|
| 110 |
+
{% endblock %}
|
| 111 |
+
</div>
|
| 112 |
+
|
| 113 |
+
<div id="ft">
|
| 114 |
+
<div class="nav">{{ secondnav() }}</div>
|
| 115 |
+
</div>
|
| 116 |
+
</div>
|
| 117 |
+
{% endblock %}
|
| 118 |
+
|
| 119 |
+
{% block sidebarrel %}
|
| 120 |
+
<h3>Browse</h3>
|
| 121 |
+
<ul>
|
| 122 |
+
{% if prev %}
|
| 123 |
+
<li>Prev: <a href="{{ prev.link }}">{{ prev.title }}</a></li>
|
| 124 |
+
{% endif %}
|
| 125 |
+
{% if next %}
|
| 126 |
+
<li>Next: <a href="{{ next.link }}">{{ next.title }}</a></li>
|
| 127 |
+
{% endif %}
|
| 128 |
+
</ul>
|
| 129 |
+
<h3>You are here:</h3>
|
| 130 |
+
<ul>
|
| 131 |
+
<li>
|
| 132 |
+
<a href="{{ pathto('index') }}">{{ docstitle }}</a>
|
| 133 |
+
{% for p in parents %}
|
| 134 |
+
<ul><li><a href="{{ p.link }}">{{ p.title }}</a>
|
| 135 |
+
{% endfor %}
|
| 136 |
+
<ul><li>{{ title }}</li></ul>
|
| 137 |
+
{% for p in parents %}</li></ul>{% endfor %}
|
| 138 |
+
</li>
|
| 139 |
+
</ul>
|
| 140 |
+
{% endblock %}
|
| 141 |
+
|
| 142 |
+
{# Empty some default blocks out #}
|
| 143 |
+
{% block relbar1 %}{% endblock %}
|
| 144 |
+
{% block relbar2 %}{% endblock %}
|
| 145 |
+
{% block sidebar1 %}{% endblock %}
|
| 146 |
+
{% block sidebar2 %}{% endblock %}
|
| 147 |
+
{% block footer %}{% endblock %}
|
testbed/django__django/docs/_theme/djangodocs/modindex.html
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "basic/modindex.html" %}
|
| 2 |
+
{% block bodyclass %}{% endblock %}
|
| 3 |
+
{% block sidebarwrapper %}{% endblock %}
|
testbed/django__django/docs/_theme/djangodocs/search.html
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "basic/search.html" %}
|
| 2 |
+
{% block bodyclass %}{% endblock %}
|
| 3 |
+
{% block sidebarwrapper %}{% endblock %}
|
testbed/django__django/docs/_theme/djangodocs/static/console-tabs.css
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import url("{{ pathto('_static/fontawesome/css/fa-brands.min.css', 1) }}");
|
| 2 |
+
|
| 3 |
+
.console-block {
|
| 4 |
+
text-align: right;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
.console-block *:before,
|
| 8 |
+
.console-block *:after {
|
| 9 |
+
box-sizing: border-box;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
.console-block > section {
|
| 13 |
+
display: none;
|
| 14 |
+
text-align: left;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
.console-block > input.c-tab-unix,
|
| 18 |
+
.console-block > input.c-tab-win {
|
| 19 |
+
display: none;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
.console-block > label {
|
| 23 |
+
display: inline-block;
|
| 24 |
+
padding: 4px 8px;
|
| 25 |
+
font-weight: normal;
|
| 26 |
+
text-align: center;
|
| 27 |
+
color: #bbb;
|
| 28 |
+
border: 1px solid transparent;
|
| 29 |
+
font-family: fontawesome;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
.console-block > input:checked + label {
|
| 33 |
+
color: #555;
|
| 34 |
+
border: 1px solid #ddd;
|
| 35 |
+
border-top: 2px solid #ab5603;
|
| 36 |
+
border-bottom: 1px solid #fff;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.console-block > .c-tab-unix:checked ~ .c-content-unix,
|
| 40 |
+
.console-block > .c-tab-win:checked ~ .c-content-win {
|
| 41 |
+
display: block;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.console-block pre {
|
| 45 |
+
margin-top: 0px;
|
| 46 |
+
}
|
testbed/django__django/docs/_theme/djangodocs/static/default.css
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@import url(reset-fonts-grids.css);
|
| 2 |
+
@import url(djangodocs.css);
|
| 3 |
+
@import url(homepage.css);
|
testbed/django__django/docs/_theme/djangodocs/static/djangodocs.css
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*** setup ***/
|
| 2 |
+
html { background:#092e20;}
|
| 3 |
+
body { font:12px/1.5 Verdana,sans-serif; background:#092e20; color: white;}
|
| 4 |
+
#custom-doc { width:76.54em;*width:74.69em;min-width:995px; max-width:100em; margin:auto; text-align:left; padding-top:16px; margin-top:0;}
|
| 5 |
+
#hd { padding: 4px 0 12px 0; }
|
| 6 |
+
#bd { background:#234F32; }
|
| 7 |
+
#ft { color:#487858; font-size:90%; padding-bottom: 2em; }
|
| 8 |
+
|
| 9 |
+
/*** links ***/
|
| 10 |
+
a {text-decoration: none;}
|
| 11 |
+
a img {border: none;}
|
| 12 |
+
a:link, a:visited { color:#ffc757; }
|
| 13 |
+
#bd a:link, #bd a:visited { color:#ab5603; text-decoration:underline; }
|
| 14 |
+
#bd #sidebar a:link, #bd #sidebar a:visited { color:#ffc757; text-decoration:none; }
|
| 15 |
+
a:hover { color:#ffe761; }
|
| 16 |
+
#bd a:hover { background-color:#E0FFB8; color:#234f32; text-decoration:none; }
|
| 17 |
+
#bd #sidebar a:hover { color:#ffe761; background:none; }
|
| 18 |
+
h2 a, h3 a, h4 a { text-decoration:none !important; }
|
| 19 |
+
a.reference em { font-style: normal; }
|
| 20 |
+
|
| 21 |
+
/*** sidebar ***/
|
| 22 |
+
#sidebar div.sphinxsidebarwrapper { font-size:92%; margin-right: 14px; }
|
| 23 |
+
#sidebar h3, #sidebar h4 { color: white; font-size: 125%; }
|
| 24 |
+
#sidebar a { color: white; }
|
| 25 |
+
#sidebar ul ul { margin-top:0; margin-bottom:0; }
|
| 26 |
+
#sidebar li { margin-top: 0.2em; margin-bottom: 0.2em; }
|
| 27 |
+
|
| 28 |
+
/*** nav ***/
|
| 29 |
+
div.nav { margin: 0; font-size: 11px; text-align: right; color: #487858;}
|
| 30 |
+
#hd div.nav { margin-top: -27px; }
|
| 31 |
+
#ft div.nav { margin-bottom: -18px; }
|
| 32 |
+
#hd h1 a { color: white; }
|
| 33 |
+
#global-nav { position:absolute; top:5px; margin-left: -5px; padding:7px 0; color:#263E2B; }
|
| 34 |
+
#global-nav a:link, #global-nav a:visited {color:#487858;}
|
| 35 |
+
#global-nav a {padding:0 4px;}
|
| 36 |
+
#global-nav a.about {padding-left:0;}
|
| 37 |
+
#global-nav:hover {color:#fff;}
|
| 38 |
+
#global-nav:hover a:link, #global-nav:hover a:visited { color:#ffc757; }
|
| 39 |
+
|
| 40 |
+
/*** content ***/
|
| 41 |
+
#yui-main div.yui-b { position: relative; }
|
| 42 |
+
#yui-main div.yui-b { margin: 0 0 0 20px; background: white; color: black; padding: 0.3em 2em 1em 2em; }
|
| 43 |
+
|
| 44 |
+
/*** basic styles ***/
|
| 45 |
+
dd { margin-left:15px; }
|
| 46 |
+
h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12 { margin-top:1em; font-family:"Trebuchet MS",sans-serif; font-weight:normal; }
|
| 47 |
+
h1 { font-size:218%; margin-top:0.6em; margin-bottom:.4em; line-height:1.1em; }
|
| 48 |
+
h2 { font-size:175%; margin-bottom:.6em; line-height:1.2em; color:#092e20; }
|
| 49 |
+
h3 { font-size:150%; font-weight:bold; margin-bottom:.2em; color:#487858; }
|
| 50 |
+
h4 { font-size:125%; font-weight:bold; margin-top:1.5em; margin-bottom:3px; }
|
| 51 |
+
h5 { font-size:110%; font-weight:bold; margin-top:1em; margin-bottom:3px; }
|
| 52 |
+
h6,h7,h8,h9,h10,h11,h12 { font-weight:bold; margin-bottom:3px; }
|
| 53 |
+
div.figure { text-align: center; }
|
| 54 |
+
div.figure p.caption { font-size:1em; margin-top:0; margin-bottom:1.5em; color: #555;}
|
| 55 |
+
hr { color:#ccc; background-color:#ccc; height:1px; border:0; }
|
| 56 |
+
p, ul, dl { margin-top:.6em; margin-bottom:1em; padding-bottom: 0.1em;}
|
| 57 |
+
#yui-main div.yui-b img { max-width: 50em; margin-left: auto; margin-right: auto; display: block; }
|
| 58 |
+
caption { font-size:1em; font-weight:bold; margin-top:0.5em; margin-bottom:0.5em; margin-left: 2px; text-align: center; }
|
| 59 |
+
blockquote { padding: 0 1em; margin: 1em 0; font:125%/1.2em "Trebuchet MS", sans-serif; color:#234f32; border-left:2px solid #94da3a; }
|
| 60 |
+
strong { font-weight: bold; }
|
| 61 |
+
em { font-style: italic; }
|
| 62 |
+
ins { font-weight: bold; text-decoration: none; }
|
| 63 |
+
|
| 64 |
+
/*** lists ***/
|
| 65 |
+
ul { padding-left:30px; }
|
| 66 |
+
ol { padding-left:30px; }
|
| 67 |
+
ol.arabic li { list-style-type: decimal; }
|
| 68 |
+
ul li { list-style-type:square; margin-bottom:.4em; }
|
| 69 |
+
ul ul li { list-style-type:disc; }
|
| 70 |
+
ul ul ul li { list-style-type:circle; }
|
| 71 |
+
ol li { margin-bottom: .4em; }
|
| 72 |
+
ul ul { padding-left:1.2em; }
|
| 73 |
+
ul ul ul { padding-left:1em; }
|
| 74 |
+
ul.linklist, ul.toc { padding-left:0; }
|
| 75 |
+
ul.toc ul { margin-left:.6em; }
|
| 76 |
+
ul.toc ul li { list-style-type:square; }
|
| 77 |
+
ul.toc ul ul li { list-style-type:disc; }
|
| 78 |
+
ul.linklist li, ul.toc li { list-style-type:none; }
|
| 79 |
+
dt { font-weight:bold; margin-top:.5em; font-size:1.1em; }
|
| 80 |
+
dd { margin-bottom:.8em; }
|
| 81 |
+
ol.toc { margin-bottom: 2em; }
|
| 82 |
+
ol.toc li { font-size:125%; padding: .5em; line-height:1.2em; clear: right; }
|
| 83 |
+
ol.toc li.b { background-color: #E0FFB8; }
|
| 84 |
+
ol.toc li a:hover { background-color: transparent !important; text-decoration: underline !important; }
|
| 85 |
+
ol.toc span.release-date { color:#487858; float: right; font-size: 85%; padding-right: .5em; }
|
| 86 |
+
ol.toc span.comment-count { font-size: 75%; color: #999; }
|
| 87 |
+
|
| 88 |
+
/*** tables ***/
|
| 89 |
+
table { color:#000; margin-bottom: 1em; width: 100%; }
|
| 90 |
+
table.docutils td p { margin-top:0; margin-bottom:.5em; }
|
| 91 |
+
table.docutils td, table.docutils th { border-bottom:1px solid #dfdfdf; padding:4px 2px;}
|
| 92 |
+
table.docutils thead th { border-bottom:2px solid #dfdfdf; text-align:left; font-weight: bold; white-space: nowrap; }
|
| 93 |
+
table.docutils thead th p { margin: 0; padding: 0; }
|
| 94 |
+
table.docutils { border-collapse:collapse; }
|
| 95 |
+
|
| 96 |
+
/*** code blocks ***/
|
| 97 |
+
.literal { color:#234f32; white-space:nowrap; }
|
| 98 |
+
dt > tt.literal { white-space: normal; }
|
| 99 |
+
#sidebar .literal { color:white; background:transparent; font-size:11px; }
|
| 100 |
+
h4 .literal { color: #234f32; font-size: 13px; }
|
| 101 |
+
pre { font-size:small; background:#E0FFB8; border:1px solid #94da3a; border-width:1px 0; margin: 1em 0; padding: .3em .4em; overflow: hidden; line-height: 1.3em; white-space: pre-wrap;}
|
| 102 |
+
dt .literal, table .literal { background:none; }
|
| 103 |
+
#bd a.reference { text-decoration: none; }
|
| 104 |
+
#bd a.reference tt.literal { border-bottom: 1px #234f32 dotted; }
|
| 105 |
+
div.code-block-caption { color: white; background-color: #234F32; margin: 0; padding: 2px 5px; width: 100%; font-family: monospace; font-size: small; line-height: 1.3em; }
|
| 106 |
+
div.code-block-caption .literal {color: white; }
|
| 107 |
+
div.literal-block-wrapper pre { margin-top: 0; }
|
| 108 |
+
|
| 109 |
+
/* Restore colors of pygments hyperlinked code */
|
| 110 |
+
#bd .highlight .k a:link, #bd .highlight .k a:visited { color: #000000; text-decoration: none; border-bottom: 1px dotted #000000; }
|
| 111 |
+
#bd .highlight .nf a:link, #bd .highlight .nf a:visited { color: #990000; text-decoration: none; border-bottom: 1px dotted #990000; }
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
/*** notes & admonitions ***/
|
| 115 |
+
.note, .admonition { padding:.8em 1em .8em; margin: 1em 0; border:1px solid #94da3a; }
|
| 116 |
+
.admonition-title { font-weight:bold; margin-top:0 !important; margin-bottom:0 !important;}
|
| 117 |
+
.admonition .last { margin-bottom:0 !important; }
|
| 118 |
+
.note, .admonition { padding-left:65px; background:url(docicons-note.png) .8em .8em no-repeat;}
|
| 119 |
+
div.admonition-philosophy { padding-left:65px; background:url(docicons-philosophy.png) .8em .8em no-repeat;}
|
| 120 |
+
div.admonition-behind-the-scenes { padding-left:65px; background:url(docicons-behindscenes.png) .8em .8em no-repeat;}
|
| 121 |
+
.admonition.warning { background:url(docicons-warning.png) .8em .8em no-repeat; border:1px solid #ffc83c;}
|
| 122 |
+
|
| 123 |
+
/*** versionadded/changes ***/
|
| 124 |
+
div.versionadded, div.versionchanged { }
|
| 125 |
+
div.versionadded span.title, div.versionchanged span.title, span.versionmodified { font-weight: bold; }
|
| 126 |
+
div.versionadded, div.versionchanged, div.deprecated { color:#555; }
|
| 127 |
+
|
| 128 |
+
/*** p-links ***/
|
| 129 |
+
a.headerlink { color: #c60f0f; font-size: 0.8em; margin-left: 4px; opacity: 0; text-decoration: none; }
|
| 130 |
+
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, h4:hover > a.headerlink, h5:hover > a.headerlink, h6:hover > a.headerlink, dt:hover > a.headerlink { opacity: 1; }
|
| 131 |
+
a.headerlink:focus { opacity: 1; }
|
| 132 |
+
|
| 133 |
+
/*** index ***/
|
| 134 |
+
table.indextable td { text-align: left; vertical-align: top;}
|
| 135 |
+
table.indextable dl, table.indextable dd { margin-top: 0; margin-bottom: 0; }
|
| 136 |
+
table.indextable tr.pcap { height: 10px; }
|
| 137 |
+
table.indextable tr.cap { margin-top: 10px; background-color: #f2f2f2;}
|
| 138 |
+
|
| 139 |
+
/*** page-specific overrides ***/
|
| 140 |
+
div#contents ul { margin-bottom: 0;}
|
| 141 |
+
div#contents ul li { margin-bottom: 0;}
|
| 142 |
+
div#contents ul ul li { margin-top: 0.3em;}
|
| 143 |
+
|
| 144 |
+
/*** IE hacks ***/
|
| 145 |
+
* pre { width: 100%; }
|
testbed/django__django/docs/_theme/djangodocs/static/fontawesome/LICENSE.txt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Font Awesome Free License
|
| 2 |
+
-------------------------
|
| 3 |
+
|
| 4 |
+
Font Awesome Free is free, open source, and GPL friendly. You can use it for
|
| 5 |
+
commercial projects, open source projects, or really almost whatever you want.
|
| 6 |
+
Full Font Awesome Free license: https://fontawesome.com/license.
|
| 7 |
+
|
| 8 |
+
# Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/)
|
| 9 |
+
In the Font Awesome Free download, the CC BY 4.0 license applies to all icons
|
| 10 |
+
packaged as SVG and JS file types.
|
| 11 |
+
|
| 12 |
+
# Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL)
|
| 13 |
+
In the Font Awesome Free download, the SIL OLF license applies to all icons
|
| 14 |
+
packaged as web and desktop font files.
|
| 15 |
+
|
| 16 |
+
# Code: MIT License (https://opensource.org/licenses/MIT)
|
| 17 |
+
In the Font Awesome Free download, the MIT license applies to all non-font and
|
| 18 |
+
non-icon files.
|
| 19 |
+
|
| 20 |
+
# Attribution
|
| 21 |
+
Attribution is required by MIT, SIL OLF, and CC BY licenses. Downloaded Font
|
| 22 |
+
Awesome Free files already contain embedded comments with sufficient
|
| 23 |
+
attribution, so you shouldn't need to do anything additional when using these
|
| 24 |
+
files normally.
|
| 25 |
+
|
| 26 |
+
We've kept attribution comments terse, so we ask that you do not actively work
|
| 27 |
+
to remove them from files, especially code. They're a great way for folks to
|
| 28 |
+
learn about Font Awesome.
|
| 29 |
+
|
| 30 |
+
# Brand Icons
|
| 31 |
+
All brand icons are trademarks of their respective owners. The use of these
|
| 32 |
+
trademarks does not indicate endorsement of the trademark holder by Font
|
| 33 |
+
Awesome, nor vice versa. **Please do not use brand logos for any purpose except
|
| 34 |
+
to represent the company, product, or service to which they refer.**
|
testbed/django__django/docs/_theme/djangodocs/static/fontawesome/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Font Awesome 5.0.4
|
| 2 |
+
|
| 3 |
+
Thanks for downloading Font Awesome! We're so excited you're here.
|
| 4 |
+
|
| 5 |
+
Our documentation is available online. Just head here:
|
| 6 |
+
|
| 7 |
+
https://fontawesome.com
|
testbed/django__django/docs/_theme/djangodocs/static/fontawesome/css/fa-brands.min.css
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*!
|
| 2 |
+
* Font Awesome Free 5.0.4 by @fontawesome - http://fontawesome.com
|
| 3 |
+
* License - http://fontawesome.com/license (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
|
| 4 |
+
*/
|
| 5 |
+
@font-face{font-family:Font Awesome\ 5 Brands;font-style:normal;font-weight:400;src:url(../webfonts/fa-brands-400.eot);src:url(../webfonts/fa-brands-400.eot?#iefix) format("embedded-opentype"),url(../webfonts/fa-brands-400.woff2) format("woff2"),url(../webfonts/fa-brands-400.woff) format("woff"),url(../webfonts/fa-brands-400.ttf) format("truetype"),url(../webfonts/fa-brands-400.svg#fontawesome) format("svg")}.fab{font-family:Font Awesome\ 5 Brands}
|
testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.eot
ADDED
|
Binary file (97.6 kB). View file
|
|
|
testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.svg
ADDED
|
|
testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.ttf
ADDED
|
Binary file (97.3 kB). View file
|
|
|
testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.woff
ADDED
|
Binary file (63 kB). View file
|
|
|
testbed/django__django/docs/_theme/djangodocs/static/fontawesome/webfonts/fa-brands-400.woff2
ADDED
|
Binary file (53.9 kB). View file
|
|
|
testbed/django__django/docs/_theme/djangodocs/static/homepage.css
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#index p.rubric { font-size:150%; font-weight:normal; margin-bottom:.2em; color:#487858; }
|
| 2 |
+
|
| 3 |
+
#index div.section dt { font-weight: normal; }
|
| 4 |
+
|
| 5 |
+
#index #s-getting-help { float: right; width: 35em; background: #E1ECE2; padding: 1em; margin: 2em 0 2em 2em; }
|
| 6 |
+
#index #s-getting-help h2 { margin: 0; }
|
| 7 |
+
|
| 8 |
+
#index #s-django-documentation div.section div.section h3 { margin: 0; }
|
| 9 |
+
#index #s-django-documentation div.section div.section { background: #E1ECE2; padding: 1em; margin: 2em 0 2em 40.3em; }
|
| 10 |
+
#index #s-django-documentation div.section div.section a.reference { white-space: nowrap; }
|
| 11 |
+
|
| 12 |
+
#index #s-using-django dl,
|
| 13 |
+
#index #s-add-on-contrib-applications dl,
|
| 14 |
+
#index #s-solving-specific-problems dl,
|
| 15 |
+
#index #s-reference dl
|
| 16 |
+
{ float: left; width: 41em; }
|
| 17 |
+
|
| 18 |
+
#index #s-add-on-contrib-applications,
|
| 19 |
+
#index #s-solving-specific-problems,
|
| 20 |
+
#index #s-reference,
|
| 21 |
+
#index #s-and-all-the-rest
|
| 22 |
+
{ clear: left; }
|
testbed/django__django/docs/_theme/djangodocs/static/reset-fonts-grids.css
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
| 3 |
+
Code licensed under the BSD License:
|
| 4 |
+
http://developer.yahoo.net/yui/license.txt
|
| 5 |
+
version: 2.5.1
|
| 6 |
+
*/
|
| 7 |
+
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym {border:0;font-variant:normal;}sup {vertical-align:text-top;}sub {vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}body {font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}table {font-size:inherit;font:100%;}pre,code,kbd,samp,tt{font-family:monospace;*font-size:108%;line-height:100%;}
|
| 8 |
+
body{text-align:center;}#ft{clear:both;}#doc,#doc2,#doc3,#doc4,.yui-t1,.yui-t2,.yui-t3,.yui-t4,.yui-t5,.yui-t6,.yui-t7{margin:auto;text-align:left;width:57.69em;*width:56.25em;min-width:750px;}#doc2{width:73.076em;*width:71.25em;}#doc3{margin:auto 10px;width:auto;}#doc4{width:74.923em;*width:73.05em;}.yui-b{position:relative;}.yui-b{_position:static;}#yui-main .yui-b{position:static;}#yui-main{width:100%;}.yui-t1 #yui-main,.yui-t2 #yui-main,.yui-t3 #yui-main{float:right;margin-left:-25em;}.yui-t4 #yui-main,.yui-t5 #yui-main,.yui-t6 #yui-main{float:left;margin-right:-25em;}.yui-t1 .yui-b{float:left;width:12.30769em;*width:12.00em;}.yui-t1 #yui-main .yui-b{margin-left:13.30769em;*margin-left:13.05em;}.yui-t2 .yui-b{float:left;width:13.8461em;*width:13.50em;}.yui-t2 #yui-main .yui-b{margin-left:14.8461em;*margin-left:14.55em;}.yui-t3 .yui-b{float:left;width:23.0769em;*width:22.50em;}.yui-t3 #yui-main .yui-b{margin-left:24.0769em;*margin-left:23.62em;}.yui-t4 .yui-b{float:right;width:13.8456em;*width:13.50em;}.yui-t4 #yui-main .yui-b{margin-right:14.8456em;*margin-right:14.55em;}.yui-t5 .yui-b{float:right;width:18.4615em;*width:18.00em;}.yui-t5 #yui-main .yui-b{margin-right:19.4615em;*margin-right:19.125em;}.yui-t6 .yui-b{float:right;width:23.0769em;*width:22.50em;}.yui-t6 #yui-main .yui-b{margin-right:24.0769em;*margin-right:23.62em;}.yui-t7 #yui-main .yui-b{display:block;margin:0 0 1em 0;}#yui-main .yui-b{float:none;width:auto;}.yui-gb .yui-u,.yui-g .yui-gb .yui-u,.yui-gb .yui-g,.yui-gb .yui-gb,.yui-gb .yui-gc,.yui-gb .yui-gd,.yui-gb .yui-ge,.yui-gb .yui-gf,.yui-gc .yui-u,.yui-gc .yui-g,.yui-gd .yui-u{float:left;}.yui-g .yui-u,.yui-g .yui-g,.yui-g .yui-gb,.yui-g .yui-gc,.yui-g .yui-gd,.yui-g .yui-ge,.yui-g .yui-gf,.yui-gc .yui-u,.yui-gd .yui-g,.yui-g .yui-gc .yui-u,.yui-ge .yui-u,.yui-ge .yui-g,.yui-gf .yui-g,.yui-gf .yui-u{float:right;}.yui-g div.first,.yui-gb div.first,.yui-gc div.first,.yui-gd div.first,.yui-ge div.first,.yui-gf div.first,.yui-g .yui-gc div.first,.yui-g .yui-ge div.first,.yui-gc div.first div.first{float:left;}.yui-g .yui-u,.yui-g .yui-g,.yui-g .yui-gb,.yui-g .yui-gc,.yui-g .yui-gd,.yui-g .yui-ge,.yui-g .yui-gf{width:49.1%;}.yui-gb .yui-u,.yui-g .yui-gb .yui-u,.yui-gb .yui-g,.yui-gb .yui-gb,.yui-gb .yui-gc,.yui-gb .yui-gd,.yui-gb .yui-ge,.yui-gb .yui-gf,.yui-gc .yui-u,.yui-gc .yui-g,.yui-gd .yui-u{width:32%;margin-left:1.99%;}.yui-gb .yui-u{*margin-left:1.9%;*width:31.9%;}.yui-gc div.first,.yui-gd .yui-u{width:66%;}.yui-gd div.first{width:32%;}.yui-ge div.first,.yui-gf .yui-u{width:74.2%;}.yui-ge .yui-u,.yui-gf div.first{width:24%;}.yui-g .yui-gb div.first,.yui-gb div.first,.yui-gc div.first,.yui-gd div.first{margin-left:0;}.yui-g .yui-g .yui-u,.yui-gb .yui-g .yui-u,.yui-gc .yui-g .yui-u,.yui-gd .yui-g .yui-u,.yui-ge .yui-g .yui-u,.yui-gf .yui-g .yui-u{width:49%;*width:48.1%;*margin-left:0;}.yui-g .yui-gb div.first,.yui-gb .yui-gb div.first{*margin-right:0;*width:32%;_width:31.7%;}.yui-g .yui-gc div.first,.yui-gd .yui-g{width:66%;}.yui-gb .yui-g div.first{*margin-right:4%;_margin-right:1.3%;}.yui-gb .yui-gc div.first,.yui-gb .yui-gd div.first{*margin-right:0;}.yui-gb .yui-gb .yui-u,.yui-gb .yui-gc .yui-u{*margin-left:1.8%;_margin-left:4%;}.yui-g .yui-gb .yui-u{_margin-left:1.0%;}.yui-gb .yui-gd .yui-u{*width:66%;_width:61.2%;}.yui-gb .yui-gd div.first{*width:31%;_width:29.5%;}.yui-g .yui-gc .yui-u,.yui-gb .yui-gc .yui-u{width:32%;_float:right;margin-right:0;_margin-left:0;}.yui-gb .yui-gc div.first{width:66%;*float:left;*margin-left:0;}.yui-gb .yui-ge .yui-u,.yui-gb .yui-gf .yui-u{margin:0;}.yui-gb .yui-gb .yui-u{_margin-left:.7%;}.yui-gb .yui-g div.first,.yui-gb .yui-gb div.first{*margin-left:0;}.yui-gc .yui-g .yui-u,.yui-gd .yui-g .yui-u{*width:48.1%;*margin-left:0;}s .yui-gb .yui-gd div.first{width:32%;}.yui-g .yui-gd div.first{_width:29.9%;}.yui-ge .yui-g{width:24%;}.yui-gf .yui-g{width:74.2%;}.yui-gb .yui-ge div.yui-u,.yui-gb .yui-gf div.yui-u{float:right;}.yui-gb .yui-ge div.first,.yui-gb .yui-gf div.first{float:left;}.yui-gb .yui-ge .yui-u,.yui-gb .yui-gf div.first{*width:24%;_width:20%;}.yui-gb .yui-ge div.first,.yui-gb .yui-gf .yui-u{*width:73.5%;_width:65.5%;}.yui-ge div.first .yui-gd .yui-u{width:65%;}.yui-ge div.first .yui-gd div.first{width:32%;}#bd:after,.yui-g:after,.yui-gb:after,.yui-gc:after,.yui-gd:after,.yui-ge:after,.yui-gf:after{content:".";display:block;height:0;clear:both;visibility:hidden;}#bd,.yui-g,.yui-gb,.yui-gc,.yui-gd,.yui-ge,.yui-gf{zoom:1;}
|
testbed/django__django/docs/_theme/djangodocs/theme.conf
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[theme]
|
| 2 |
+
inherit = basic
|
| 3 |
+
stylesheet = default.css
|
| 4 |
+
pygments_style = trac
|
testbed/django__django/docs/faq/admin.txt
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
==============
|
| 2 |
+
FAQ: The admin
|
| 3 |
+
==============
|
| 4 |
+
|
| 5 |
+
I can't log in. When I enter a valid username and password, it just brings up the login page again, with no error messages.
|
| 6 |
+
===========================================================================================================================
|
| 7 |
+
|
| 8 |
+
The login cookie isn't being set correctly, because the domain of the cookie
|
| 9 |
+
sent out by Django doesn't match the domain in your browser. Try setting the
|
| 10 |
+
:setting:`SESSION_COOKIE_DOMAIN` setting to match your domain. For example, if
|
| 11 |
+
you're going to "https://www.example.com/admin/" in your browser, set
|
| 12 |
+
``SESSION_COOKIE_DOMAIN = 'www.example.com'``.
|
| 13 |
+
|
| 14 |
+
I can't log in. When I enter a valid username and password, it brings up the login page again, with a "Please enter a correct username and password" error.
|
| 15 |
+
===========================================================================================================================================================
|
| 16 |
+
|
| 17 |
+
If you're sure your username and password are correct, make sure your user
|
| 18 |
+
account has :attr:`~django.contrib.auth.models.User.is_active` and
|
| 19 |
+
:attr:`~django.contrib.auth.models.User.is_staff` set to True. The admin site
|
| 20 |
+
only allows access to users with those two fields both set to True.
|
| 21 |
+
|
| 22 |
+
How do I automatically set a field's value to the user who last edited the object in the admin?
|
| 23 |
+
===============================================================================================
|
| 24 |
+
|
| 25 |
+
The :class:`~django.contrib.admin.ModelAdmin` class provides customization hooks
|
| 26 |
+
that allow you to transform an object as it saved, using details from the
|
| 27 |
+
request. By extracting the current user from the request, and customizing the
|
| 28 |
+
:meth:`~django.contrib.admin.ModelAdmin.save_model` hook, you can update an
|
| 29 |
+
object to reflect the user that edited it. See :ref:`the documentation on
|
| 30 |
+
ModelAdmin methods <model-admin-methods>` for an example.
|
| 31 |
+
|
| 32 |
+
How do I limit admin access so that objects can only be edited by the users who created them?
|
| 33 |
+
=============================================================================================
|
| 34 |
+
|
| 35 |
+
The :class:`~django.contrib.admin.ModelAdmin` class also provides customization
|
| 36 |
+
hooks that allow you to control the visibility and editability of objects in the
|
| 37 |
+
admin. Using the same trick of extracting the user from the request, the
|
| 38 |
+
:meth:`~django.contrib.admin.ModelAdmin.get_queryset` and
|
| 39 |
+
:meth:`~django.contrib.admin.ModelAdmin.has_change_permission` can be used to
|
| 40 |
+
control the visibility and editability of objects in the admin.
|
| 41 |
+
|
| 42 |
+
My admin-site CSS and images showed up fine using the development server, but they're not displaying when using mod_wsgi.
|
| 43 |
+
=========================================================================================================================
|
| 44 |
+
|
| 45 |
+
See :ref:`serving the admin files <serving-the-admin-files>`
|
| 46 |
+
in the "How to use Django with mod_wsgi" documentation.
|
| 47 |
+
|
| 48 |
+
My "list_filter" contains a ManyToManyField, but the filter doesn't display.
|
| 49 |
+
============================================================================
|
| 50 |
+
|
| 51 |
+
Django won't bother displaying the filter for a ``ManyToManyField`` if there
|
| 52 |
+
are no related objects.
|
| 53 |
+
|
| 54 |
+
For example, if your :attr:`~django.contrib.admin.ModelAdmin.list_filter`
|
| 55 |
+
includes :doc:`sites </ref/contrib/sites>`, and there are no sites in your
|
| 56 |
+
database, it won't display a "Site" filter. In that case, filtering by site
|
| 57 |
+
would be meaningless.
|
| 58 |
+
|
| 59 |
+
Some objects aren't appearing in the admin.
|
| 60 |
+
===========================================
|
| 61 |
+
|
| 62 |
+
Inconsistent row counts may be caused by missing foreign key values or a
|
| 63 |
+
foreign key field incorrectly set to :attr:`null=False
|
| 64 |
+
<django.db.models.Field.null>`. If you have a record with a
|
| 65 |
+
:class:`~django.db.models.ForeignKey` pointing to a nonexistent object and
|
| 66 |
+
that foreign key is included is
|
| 67 |
+
:attr:`~django.contrib.admin.ModelAdmin.list_display`, the record will not be
|
| 68 |
+
shown in the admin changelist because the Django model is declaring an
|
| 69 |
+
integrity constraint that is not implemented at the database level.
|
| 70 |
+
|
| 71 |
+
How can I customize the functionality of the admin interface?
|
| 72 |
+
=============================================================
|
| 73 |
+
|
| 74 |
+
You've got several options. If you want to piggyback on top of an add/change
|
| 75 |
+
form that Django automatically generates, you can attach arbitrary JavaScript
|
| 76 |
+
modules to the page via the model's class Admin :ref:`js parameter
|
| 77 |
+
<modeladmin-asset-definitions>`. That parameter is a list of URLs, as strings,
|
| 78 |
+
pointing to JavaScript modules that will be included within the admin form via
|
| 79 |
+
a ``<script>`` tag.
|
| 80 |
+
|
| 81 |
+
If you want more flexibility than is feasible by tweaking the auto-generated
|
| 82 |
+
forms, feel free to write custom views for the admin. The admin is powered by
|
| 83 |
+
Django itself, and you can write custom views that hook into the authentication
|
| 84 |
+
system, check permissions and do whatever else they need to do.
|
| 85 |
+
|
| 86 |
+
If you want to customize the look-and-feel of the admin interface, read the
|
| 87 |
+
next question.
|
| 88 |
+
|
| 89 |
+
The dynamically-generated admin site is ugly! How can I change it?
|
| 90 |
+
==================================================================
|
| 91 |
+
|
| 92 |
+
We like it, but if you don't agree, you can modify the admin site's
|
| 93 |
+
presentation by editing the CSS stylesheet and/or associated image files. The
|
| 94 |
+
site is built using semantic HTML and plenty of CSS hooks, so any changes you'd
|
| 95 |
+
like to make should be possible by editing the stylesheet.
|
| 96 |
+
|
| 97 |
+
.. _admin-browser-support:
|
| 98 |
+
|
| 99 |
+
What browsers are supported for using the admin?
|
| 100 |
+
================================================
|
| 101 |
+
|
| 102 |
+
The admin provides a fully-functional experience to the recent versions of
|
| 103 |
+
modern, web standards compliant browsers. On desktop this means Chrome, Edge,
|
| 104 |
+
Firefox, Opera, Safari, and others.
|
| 105 |
+
|
| 106 |
+
On mobile and tablet devices, the admin provides a responsive experience for
|
| 107 |
+
web standards compliant browsers. This includes the major browsers on both
|
| 108 |
+
Android and iOS.
|
| 109 |
+
|
| 110 |
+
Depending on feature support, there *may* be minor stylistic differences
|
| 111 |
+
between browsers. These are considered acceptable variations in rendering.
|
testbed/django__django/docs/faq/contributing.txt
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
======================
|
| 2 |
+
FAQ: Contributing code
|
| 3 |
+
======================
|
| 4 |
+
|
| 5 |
+
.. _new-contributors-faq:
|
| 6 |
+
|
| 7 |
+
How can I get started contributing code to Django?
|
| 8 |
+
==================================================
|
| 9 |
+
|
| 10 |
+
Thanks for asking! We've written an entire document devoted to this question.
|
| 11 |
+
It's titled :doc:`Contributing to Django </internals/contributing/index>`.
|
| 12 |
+
|
| 13 |
+
I submitted a bug fix in the ticket system several weeks ago. Why are you ignoring my patch?
|
| 14 |
+
============================================================================================
|
| 15 |
+
|
| 16 |
+
Don't worry: We're not ignoring you!
|
| 17 |
+
|
| 18 |
+
It's important to understand there is a difference between "a ticket is being
|
| 19 |
+
ignored" and "a ticket has not been attended to yet." Django's ticket system
|
| 20 |
+
contains hundreds of open tickets, of various degrees of impact on end-user
|
| 21 |
+
functionality, and Django's developers have to review and prioritize.
|
| 22 |
+
|
| 23 |
+
On top of that: the people who work on Django are all volunteers. As a result,
|
| 24 |
+
the amount of time that we have to work on the framework is limited and will
|
| 25 |
+
vary from week to week depending on our spare time. If we're busy, we may not
|
| 26 |
+
be able to spend as much time on Django as we might want.
|
| 27 |
+
|
| 28 |
+
The best way to make sure tickets do not get hung up on the way to checkin is
|
| 29 |
+
to make it dead easy, even for someone who may not be intimately familiar with
|
| 30 |
+
that area of the code, to understand the problem and verify the fix:
|
| 31 |
+
|
| 32 |
+
* Are there clear instructions on how to reproduce the bug? If this
|
| 33 |
+
touches a dependency (such as Pillow), a contrib module, or a specific
|
| 34 |
+
database, are those instructions clear enough even for someone not
|
| 35 |
+
familiar with it?
|
| 36 |
+
|
| 37 |
+
* If there are several patches attached to the ticket, is it clear what
|
| 38 |
+
each one does, which ones can be ignored and which matter?
|
| 39 |
+
|
| 40 |
+
* Does the patch include a unit test? If not, is there a very clear
|
| 41 |
+
explanation why not? A test expresses succinctly what the problem is,
|
| 42 |
+
and shows that the patch actually fixes it.
|
| 43 |
+
|
| 44 |
+
If your patch stands no chance of inclusion in Django, we won't ignore it --
|
| 45 |
+
we'll just close the ticket. So if your ticket is still open, it doesn't mean
|
| 46 |
+
we're ignoring you; it just means we haven't had time to look at it yet.
|
| 47 |
+
|
| 48 |
+
When and how might I remind the team of a patch I care about?
|
| 49 |
+
=============================================================
|
| 50 |
+
|
| 51 |
+
A polite, well-timed message to the mailing list is one way to get attention.
|
| 52 |
+
To determine the right time, you need to keep an eye on the schedule. If you
|
| 53 |
+
post your message right before a release deadline, you're not likely to get the
|
| 54 |
+
sort of attention you require.
|
| 55 |
+
|
| 56 |
+
Gentle IRC reminders can also work -- again, strategically timed if possible.
|
| 57 |
+
During a bug sprint would be a very good time, for example.
|
| 58 |
+
|
| 59 |
+
Another way to get traction is to pull several related tickets together. When
|
| 60 |
+
someone sits down to review a bug in an area they haven't touched for
|
| 61 |
+
a while, it can take a few minutes to remember all the fine details of how
|
| 62 |
+
that area of code works. If you collect several minor bug fixes together into
|
| 63 |
+
a similarly themed group, you make an attractive target, as the cost of coming
|
| 64 |
+
up to speed on an area of code can be spread over multiple tickets.
|
| 65 |
+
|
| 66 |
+
Please refrain from emailing anyone personally or repeatedly raising the same
|
| 67 |
+
issue over and over again. This sort of behavior will not gain you any
|
| 68 |
+
additional attention -- certainly not the attention that you need in order to
|
| 69 |
+
get your issue addressed.
|
| 70 |
+
|
| 71 |
+
But I've reminded you several times and you keep ignoring my patch!
|
| 72 |
+
===================================================================
|
| 73 |
+
|
| 74 |
+
Seriously - we're not ignoring you. If your patch stands no chance of
|
| 75 |
+
inclusion in Django, we'll close the ticket. For all the other tickets, we
|
| 76 |
+
need to prioritize our efforts, which means that some tickets will be
|
| 77 |
+
addressed before others.
|
| 78 |
+
|
| 79 |
+
One of the criteria that is used to prioritize bug fixes is the number of
|
| 80 |
+
people that will likely be affected by a given bug. Bugs that have the
|
| 81 |
+
potential to affect many people will generally get priority over those that
|
| 82 |
+
are edge cases.
|
| 83 |
+
|
| 84 |
+
Another reason that a bug might be ignored for a while is if the bug is a
|
| 85 |
+
symptom of a larger problem. While we can spend time writing, testing and
|
| 86 |
+
applying lots of little patches, sometimes the right solution is to rebuild. If
|
| 87 |
+
a rebuild or refactor of a particular component has been proposed or is
|
| 88 |
+
underway, you may find that bugs affecting that component will not get as much
|
| 89 |
+
attention. Again, this is a matter of prioritizing scarce resources. By
|
| 90 |
+
concentrating on the rebuild, we can close all the little bugs at once, and
|
| 91 |
+
hopefully prevent other little bugs from appearing in the future.
|
| 92 |
+
|
| 93 |
+
Whatever the reason, please keep in mind that while you may hit a particular
|
| 94 |
+
bug regularly, it doesn't necessarily follow that every single Django user
|
| 95 |
+
will hit the same bug. Different users use Django in different ways, stressing
|
| 96 |
+
different parts of the code under different conditions. When we evaluate the
|
| 97 |
+
relative priorities, we are generally trying to consider the needs of the
|
| 98 |
+
entire community, instead of prioritizing the impact on one particular user.
|
| 99 |
+
This doesn't mean that we think your problem is unimportant -- just that in the
|
| 100 |
+
limited time we have available, we will always err on the side of making 10
|
| 101 |
+
people happy rather than making a single person happy.
|
| 102 |
+
|
| 103 |
+
I'm sure my ticket is absolutely 100% perfect, can I mark it as "Ready For Checkin" myself?
|
| 104 |
+
===========================================================================================
|
| 105 |
+
|
| 106 |
+
Sorry, no. It's always better to get another set of eyes on a ticket. If
|
| 107 |
+
you're having trouble getting that second set of eyes, see questions above.
|
testbed/django__django/docs/faq/general.txt
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
============
|
| 2 |
+
FAQ: General
|
| 3 |
+
============
|
| 4 |
+
|
| 5 |
+
Why does this project exist?
|
| 6 |
+
============================
|
| 7 |
+
|
| 8 |
+
Django grew from a very practical need: World Online, a newspaper web
|
| 9 |
+
operation, is responsible for building intensive web applications on journalism
|
| 10 |
+
deadlines. In the fast-paced newsroom, World Online often has only a matter of
|
| 11 |
+
hours to take a complicated web application from concept to public launch.
|
| 12 |
+
|
| 13 |
+
At the same time, the World Online web developers have consistently been
|
| 14 |
+
perfectionists when it comes to following best practices of web development.
|
| 15 |
+
|
| 16 |
+
In fall 2003, the World Online developers (Adrian Holovaty and Simon Willison)
|
| 17 |
+
ditched PHP and began using Python to develop its websites. As they built
|
| 18 |
+
intensive, richly interactive sites such as Lawrence.com, they began to extract
|
| 19 |
+
a generic web development framework that let them build web applications more
|
| 20 |
+
and more quickly. They tweaked this framework constantly, adding improvements
|
| 21 |
+
over two years.
|
| 22 |
+
|
| 23 |
+
In summer 2005, World Online decided to open-source the resulting software,
|
| 24 |
+
Django. Django would not be possible without a whole host of open-source
|
| 25 |
+
projects -- `Apache`_, `Python`_, and `PostgreSQL`_ to name a few -- and we're
|
| 26 |
+
thrilled to be able to give something back to the open-source community.
|
| 27 |
+
|
| 28 |
+
.. _Apache: https://httpd.apache.org/
|
| 29 |
+
.. _Python: https://www.python.org/
|
| 30 |
+
.. _PostgreSQL: https://www.postgresql.org/
|
| 31 |
+
|
| 32 |
+
What does "Django" mean, and how do you pronounce it?
|
| 33 |
+
=====================================================
|
| 34 |
+
|
| 35 |
+
Django is named after `Django Reinhardt`_, a jazz manouche guitarist from the 1930s
|
| 36 |
+
to early 1950s. To this day, he's considered one of the best guitarists of all time.
|
| 37 |
+
|
| 38 |
+
Listen to his music. You'll like it.
|
| 39 |
+
|
| 40 |
+
Django is pronounced **JANG**-oh. Rhymes with FANG-oh. The "D" is silent.
|
| 41 |
+
|
| 42 |
+
We've also recorded an `audio clip of the pronunciation`_.
|
| 43 |
+
|
| 44 |
+
.. _Django Reinhardt: https://en.wikipedia.org/wiki/Django_Reinhardt
|
| 45 |
+
.. _audio clip of the pronunciation: https://www.red-bean.com/~adrian/django_pronunciation.mp3
|
| 46 |
+
|
| 47 |
+
Is Django stable?
|
| 48 |
+
=================
|
| 49 |
+
|
| 50 |
+
Yes, it's quite stable. Companies like Disqus, Instagram, Pinterest, and
|
| 51 |
+
Mozilla have been using Django for many years. Sites built on Django have
|
| 52 |
+
weathered traffic spikes of over 50 thousand hits per second.
|
| 53 |
+
|
| 54 |
+
Does Django scale?
|
| 55 |
+
==================
|
| 56 |
+
|
| 57 |
+
Yes. Compared to development time, hardware is cheap, and so Django is
|
| 58 |
+
designed to take advantage of as much hardware as you can throw at it.
|
| 59 |
+
|
| 60 |
+
Django uses a "shared-nothing" architecture, which means you can add hardware
|
| 61 |
+
at any level -- database servers, caching servers or web/application servers.
|
| 62 |
+
|
| 63 |
+
The framework cleanly separates components such as its database layer and
|
| 64 |
+
application layer. And it ships with a simple-yet-powerful
|
| 65 |
+
:doc:`cache framework </topics/cache>`.
|
| 66 |
+
|
| 67 |
+
Who's behind this?
|
| 68 |
+
==================
|
| 69 |
+
|
| 70 |
+
Django was originally developed at World Online, the web department of a
|
| 71 |
+
newspaper in Lawrence, Kansas, USA. Django's now run by an international
|
| 72 |
+
`team of volunteers <https://www.djangoproject.com/foundation/teams/>`_.
|
| 73 |
+
|
| 74 |
+
How is Django licensed?
|
| 75 |
+
=======================
|
| 76 |
+
|
| 77 |
+
Django is distributed under :source:`the 3-clause BSD license <LICENSE>`. This
|
| 78 |
+
is an open source license granting broad permissions to modify and redistribute
|
| 79 |
+
Django.
|
| 80 |
+
|
| 81 |
+
Why does Django include Python's license file?
|
| 82 |
+
==============================================
|
| 83 |
+
|
| 84 |
+
Django includes code from the Python standard library. Python is distributed
|
| 85 |
+
under a permissive open source license. :source:`A copy of the Python license
|
| 86 |
+
<LICENSE.python>` is included with Django for compliance with Python's terms.
|
| 87 |
+
|
| 88 |
+
Which sites use Django?
|
| 89 |
+
=======================
|
| 90 |
+
|
| 91 |
+
`DjangoSites.org`_ features a constantly growing list of Django-powered sites.
|
| 92 |
+
|
| 93 |
+
.. _DjangoSites.org: https://djangosites.org
|
| 94 |
+
|
| 95 |
+
.. _faq-mtv:
|
| 96 |
+
|
| 97 |
+
Django appears to be a MVC framework, but you call the Controller the "view", and the View the "template". How come you don't use the standard names?
|
| 98 |
+
=====================================================================================================================================================
|
| 99 |
+
|
| 100 |
+
Well, the standard names are debatable.
|
| 101 |
+
|
| 102 |
+
In our interpretation of MVC, the "view" describes the data that gets presented
|
| 103 |
+
to the user. It's not necessarily *how* the data *looks*, but *which* data is
|
| 104 |
+
presented. The view describes *which data you see*, not *how you see it.* It's
|
| 105 |
+
a subtle distinction.
|
| 106 |
+
|
| 107 |
+
So, in our case, a "view" is the Python callback function for a particular URL,
|
| 108 |
+
because that callback function describes which data is presented.
|
| 109 |
+
|
| 110 |
+
Furthermore, it's sensible to separate content from presentation -- which is
|
| 111 |
+
where templates come in. In Django, a "view" describes which data is presented,
|
| 112 |
+
but a view normally delegates to a template, which describes *how* the data is
|
| 113 |
+
presented.
|
| 114 |
+
|
| 115 |
+
Where does the "controller" fit in, then? In Django's case, it's probably the
|
| 116 |
+
framework itself: the machinery that sends a request to the appropriate view,
|
| 117 |
+
according to the Django URL configuration.
|
| 118 |
+
|
| 119 |
+
If you're hungry for acronyms, you might say that Django is a "MTV" framework
|
| 120 |
+
-- that is, "model", "template", and "view." That breakdown makes much more
|
| 121 |
+
sense.
|
| 122 |
+
|
| 123 |
+
At the end of the day, it comes down to getting stuff done. And, regardless of
|
| 124 |
+
how things are named, Django gets stuff done in a way that's most logical to
|
| 125 |
+
us.
|
| 126 |
+
|
| 127 |
+
<Framework X> does <feature Y> -- why doesn't Django?
|
| 128 |
+
=====================================================
|
| 129 |
+
|
| 130 |
+
We're well aware that there are other awesome web frameworks out there, and
|
| 131 |
+
we're not averse to borrowing ideas where appropriate. However, Django was
|
| 132 |
+
developed precisely because we were unhappy with the status quo, so please be
|
| 133 |
+
aware that "because <Framework X> does it" is not going to be sufficient reason
|
| 134 |
+
to add a given feature to Django.
|
| 135 |
+
|
| 136 |
+
Why did you write all of Django from scratch, instead of using other Python libraries?
|
| 137 |
+
======================================================================================
|
| 138 |
+
|
| 139 |
+
When Django was originally written, Adrian and Simon spent quite a bit of time
|
| 140 |
+
exploring the various Python web frameworks available.
|
| 141 |
+
|
| 142 |
+
In our opinion, none of them were completely up to snuff.
|
| 143 |
+
|
| 144 |
+
We're picky. You might even call us perfectionists. (With deadlines.)
|
| 145 |
+
|
| 146 |
+
Over time, we stumbled across open-source libraries that did things we'd
|
| 147 |
+
already implemented. It was reassuring to see other people solving similar
|
| 148 |
+
problems in similar ways, but it was too late to integrate outside code: We'd
|
| 149 |
+
already written, tested and implemented our own framework bits in several
|
| 150 |
+
production settings -- and our own code met our needs delightfully.
|
| 151 |
+
|
| 152 |
+
In most cases, however, we found that existing frameworks/tools inevitably had
|
| 153 |
+
some sort of fundamental, fatal flaw that made us squeamish. No tool fit our
|
| 154 |
+
philosophies 100%.
|
| 155 |
+
|
| 156 |
+
Like we said: We're picky.
|
| 157 |
+
|
| 158 |
+
We've documented our philosophies on the
|
| 159 |
+
:doc:`design philosophies page </misc/design-philosophies>`.
|
| 160 |
+
|
| 161 |
+
Is Django a content-management-system (CMS)?
|
| 162 |
+
============================================
|
| 163 |
+
|
| 164 |
+
No, Django is not a CMS, or any sort of "turnkey product" in and of itself.
|
| 165 |
+
It's a web framework; it's a programming tool that lets you build websites.
|
| 166 |
+
|
| 167 |
+
For example, it doesn't make much sense to compare Django to something like
|
| 168 |
+
Drupal_, because Django is something you use to *create* things like Drupal.
|
| 169 |
+
|
| 170 |
+
Yes, Django's automatic admin site is fantastic and timesaving -- but the admin
|
| 171 |
+
site is one module of Django the framework. Furthermore, although Django has
|
| 172 |
+
special conveniences for building "CMS-y" apps, that doesn't mean it's not just
|
| 173 |
+
as appropriate for building "non-CMS-y" apps (whatever that means!).
|
| 174 |
+
|
| 175 |
+
.. _Drupal: https://www.drupal.org/
|
| 176 |
+
|
| 177 |
+
How can I download the Django documentation to read it offline?
|
| 178 |
+
===============================================================
|
| 179 |
+
|
| 180 |
+
The Django docs are available in the ``docs`` directory of each Django tarball
|
| 181 |
+
release. These docs are in reST (reStructuredText) format, and each text file
|
| 182 |
+
corresponds to a web page on the official Django site.
|
| 183 |
+
|
| 184 |
+
Because the documentation is :source:`stored in revision control <docs>`, you
|
| 185 |
+
can browse documentation changes just like you can browse code changes.
|
| 186 |
+
|
| 187 |
+
Technically, the docs on Django's site are generated from the latest development
|
| 188 |
+
versions of those reST documents, so the docs on the Django site may offer more
|
| 189 |
+
information than the docs that come with the latest Django release.
|
| 190 |
+
|
| 191 |
+
How do I cite Django?
|
| 192 |
+
=====================
|
| 193 |
+
|
| 194 |
+
It's difficult to give an official citation format, for two reasons: citation
|
| 195 |
+
formats can vary wildly between publications, and citation standards for
|
| 196 |
+
software are still a matter of some debate.
|
| 197 |
+
|
| 198 |
+
For example, `APA style`_, would dictate something like:
|
| 199 |
+
|
| 200 |
+
.. code-block:: text
|
| 201 |
+
|
| 202 |
+
Django (Version 1.5) [Computer Software]. (2013). Retrieved from https://www.djangoproject.com/.
|
| 203 |
+
|
| 204 |
+
However, the only true guide is what your publisher will accept, so get a copy
|
| 205 |
+
of those guidelines and fill in the gaps as best you can.
|
| 206 |
+
|
| 207 |
+
If your referencing style guide requires a publisher name, use "Django Software
|
| 208 |
+
Foundation".
|
| 209 |
+
|
| 210 |
+
If you need a publishing location, use "Lawrence, Kansas".
|
| 211 |
+
|
| 212 |
+
If you need a web address, use https://www.djangoproject.com/.
|
| 213 |
+
|
| 214 |
+
If you need a name, just use "Django", without any tagline.
|
| 215 |
+
|
| 216 |
+
If you need a publication date, use the year of release of the version you're
|
| 217 |
+
referencing (e.g., 2013 for v1.5)
|
| 218 |
+
|
| 219 |
+
.. _APA style: https://apastyle.apa.org/
|
testbed/django__django/docs/faq/help.txt
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
=================
|
| 2 |
+
FAQ: Getting Help
|
| 3 |
+
=================
|
| 4 |
+
|
| 5 |
+
How do I do X? Why doesn't Y work? Where can I go to get help?
|
| 6 |
+
==============================================================
|
| 7 |
+
|
| 8 |
+
First, please check if your question is answered on the :doc:`FAQ
|
| 9 |
+
</faq/index>`. Also, search for answers using your favorite search engine, and
|
| 10 |
+
in `the forum`_.
|
| 11 |
+
|
| 12 |
+
.. _`the forum`: https://forum.djangoproject.com/
|
| 13 |
+
|
| 14 |
+
If you can't find an answer, please take a few minutes to formulate your
|
| 15 |
+
question well. Explaining the problems you are facing clearly will help others
|
| 16 |
+
help you. See the StackOverflow guide on `asking good questions`_.
|
| 17 |
+
|
| 18 |
+
.. _`asking good questions`: https://stackoverflow.com/help/how-to-ask
|
| 19 |
+
|
| 20 |
+
Then, please post it in one of the following channels:
|
| 21 |
+
|
| 22 |
+
* The Django Forum section `"Using Django"`_. This is for web-based
|
| 23 |
+
discussions.
|
| 24 |
+
* The |django-users| mailing list. This is for email-based discussions.
|
| 25 |
+
* The `#django IRC channel`_ on the Libera.Chat IRC network. This is for
|
| 26 |
+
chat-based discussions. If you're new to IRC, see the `Libera.Chat
|
| 27 |
+
documentation`_ for different ways to connect.
|
| 28 |
+
|
| 29 |
+
.. _`"Using Django"`: https://forum.djangoproject.com/c/users/6
|
| 30 |
+
.. _#django IRC channel: https://web.libera.chat/#django
|
| 31 |
+
.. _Libera.Chat documentation: https://libera.chat/guides/connect
|
| 32 |
+
|
| 33 |
+
In all these channels please abide by the `Django Code of Conduct`_. In
|
| 34 |
+
summary, being friendly and patient, considerate, respectful, and careful in
|
| 35 |
+
your choice of words.
|
| 36 |
+
|
| 37 |
+
.. _Django Code of Conduct: https://www.djangoproject.com/conduct/
|
| 38 |
+
|
| 39 |
+
.. _message-does-not-appear-on-django-users:
|
| 40 |
+
|
| 41 |
+
Why hasn't my message appeared on *django-users*?
|
| 42 |
+
=================================================
|
| 43 |
+
|
| 44 |
+
|django-users| has a lot of subscribers. This is good for the community, as
|
| 45 |
+
it means many people are available to contribute answers to questions.
|
| 46 |
+
Unfortunately, it also means that |django-users| is an attractive target for
|
| 47 |
+
spammers.
|
| 48 |
+
|
| 49 |
+
In order to combat the spam problem, when you join the |django-users| mailing
|
| 50 |
+
list, we manually moderate the first message you send to the list. This means
|
| 51 |
+
that spammers get caught, but it also means that your first question to the
|
| 52 |
+
list might take a little longer to get answered. We apologize for any
|
| 53 |
+
inconvenience that this policy may cause.
|
| 54 |
+
|
| 55 |
+
Nobody answered my question! What should I do?
|
| 56 |
+
==============================================
|
| 57 |
+
|
| 58 |
+
Try making your question more specific, or provide a better example of your
|
| 59 |
+
problem.
|
| 60 |
+
|
| 61 |
+
As with most open-source projects, the folks on these channels are volunteers.
|
| 62 |
+
If nobody has answered your question, it may be because nobody knows the
|
| 63 |
+
answer, it may be because nobody can understand the question, or it may be that
|
| 64 |
+
everybody that can help is busy.
|
| 65 |
+
|
| 66 |
+
You can also try asking on a different channel. But please don't post your
|
| 67 |
+
question in all three channels in quick succession.
|
| 68 |
+
|
| 69 |
+
You might notice we have a second mailing list, called |django-developers|.
|
| 70 |
+
This list is for discussion of the development of Django itself. Please don't
|
| 71 |
+
email support questions to this mailing list. Asking a tech support question
|
| 72 |
+
there is considered impolite, and you will likely be directed to ask on
|
| 73 |
+
|django-users|.
|
| 74 |
+
|
| 75 |
+
I think I've found a bug! What should I do?
|
| 76 |
+
===========================================
|
| 77 |
+
|
| 78 |
+
Detailed instructions on how to handle a potential bug can be found in our
|
| 79 |
+
:ref:`Guide to contributing to Django <reporting-bugs>`.
|
| 80 |
+
|
| 81 |
+
I think I've found a security problem! What should I do?
|
| 82 |
+
========================================================
|
| 83 |
+
|
| 84 |
+
If you think you've found a security problem with Django, please send a message
|
| 85 |
+
to security@djangoproject.com. This is a private list only open to long-time,
|
| 86 |
+
highly trusted Django developers, and its archives are not publicly readable.
|
| 87 |
+
|
| 88 |
+
Due to the sensitive nature of security issues, we ask that if you think you
|
| 89 |
+
have found a security problem, *please* don't post a message on the forum, IRC,
|
| 90 |
+
or one of the public mailing lists. Django has a
|
| 91 |
+
:ref:`policy for handling security issues <reporting-security-issues>`;
|
| 92 |
+
while a defect is outstanding, we would like to minimize any damage that
|
| 93 |
+
could be inflicted through public knowledge of that defect.
|
testbed/django__django/docs/faq/index.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
==========
|
| 2 |
+
Django FAQ
|
| 3 |
+
==========
|
| 4 |
+
|
| 5 |
+
.. toctree::
|
| 6 |
+
:maxdepth: 2
|
| 7 |
+
|
| 8 |
+
general
|
| 9 |
+
install
|
| 10 |
+
usage
|
| 11 |
+
help
|
| 12 |
+
models
|
| 13 |
+
admin
|
| 14 |
+
contributing
|
| 15 |
+
troubleshooting
|
testbed/django__django/docs/faq/install.txt
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
=================
|
| 2 |
+
FAQ: Installation
|
| 3 |
+
=================
|
| 4 |
+
|
| 5 |
+
How do I get started?
|
| 6 |
+
=====================
|
| 7 |
+
|
| 8 |
+
#. `Download the code`_.
|
| 9 |
+
#. Install Django (read the :doc:`installation guide </intro/install>`).
|
| 10 |
+
#. Walk through the :doc:`tutorial </intro/tutorial01>`.
|
| 11 |
+
#. Check out the rest of the :doc:`documentation </index>`, and `ask questions`_ if you
|
| 12 |
+
run into trouble.
|
| 13 |
+
|
| 14 |
+
.. _`Download the code`: https://www.djangoproject.com/download/
|
| 15 |
+
.. _ask questions: https://www.djangoproject.com/community/
|
| 16 |
+
|
| 17 |
+
What are Django's prerequisites?
|
| 18 |
+
================================
|
| 19 |
+
|
| 20 |
+
Django requires Python. See the table in the next question for the versions of
|
| 21 |
+
Python that work with each version of Django. Other Python libraries may be
|
| 22 |
+
required for some use cases, but you'll receive an error about them as they're
|
| 23 |
+
needed.
|
| 24 |
+
|
| 25 |
+
For a development environment -- if you just want to experiment with Django --
|
| 26 |
+
you don't need to have a separate web server installed or database server.
|
| 27 |
+
|
| 28 |
+
Django comes with its own :djadmin:`lightweight development server<runserver>`.
|
| 29 |
+
For a production environment, Django follows the WSGI spec, :pep:`3333`, which
|
| 30 |
+
means it can run on a variety of web servers. See :doc:`Deploying Django
|
| 31 |
+
</howto/deployment/index>` for more information.
|
| 32 |
+
|
| 33 |
+
Django runs `SQLite`_ by default, which is included in Python installations.
|
| 34 |
+
For a production environment, we recommend PostgreSQL_; but we also officially
|
| 35 |
+
support MariaDB_, MySQL_, `SQLite`_, and Oracle_. See :doc:`Supported Databases
|
| 36 |
+
</ref/databases>` for more information.
|
| 37 |
+
|
| 38 |
+
.. _Python: https://www.python.org/
|
| 39 |
+
.. _PostgreSQL: https://www.postgresql.org/
|
| 40 |
+
.. _MariaDB: https://mariadb.org/
|
| 41 |
+
.. _MySQL: https://www.mysql.com/
|
| 42 |
+
.. _`SQLite`: https://www.sqlite.org/
|
| 43 |
+
.. _Oracle: https://www.oracle.com/
|
| 44 |
+
|
| 45 |
+
.. _faq-python-version-support:
|
| 46 |
+
|
| 47 |
+
What Python version can I use with Django?
|
| 48 |
+
==========================================
|
| 49 |
+
|
| 50 |
+
============== ===============
|
| 51 |
+
Django version Python versions
|
| 52 |
+
============== ===============
|
| 53 |
+
3.2 3.6, 3.7, 3.8, 3.9, 3.10 (added in 3.2.9)
|
| 54 |
+
4.0 3.8, 3.9, 3.10
|
| 55 |
+
4.1 3.8, 3.9, 3.10, 3.11 (added in 4.1.3)
|
| 56 |
+
4.2 3.8, 3.9, 3.10, 3.11
|
| 57 |
+
5.0 3.10, 3.11, 3.12
|
| 58 |
+
============== ===============
|
| 59 |
+
|
| 60 |
+
For each version of Python, only the latest micro release (A.B.C) is officially
|
| 61 |
+
supported. You can find the latest micro version for each series on the `Python
|
| 62 |
+
download page <https://www.python.org/downloads/>`_.
|
| 63 |
+
|
| 64 |
+
Typically, we will support a Python version up to and including the first
|
| 65 |
+
Django LTS release whose security support ends after security support for that
|
| 66 |
+
version of Python ends. For example, Python 3.3 security support ended
|
| 67 |
+
September 2017 and Django 1.8 LTS security support ended April 2018. Therefore
|
| 68 |
+
Django 1.8 is the last version to support Python 3.3.
|
| 69 |
+
|
| 70 |
+
What Python version should I use with Django?
|
| 71 |
+
=============================================
|
| 72 |
+
|
| 73 |
+
Since newer versions of Python are often faster, have more features, and are
|
| 74 |
+
better supported, the latest version of Python 3 is recommended.
|
| 75 |
+
|
| 76 |
+
You don't lose anything in Django by using an older release, but you don't take
|
| 77 |
+
advantage of the improvements and optimizations in newer Python releases.
|
| 78 |
+
Third-party applications for use with Django are free to set their own version
|
| 79 |
+
requirements.
|
| 80 |
+
|
| 81 |
+
Should I use the stable version or development version?
|
| 82 |
+
=======================================================
|
| 83 |
+
|
| 84 |
+
Generally, if you're using code in production, you should be using a
|
| 85 |
+
stable release. The Django project publishes a full stable release
|
| 86 |
+
every eight months or so, with bugfix updates in between. These stable
|
| 87 |
+
releases contain the API that is covered by our backwards
|
| 88 |
+
compatibility guarantees; if you write code against stable releases,
|
| 89 |
+
you shouldn't have any problems upgrading when the next official
|
| 90 |
+
version is released.
|
testbed/django__django/docs/faq/models.txt
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
=========================
|
| 2 |
+
FAQ: Databases and models
|
| 3 |
+
=========================
|
| 4 |
+
|
| 5 |
+
.. _faq-see-raw-sql-queries:
|
| 6 |
+
|
| 7 |
+
How can I see the raw SQL queries Django is running?
|
| 8 |
+
====================================================
|
| 9 |
+
|
| 10 |
+
Make sure your Django :setting:`DEBUG` setting is set to ``True``.
|
| 11 |
+
Then do this:
|
| 12 |
+
|
| 13 |
+
.. code-block:: pycon
|
| 14 |
+
|
| 15 |
+
>>> from django.db import connection
|
| 16 |
+
>>> connection.queries
|
| 17 |
+
[{'sql': 'SELECT polls_polls.id, polls_polls.question, polls_polls.pub_date FROM polls_polls',
|
| 18 |
+
'time': '0.002'}]
|
| 19 |
+
|
| 20 |
+
``connection.queries`` is only available if :setting:`DEBUG` is ``True``.
|
| 21 |
+
It's a list of dictionaries in order of query execution. Each dictionary has
|
| 22 |
+
the following:
|
| 23 |
+
|
| 24 |
+
* ``sql`` - The raw SQL statement
|
| 25 |
+
* ``time`` - How long the statement took to execute, in seconds.
|
| 26 |
+
|
| 27 |
+
``connection.queries`` includes all SQL statements -- INSERTs, UPDATES,
|
| 28 |
+
SELECTs, etc. Each time your app hits the database, the query will be recorded.
|
| 29 |
+
|
| 30 |
+
If you are using :doc:`multiple databases</topics/db/multi-db>`, you can use the
|
| 31 |
+
same interface on each member of the ``connections`` dictionary:
|
| 32 |
+
|
| 33 |
+
.. code-block:: pycon
|
| 34 |
+
|
| 35 |
+
>>> from django.db import connections
|
| 36 |
+
>>> connections["my_db_alias"].queries
|
| 37 |
+
|
| 38 |
+
If you need to clear the query list manually at any point in your functions,
|
| 39 |
+
call ``reset_queries()``, like this::
|
| 40 |
+
|
| 41 |
+
from django.db import reset_queries
|
| 42 |
+
|
| 43 |
+
reset_queries()
|
| 44 |
+
|
| 45 |
+
Can I use Django with a preexisting database?
|
| 46 |
+
=============================================
|
| 47 |
+
|
| 48 |
+
Yes. See :doc:`Integrating with a legacy database </howto/legacy-databases>`.
|
| 49 |
+
|
| 50 |
+
If I make changes to a model, how do I update the database?
|
| 51 |
+
===========================================================
|
| 52 |
+
|
| 53 |
+
Take a look at Django's support for :mod:`schema migrations
|
| 54 |
+
<django.db.migrations>`.
|
| 55 |
+
|
| 56 |
+
If you don't mind clearing data, your project's ``manage.py`` utility has a
|
| 57 |
+
:djadmin:`flush` option to reset the database to the state it was in
|
| 58 |
+
immediately after :djadmin:`migrate` was executed.
|
| 59 |
+
|
| 60 |
+
Do Django models support multiple-column primary keys?
|
| 61 |
+
======================================================
|
| 62 |
+
|
| 63 |
+
No. Only single-column primary keys are supported.
|
| 64 |
+
|
| 65 |
+
But this isn't an issue in practice, because there's nothing stopping you from
|
| 66 |
+
adding other constraints (using the ``unique_together`` model option or
|
| 67 |
+
creating the constraint directly in your database), and enforcing the
|
| 68 |
+
uniqueness at that level. Single-column primary keys are needed for things such
|
| 69 |
+
as the admin interface to work; e.g., you need a single value to specify
|
| 70 |
+
an object to edit or delete.
|
| 71 |
+
|
| 72 |
+
Does Django support NoSQL databases?
|
| 73 |
+
====================================
|
| 74 |
+
|
| 75 |
+
NoSQL databases are not officially supported by Django itself. There are,
|
| 76 |
+
however, a number of side projects and forks which allow NoSQL functionality in
|
| 77 |
+
Django.
|
| 78 |
+
|
| 79 |
+
You can take a look on `the wiki page`_ which discusses some projects.
|
| 80 |
+
|
| 81 |
+
.. _the wiki page: https://code.djangoproject.com/wiki/NoSqlSupport
|
| 82 |
+
|
| 83 |
+
How do I add database-specific options to my CREATE TABLE statements, such as specifying MyISAM as the table type?
|
| 84 |
+
==================================================================================================================
|
| 85 |
+
|
| 86 |
+
We try to avoid adding special cases in the Django code to accommodate all the
|
| 87 |
+
database-specific options such as table type, etc. If you'd like to use any of
|
| 88 |
+
these options, create a migration with a
|
| 89 |
+
:class:`~django.db.migrations.operations.RunSQL` operation that contains
|
| 90 |
+
``ALTER TABLE`` statements that do what you want to do.
|
| 91 |
+
|
| 92 |
+
For example, if you're using MySQL and want your tables to use the MyISAM table
|
| 93 |
+
type, use the following SQL:
|
| 94 |
+
|
| 95 |
+
.. code-block:: sql
|
| 96 |
+
|
| 97 |
+
ALTER TABLE myapp_mytable ENGINE=MyISAM;
|
testbed/django__django/docs/faq/troubleshooting.txt
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
===============
|
| 2 |
+
Troubleshooting
|
| 3 |
+
===============
|
| 4 |
+
|
| 5 |
+
This page contains some advice about errors and problems commonly encountered
|
| 6 |
+
during the development of Django applications.
|
| 7 |
+
|
| 8 |
+
.. _troubleshooting-django-admin:
|
| 9 |
+
|
| 10 |
+
Problems running ``django-admin``
|
| 11 |
+
=================================
|
| 12 |
+
|
| 13 |
+
``command not found: django-admin``
|
| 14 |
+
-----------------------------------
|
| 15 |
+
|
| 16 |
+
:doc:`django-admin </ref/django-admin>` should be on your system path if you
|
| 17 |
+
installed Django via ``pip``. If it's not in your path, ensure you have your
|
| 18 |
+
virtual environment activated and you can try running the equivalent command
|
| 19 |
+
``python -m django``.
|
| 20 |
+
|
| 21 |
+
macOS permissions
|
| 22 |
+
-----------------
|
| 23 |
+
|
| 24 |
+
If you're using macOS, you may see the message "permission denied" when
|
| 25 |
+
you try to run ``django-admin``. This is because, on Unix-based systems like
|
| 26 |
+
macOS, a file must be marked as "executable" before it can be run as a program.
|
| 27 |
+
To do this, open Terminal.app and navigate (using the ``cd`` command) to the
|
| 28 |
+
directory where :doc:`django-admin </ref/django-admin>` is installed, then
|
| 29 |
+
run the command ``sudo chmod +x django-admin``.
|
| 30 |
+
|
| 31 |
+
Miscellaneous
|
| 32 |
+
=============
|
| 33 |
+
|
| 34 |
+
I'm getting a ``UnicodeDecodeError``. What am I doing wrong?
|
| 35 |
+
------------------------------------------------------------
|
| 36 |
+
|
| 37 |
+
This class of errors happen when a bytestring containing non-ASCII sequences is
|
| 38 |
+
transformed into a Unicode string and the specified encoding is incorrect. The
|
| 39 |
+
output generally looks like this:
|
| 40 |
+
|
| 41 |
+
.. code-block:: pytb
|
| 42 |
+
|
| 43 |
+
UnicodeDecodeError: 'ascii' codec can't decode byte 0x?? in position ?:
|
| 44 |
+
ordinal not in range(128)
|
| 45 |
+
|
| 46 |
+
The resolution mostly depends on the context, however here are two common
|
| 47 |
+
pitfalls producing this error:
|
| 48 |
+
|
| 49 |
+
* Your system locale may be a default ASCII locale, like the "C" locale on
|
| 50 |
+
UNIX-like systems (can be checked by the ``locale`` command). If it's the
|
| 51 |
+
case, please refer to your system documentation to learn how you can change
|
| 52 |
+
this to a UTF-8 locale.
|
| 53 |
+
|
| 54 |
+
Related resources:
|
| 55 |
+
|
| 56 |
+
* :doc:`Unicode in Django </ref/unicode>`
|
| 57 |
+
* https://wiki.python.org/moin/UnicodeDecodeError
|