diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2013-06-28 17:32:57 +0100 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2013-06-28 17:32:57 +0100 |
| commit | 7a47ba6f6aeca36b8b092dbafd36abb342d34d4b (patch) | |
| tree | e959922f7d4d08057225459e31697f410e26df26 /django/forms | |
| parent | e2d7e83256234251a81ad3388428f6579795a672 (diff) | |
| parent | 48dd1e63bbb93479666208535a56f8c7c4aeab3a (diff) | |
Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
django/db/backends/__init__.py
django/db/models/fields/related.py
tests/field_deconstruction/tests.py
Diffstat (limited to 'django/forms')
| -rw-r--r-- | django/forms/fields.py | 10 | ||||
| -rw-r--r-- | django/forms/formsets.py | 17 | ||||
| -rw-r--r-- | django/forms/util.py | 1 | ||||
| -rw-r--r-- | django/forms/widgets.py | 5 |
4 files changed, 13 insertions, 20 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 52bcf9485c..c4bc3fa88c 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -370,14 +370,8 @@ class DecimalField(IntegerField): def widget_attrs(self, widget): attrs = super(DecimalField, self).widget_attrs(widget) - if isinstance(widget, NumberInput): - if self.max_digits is not None: - max_length = self.max_digits + 1 # for the sign - if self.decimal_places is None or self.decimal_places > 0: - max_length += 1 # for the dot - attrs['maxlength'] = max_length - if self.decimal_places: - attrs['step'] = '0.%s1' % ('0' * (self.decimal_places-1)) + if isinstance(widget, NumberInput) and self.decimal_places: + attrs['step'] = '0.%s1' % ('0' * (self.decimal_places - 1)) return attrs diff --git a/django/forms/formsets.py b/django/forms/formsets.py index edd362c595..cb3126e6d7 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -4,8 +4,9 @@ from django.core.exceptions import ValidationError from django.forms import Form from django.forms.fields import IntegerField, BooleanField from django.forms.util import ErrorList -from django.forms.widgets import Media, HiddenInput +from django.forms.widgets import HiddenInput from django.utils.encoding import python_2_unicode_compatible +from django.utils.functional import cached_property from django.utils.safestring import mark_safe from django.utils import six from django.utils.six.moves import xrange @@ -55,8 +56,6 @@ class BaseFormSet(object): self.error_class = error_class self._errors = None self._non_form_errors = None - # construct the forms in the formset - self._construct_forms() def __str__(self): return self.as_table() @@ -125,12 +124,14 @@ class BaseFormSet(object): initial_forms = len(self.initial) if self.initial else 0 return initial_forms - def _construct_forms(self): - # instantiate all the forms and put them in self.forms - self.forms = [] + @cached_property + def forms(self): + """ + Instantiate forms at first property access. + """ # DoS protection is included in total_form_count() - for i in xrange(self.total_form_count()): - self.forms.append(self._construct_form(i)) + forms = [self._construct_form(i) for i in xrange(self.total_form_count())] + return forms def _construct_form(self, i, **kwargs): """ diff --git a/django/forms/util.py b/django/forms/util.py index 568cdd1086..0a73320f83 100644 --- a/django/forms/util.py +++ b/django/forms/util.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals from django.conf import settings from django.utils.html import format_html, format_html_join from django.utils.encoding import force_text, python_2_unicode_compatible -from django.utils.safestring import mark_safe from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from django.utils import six diff --git a/django/forms/widgets.py b/django/forms/widgets.py index aca4a457af..38d1b99b0d 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -5,7 +5,6 @@ HTML Widget classes from __future__ import absolute_import, unicode_literals import copy -import datetime from itertools import chain try: from urllib.parse import urljoin @@ -16,8 +15,8 @@ import warnings from django.conf import settings from django.forms.util import flatatt, to_current_timezone from django.utils.datastructures import MultiValueDict, MergeDict -from django.utils.html import conditional_escape, format_html, format_html_join -from django.utils.translation import ugettext, ugettext_lazy +from django.utils.html import conditional_escape, format_html +from django.utils.translation import ugettext_lazy from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.safestring import mark_safe from django.utils import datetime_safe, formats, six |
