änderung1
This commit is contained in:
1 parent
cc1d096bc3
commit
cbdda613b7
2098 files changed
+274524
No files matched your search
@@ -0,0 +1,11 @@
|
||||
"""
|
||||
Django validation and HTML form handling.
|
||||
"""
|
||||
|
||||
from django.core.exceptions import ValidationError # NOQA
|
||||
from django.forms.boundfield import * # NOQA
|
||||
from django.forms.fields import * # NOQA
|
||||
from django.forms.forms import * # NOQA
|
||||
from django.forms.formsets import * # NOQA
|
||||
from django.forms.models import * # NOQA
|
||||
from django.forms.widgets import * # NOQA
|
||||
@@ -0,0 +1 @@
|
||||
{% for name, value in widget.attrs.items() %}{% if value is not sameas False %} {{ name }}{% if value is not sameas True %}="{{ value }}"{% endif %}{% endif %}{% endfor %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/multiple_input.html" %}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{% if widget.is_initial %}{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a>{% if not widget.required %}
|
||||
<input type="checkbox" name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}">
|
||||
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label>{% endif %}<br>
|
||||
{{ widget.input_text }}:{% endif %}
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
|
||||
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
@@ -0,0 +1 @@
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}>
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% for widget in widget.subwidgets -%}{% include widget.template_name %}{%- endfor %}
|
||||
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/multiple_input.html" %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input_option.html" %}
|
||||
@@ -0,0 +1,5 @@
|
||||
<select name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>{% for group_name, group_choices, group_index in widget.optgroups %}{% if group_name %}
|
||||
<optgroup label="{{ group_name }}">{% endif %}{% for widget in group_choices %}
|
||||
{% include widget.template_name %}{% endfor %}{% if group_name %}
|
||||
</optgroup>{% endif %}{% endfor %}
|
||||
</select>
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include 'django/forms/widgets/multiwidget.html' %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<option value="{{ widget.value }}"{% include "django/forms/widgets/attrs.html" %}>{{ widget.label }}</option>
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include 'django/forms/widgets/multiwidget.html' %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include 'django/forms/widgets/multiwidget.html' %}
|
||||
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
File diff suppressed because it is too large.
Load diff
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/multiple_input.html" %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
<input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}>
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% if widget.wrap_label %}<label{% if widget.attrs.id %} for="{{ widget.attrs.id }}"{% endif %}>{% endif %}{% include "django/forms/widgets/input.html" %}{% if widget.wrap_label %} {{ widget.label }}</label>{% endif %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/multiwidget.html" %}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{% with id=widget.attrs.id %}<ul{% if id %} id="{{ id }}"{% endif %}{% if widget.attrs.class %} class="{{ widget.attrs.class }}"{% endif %}>{% for group, options, index in widget.optgroups %}{% if group %}
|
||||
<li>{{ group }}<ul{% if id %} id="{{ id }}_{{ index }}"{% endif %}>{% endif %}{% for option in options %}
|
||||
<li>{% include option.template_name with widget=option %}</li>{% endfor %}{% if group %}
|
||||
</ul></li>{% endif %}{% endfor %}
|
||||
</ul>{% endwith %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% spaceless %}{% for widget in widget.subwidgets %}{% include widget.template_name %}{% endfor %}{% endspaceless %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input_option.html" %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include 'django/forms/widgets/multiwidget.html' %}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{% include 'django/forms/widgets/multiwidget.html' %}
|
||||
@@ -0,0 +1 @@
|
||||
{% include "django/forms/widgets/input.html" %}
|
||||
@@ -0,0 +1,178 @@
|
||||
import json
|
||||
from collections import UserList
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError # backwards compatibility
|
||||
from django.utils import timezone
|
||||
from django.utils.html import escape, format_html, format_html_join, html_safe
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
def pretty_name(name):
|
||||
"""Convert 'first_name' to 'First name'."""
|
||||
if not name:
|
||||
return ''
|
||||
return name.replace('_', ' ').capitalize()
|
||||
|
||||
|
||||
def flatatt(attrs):
|
||||
"""
|
||||
Convert a dictionary of attributes to a single string.
|
||||
The returned string will contain a leading space followed by key="value",
|
||||
XML-style pairs. In the case of a boolean value, the key will appear
|
||||
without a value. It is assumed that the keys do not need to be
|
||||
XML-escaped. If the passed dictionary is empty, then return an empty
|
||||
string.
|
||||
|
||||
The result is passed through 'mark_safe' (by way of 'format_html_join').
|
||||
"""
|
||||
key_value_attrs = []
|
||||
boolean_attrs = []
|
||||
for attr, value in attrs.items():
|
||||
if isinstance(value, bool):
|
||||
if value:
|
||||
boolean_attrs.append((attr,))
|
||||
elif value is not None:
|
||||
key_value_attrs.append((attr, value))
|
||||
|
||||
return (
|
||||
format_html_join('', ' {}="{}"', sorted(key_value_attrs)) +
|
||||
format_html_join('', ' {}', sorted(boolean_attrs))
|
||||
)
|
||||
|
||||
|
||||
@html_safe
|
||||
class ErrorDict(dict):
|
||||
"""
|
||||
A collection of errors that knows how to display itself in various formats.
|
||||
|
||||
The dictionary keys are the field names, and the values are the errors.
|
||||
"""
|
||||
def as_data(self):
|
||||
return {f: e.as_data() for f, e in self.items()}
|
||||
|
||||
def get_json_data(self, escape_html=False):
|
||||
return {f: e.get_json_data(escape_html) for f, e in self.items()}
|
||||
|
||||
def as_json(self, escape_html=False):
|
||||
return json.dumps(self.get_json_data(escape_html))
|
||||
|
||||
def as_ul(self):
|
||||
if not self:
|
||||
return ''
|
||||
return format_html(
|
||||
'<ul class="errorlist">{}</ul>',
|
||||
format_html_join('', '<li>{}{}</li>', self.items())
|
||||
)
|
||||
|
||||
def as_text(self):
|
||||
output = []
|
||||
for field, errors in self.items():
|
||||
output.append('* %s' % field)
|
||||
output.append('\n'.join(' * %s' % e for e in errors))
|
||||
return '\n'.join(output)
|
||||
|
||||
def __str__(self):
|
||||
return self.as_ul()
|
||||
|
||||
|
||||
@html_safe
|
||||
class ErrorList(UserList, list):
|
||||
"""
|
||||
A collection of errors that knows how to display itself in various formats.
|
||||
"""
|
||||
def __init__(self, initlist=None, error_class=None):
|
||||
super().__init__(initlist)
|
||||
|
||||
if error_class is None:
|
||||
self.error_class = 'errorlist'
|
||||
else:
|
||||
self.error_class = 'errorlist {}'.format(error_class)
|
||||
|
||||
def as_data(self):
|
||||
return ValidationError(self.data).error_list
|
||||
|
||||
def get_json_data(self, escape_html=False):
|
||||
errors = []
|
||||
for error in self.as_data():
|
||||
message = next(iter(error))
|
||||
errors.append({
|
||||
'message': escape(message) if escape_html else message,
|
||||
'code': error.code or '',
|
||||
})
|
||||
return errors
|
||||
|
||||
def as_json(self, escape_html=False):
|
||||
return json.dumps(self.get_json_data(escape_html))
|
||||
|
||||
def as_ul(self):
|
||||
if not self.data:
|
||||
return ''
|
||||
|
||||
return format_html(
|
||||
'<ul class="{}">{}</ul>',
|
||||
self.error_class,
|
||||
format_html_join('', '<li>{}</li>', ((e,) for e in self))
|
||||
)
|
||||
|
||||
def as_text(self):
|
||||
return '\n'.join('* %s' % e for e in self)
|
||||
|
||||
def __str__(self):
|
||||
return self.as_ul()
|
||||
|
||||
def __repr__(self):
|
||||
return repr(list(self))
|
||||
|
||||
def __contains__(self, item):
|
||||
return item in list(self)
|
||||
|
||||
def __eq__(self, other):
|
||||
return list(self) == other
|
||||
|
||||
def __getitem__(self, i):
|
||||
error = self.data[i]
|
||||
if isinstance(error, ValidationError):
|
||||
return next(iter(error))
|
||||
return error
|
||||
|
||||
def __reduce_ex__(self, *args, **kwargs):
|
||||
# The `list` reduce function returns an iterator as the fourth element
|
||||
# that is normally used for repopulating. Since we only inherit from
|
||||
# `list` for `isinstance` backward compatibility (Refs #17413) we
|
||||
# nullify this iterator as it would otherwise result in duplicate
|
||||
# entries. (Refs #23594)
|
||||
info = super(UserList, self).__reduce_ex__(*args, **kwargs)
|
||||
return info[:3] + (None, None)
|
||||
|
||||
|
||||
# Utilities for time zone support in DateTimeField et al.
|
||||
|
||||
def from_current_timezone(value):
|
||||
"""
|
||||
When time zone support is enabled, convert naive datetimes
|
||||
entered in the current time zone to aware datetimes.
|
||||
"""
|
||||
if settings.USE_TZ and value is not None and timezone.is_naive(value):
|
||||
current_timezone = timezone.get_current_timezone()
|
||||
try:
|
||||
return timezone.make_aware(value, current_timezone)
|
||||
except Exception as exc:
|
||||
raise ValidationError(
|
||||
_('%(datetime)s couldn\'t be interpreted '
|
||||
'in time zone %(current_timezone)s; it '
|
||||
'may be ambiguous or it may not exist.'),
|
||||
code='ambiguous_timezone',
|
||||
params={'datetime': value, 'current_timezone': current_timezone}
|
||||
) from exc
|
||||
return value
|
||||
|
||||
|
||||
def to_current_timezone(value):
|
||||
"""
|
||||
When time zone support is enabled, convert aware datetimes
|
||||
to naive datetimes in the current time zone for display.
|
||||
"""
|
||||
if settings.USE_TZ and value is not None and timezone.is_aware(value):
|
||||
return timezone.make_naive(value)
|
||||
return value
|
||||
Reference in new issue
Block a user