From 46786b4193e04d398532bbfc3dcf63c03c1793cb Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sat, 19 Jul 2008 01:22:26 +0000 Subject: Fixed #7741: django.newforms is now django.forms. This is obviously a backwards-incompatible change. There's a warning upon import of django.newforms itself, but deeper imports will raise errors. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7971 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/options.py | 12 +- django/contrib/admin/validation.py | 2 +- django/contrib/admin/widgets.py | 6 +- django/contrib/auth/forms.py | 2 +- django/contrib/formtools/tests.py | 2 +- django/contrib/formtools/wizard.py | 2 +- django/contrib/localflavor/ar/forms.py | 4 +- django/contrib/localflavor/au/forms.py | 6 +- django/contrib/localflavor/br/forms.py | 4 +- django/contrib/localflavor/ca/forms.py | 6 +- django/contrib/localflavor/ch/forms.py | 4 +- django/contrib/localflavor/cl/forms.py | 4 +- django/contrib/localflavor/de/forms.py | 4 +- django/contrib/localflavor/es/forms.py | 4 +- django/contrib/localflavor/fi/forms.py | 4 +- django/contrib/localflavor/fr/forms.py | 4 +- django/contrib/localflavor/generic/forms.py | 2 +- django/contrib/localflavor/in_/forms.py | 4 +- django/contrib/localflavor/is_/forms.py | 6 +- django/contrib/localflavor/it/forms.py | 4 +- django/contrib/localflavor/jp/forms.py | 4 +- django/contrib/localflavor/mx/forms.py | 2 +- django/contrib/localflavor/nl/forms.py | 4 +- django/contrib/localflavor/no/forms.py | 4 +- django/contrib/localflavor/pe/forms.py | 4 +- django/contrib/localflavor/pl/forms.py | 4 +- django/contrib/localflavor/sk/forms.py | 2 +- django/contrib/localflavor/uk/forms.py | 4 +- django/contrib/localflavor/us/forms.py | 4 +- django/contrib/localflavor/za/forms.py | 4 +- django/db/models/fields/__init__.py | 4 +- django/db/models/fields/related.py | 2 +- django/forms/__init__.py | 18 +- django/forms/extras/__init__.py | 1 + django/forms/extras/widgets.py | 79 +++ django/forms/fields.py | 812 ++++++++++++++++++++++++ django/forms/forms.py | 396 ++++++++++++ django/forms/formsets.py | 292 +++++++++ django/forms/models.py | 608 ++++++++++++++++++ django/forms/util.py | 69 ++ django/forms/widgets.py | 647 +++++++++++++++++++ django/newforms/__init__.py | 25 +- django/newforms/extras/__init__.py | 1 - django/newforms/extras/widgets.py | 79 --- django/newforms/fields.py | 812 ------------------------ django/newforms/forms.py | 396 ------------ django/newforms/formsets.py | 292 --------- django/newforms/models.py | 608 ------------------ django/newforms/util.py | 69 -- django/newforms/widgets.py | 647 ------------------- django/views/generic/create_update.py | 2 +- tests/modeltests/many_to_one/models.py | 2 +- tests/modeltests/model_forms/models.py | 10 +- tests/modeltests/model_formsets/models.py | 4 +- tests/modeltests/test_client/views.py | 4 +- tests/regressiontests/forms/error_messages.py | 2 +- tests/regressiontests/forms/extra.py | 8 +- tests/regressiontests/forms/fields.py | 18 +- tests/regressiontests/forms/forms.py | 2 +- tests/regressiontests/forms/formsets.py | 4 +- tests/regressiontests/forms/media.py | 2 +- tests/regressiontests/forms/models.py | 2 +- tests/regressiontests/forms/regressions.py | 2 +- tests/regressiontests/forms/util.py | 6 +- tests/regressiontests/forms/widgets.py | 4 +- tests/regressiontests/inline_formsets/models.py | 2 +- tests/regressiontests/modeladmin/models.py | 12 +- tests/regressiontests/views/views.py | 2 +- 68 files changed, 3036 insertions(+), 3031 deletions(-) create mode 100644 django/forms/extras/__init__.py create mode 100644 django/forms/extras/widgets.py create mode 100644 django/forms/fields.py create mode 100644 django/forms/forms.py create mode 100644 django/forms/formsets.py create mode 100644 django/forms/models.py create mode 100644 django/forms/util.py create mode 100644 django/forms/widgets.py delete mode 100644 django/newforms/extras/__init__.py delete mode 100644 django/newforms/extras/widgets.py delete mode 100644 django/newforms/fields.py delete mode 100644 django/newforms/forms.py delete mode 100644 django/newforms/formsets.py delete mode 100644 django/newforms/models.py delete mode 100644 django/newforms/util.py delete mode 100644 django/newforms/widgets.py diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 3b26f7b262..501014a0d5 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1,8 +1,8 @@ from django import oldforms, template -from django import newforms as forms -from django.newforms.formsets import all_valid -from django.newforms.models import modelform_factory, inlineformset_factory -from django.newforms.models import BaseInlineFormset +from django import forms +from django.forms.formsets import all_valid +from django.forms.models import modelform_factory, inlineformset_factory +from django.forms.models import BaseInlineFormset from django.contrib.contenttypes.models import ContentType from django.contrib.admin import widgets from django.contrib.admin.util import quote, unquote, get_deleted_objects @@ -775,11 +775,11 @@ class InlineAdminForm(AdminForm): return AdminField(self.form, self.formset._pk_field_name, False) def deletion_field(self): - from django.newforms.formsets import DELETION_FIELD_NAME + from django.forms.formsets import DELETION_FIELD_NAME return AdminField(self.form, DELETION_FIELD_NAME, False) def ordering_field(self): - from django.newforms.formsets import ORDERING_FIELD_NAME + from django.forms.formsets import ORDERING_FIELD_NAME return AdminField(self.form, ORDERING_FIELD_NAME, False) class AdminErrorList(forms.util.ErrorList): diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index f640cc5100..2c9cb8554d 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -1,7 +1,7 @@ from django.core.exceptions import ImproperlyConfigured from django.db import models -from django.newforms.models import BaseModelForm, BaseModelFormSet, fields_for_model +from django.forms.models import BaseModelForm, BaseModelFormSet, fields_for_model from django.contrib.admin.options import flatten_fieldsets, BaseModelAdmin from django.contrib.admin.options import HORIZONTAL, VERTICAL diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 4ae8889ac4..14ede5c114 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -4,9 +4,9 @@ Form Widget classes specific to the Django admin site. import copy -from django import newforms as forms -from django.newforms.widgets import RadioFieldRenderer -from django.newforms.util import flatatt +from django import forms +from django.forms.widgets import RadioFieldRenderer +from django.forms.util import flatatt from django.utils.datastructures import MultiValueDict from django.utils.text import capfirst, truncate_words from django.utils.translation import ugettext as _ diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index f63dc7b854..13ddcd3841 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -3,7 +3,7 @@ from django.contrib.auth import authenticate from django.contrib.sites.models import Site from django.template import Context, loader from django.core import validators -from django import newforms as forms +from django import forms from django.utils.translation import ugettext_lazy as _ class UserCreationForm(forms.ModelForm): diff --git a/django/contrib/formtools/tests.py b/django/contrib/formtools/tests.py index ba241e9dc6..99fe80bbb3 100644 --- a/django/contrib/formtools/tests.py +++ b/django/contrib/formtools/tests.py @@ -1,4 +1,4 @@ -from django import newforms as forms +from django import forms from django.contrib.formtools import preview from django import http from django.conf import settings diff --git a/django/contrib/formtools/wizard.py b/django/contrib/formtools/wizard.py index 398de742ec..7b96d91187 100644 --- a/django/contrib/formtools/wizard.py +++ b/django/contrib/formtools/wizard.py @@ -4,7 +4,7 @@ step and storing the form's state as HTML hidden fields so that no state is stored on the server side. """ -from django import newforms as forms +from django import forms from django.conf import settings from django.http import Http404 from django.shortcuts import render_to_response diff --git a/django/contrib/localflavor/ar/forms.py b/django/contrib/localflavor/ar/forms.py index 464399188f..8e8e1af387 100644 --- a/django/contrib/localflavor/ar/forms.py +++ b/django/contrib/localflavor/ar/forms.py @@ -3,8 +3,8 @@ AR-specific Form helpers. """ -from django.newforms import ValidationError -from django.newforms.fields import RegexField, CharField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import RegexField, CharField, Select, EMPTY_VALUES from django.utils.encoding import smart_unicode from django.utils.translation import ugettext_lazy as _ diff --git a/django/contrib/localflavor/au/forms.py b/django/contrib/localflavor/au/forms.py index 41d4e04fec..afc3a0cc4c 100644 --- a/django/contrib/localflavor/au/forms.py +++ b/django/contrib/localflavor/au/forms.py @@ -2,9 +2,9 @@ Australian-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES -from django.newforms.util import smart_unicode +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms.util import smart_unicode from django.utils.translation import ugettext_lazy as _ import re diff --git a/django/contrib/localflavor/br/forms.py b/django/contrib/localflavor/br/forms.py index 81dcb8228b..6d0a0384c6 100644 --- a/django/contrib/localflavor/br/forms.py +++ b/django/contrib/localflavor/br/forms.py @@ -3,8 +3,8 @@ BR-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, CharField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, CharField, Select, EMPTY_VALUES from django.utils.encoding import smart_unicode from django.utils.translation import ugettext_lazy as _ import re diff --git a/django/contrib/localflavor/ca/forms.py b/django/contrib/localflavor/ca/forms.py index 548f85b7f6..327d938373 100644 --- a/django/contrib/localflavor/ca/forms.py +++ b/django/contrib/localflavor/ca/forms.py @@ -2,9 +2,9 @@ Canada-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES -from django.newforms.util import smart_unicode +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms.util import smart_unicode from django.utils.translation import ugettext_lazy as _ import re diff --git a/django/contrib/localflavor/ch/forms.py b/django/contrib/localflavor/ch/forms.py index e2d3aea944..bd92fcae98 100644 --- a/django/contrib/localflavor/ch/forms.py +++ b/django/contrib/localflavor/ch/forms.py @@ -2,8 +2,8 @@ Swiss-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES from django.utils.encoding import smart_unicode from django.utils.translation import ugettext_lazy as _ import re diff --git a/django/contrib/localflavor/cl/forms.py b/django/contrib/localflavor/cl/forms.py index 69473607a6..61b3ab7aac 100644 --- a/django/contrib/localflavor/cl/forms.py +++ b/django/contrib/localflavor/cl/forms.py @@ -2,8 +2,8 @@ Chile specific form helpers. """ -from django.newforms import ValidationError -from django.newforms.fields import RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import RegexField, Select, EMPTY_VALUES from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import smart_unicode diff --git a/django/contrib/localflavor/de/forms.py b/django/contrib/localflavor/de/forms.py index c5402fa260..7a1b7c03c8 100644 --- a/django/contrib/localflavor/de/forms.py +++ b/django/contrib/localflavor/de/forms.py @@ -2,8 +2,8 @@ DE-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES from django.utils.translation import ugettext_lazy as _ import re diff --git a/django/contrib/localflavor/es/forms.py b/django/contrib/localflavor/es/forms.py index 57e730b2cf..522f5f4696 100644 --- a/django/contrib/localflavor/es/forms.py +++ b/django/contrib/localflavor/es/forms.py @@ -3,8 +3,8 @@ Spanish-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import RegexField, Select, EMPTY_VALUES from django.utils.translation import ugettext_lazy as _ import re diff --git a/django/contrib/localflavor/fi/forms.py b/django/contrib/localflavor/fi/forms.py index e9e0fc1e93..2b82a796fe 100644 --- a/django/contrib/localflavor/fi/forms.py +++ b/django/contrib/localflavor/fi/forms.py @@ -3,8 +3,8 @@ FI-specific Form helpers """ import re -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES from django.utils.translation import ugettext_lazy as _ class FIZipCodeField(RegexField): diff --git a/django/contrib/localflavor/fr/forms.py b/django/contrib/localflavor/fr/forms.py index 960e8b221c..8d9d9d7771 100644 --- a/django/contrib/localflavor/fr/forms.py +++ b/django/contrib/localflavor/fr/forms.py @@ -2,8 +2,8 @@ FR-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES from django.utils.encoding import smart_unicode from django.utils.translation import ugettext_lazy as _ import re diff --git a/django/contrib/localflavor/generic/forms.py b/django/contrib/localflavor/generic/forms.py index a5e431e4b3..8bafce7b1b 100644 --- a/django/contrib/localflavor/generic/forms.py +++ b/django/contrib/localflavor/generic/forms.py @@ -1,4 +1,4 @@ -from django import newforms as forms +from django import forms DEFAULT_DATE_INPUT_FORMATS = ( '%Y-%m-%d', '%d/%m/%Y', '%d/%m/%y', # '2006-10-25', '25/10/2006', '25/10/06' diff --git a/django/contrib/localflavor/in_/forms.py b/django/contrib/localflavor/in_/forms.py index 1cb303d772..270b0a09b1 100644 --- a/django/contrib/localflavor/in_/forms.py +++ b/django/contrib/localflavor/in_/forms.py @@ -2,8 +2,8 @@ India-specific Form helpers. """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES from django.utils.encoding import smart_unicode from django.utils.translation import gettext import re diff --git a/django/contrib/localflavor/is_/forms.py b/django/contrib/localflavor/is_/forms.py index 9f7b6f0211..cab6eb18c0 100644 --- a/django/contrib/localflavor/is_/forms.py +++ b/django/contrib/localflavor/is_/forms.py @@ -2,9 +2,9 @@ Iceland specific form helpers. """ -from django.newforms import ValidationError -from django.newforms.fields import RegexField, EMPTY_VALUES -from django.newforms.widgets import Select +from django.forms import ValidationError +from django.forms.fields import RegexField, EMPTY_VALUES +from django.forms.widgets import Select from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import smart_unicode diff --git a/django/contrib/localflavor/it/forms.py b/django/contrib/localflavor/it/forms.py index 7d4a82dd63..d2d651955a 100644 --- a/django/contrib/localflavor/it/forms.py +++ b/django/contrib/localflavor/it/forms.py @@ -2,8 +2,8 @@ IT-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import smart_unicode from django.contrib.localflavor.it.util import ssn_check_digit, vat_number_check_digit diff --git a/django/contrib/localflavor/jp/forms.py b/django/contrib/localflavor/jp/forms.py index 70def85351..c86dbaf8da 100644 --- a/django/contrib/localflavor/jp/forms.py +++ b/django/contrib/localflavor/jp/forms.py @@ -3,9 +3,9 @@ JP-specific Form helpers """ from django.core import validators -from django.newforms import ValidationError +from django.forms import ValidationError from django.utils.translation import ugettext_lazy as _ -from django.newforms.fields import RegexField, Select +from django.forms.fields import RegexField, Select class JPPostalCodeField(RegexField): """ diff --git a/django/contrib/localflavor/mx/forms.py b/django/contrib/localflavor/mx/forms.py index 5e42cca7d7..95819375ef 100644 --- a/django/contrib/localflavor/mx/forms.py +++ b/django/contrib/localflavor/mx/forms.py @@ -2,7 +2,7 @@ Mexican-specific form helpers. """ -from django.newforms.fields import Select +from django.forms.fields import Select class MXStateSelect(Select): """ diff --git a/django/contrib/localflavor/nl/forms.py b/django/contrib/localflavor/nl/forms.py index 6f9e887339..6dc5319eb7 100644 --- a/django/contrib/localflavor/nl/forms.py +++ b/django/contrib/localflavor/nl/forms.py @@ -4,8 +4,8 @@ NL-specific Form helpers import re -from django.newforms import ValidationError -from django.newforms.fields import Field, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, Select, EMPTY_VALUES from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import smart_unicode diff --git a/django/contrib/localflavor/no/forms.py b/django/contrib/localflavor/no/forms.py index 39c80ec0b2..0fe55adf7e 100644 --- a/django/contrib/localflavor/no/forms.py +++ b/django/contrib/localflavor/no/forms.py @@ -3,8 +3,8 @@ Norwegian-specific Form helpers """ import re, datetime -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES from django.utils.translation import ugettext_lazy as _ class NOZipCodeField(RegexField): diff --git a/django/contrib/localflavor/pe/forms.py b/django/contrib/localflavor/pe/forms.py index 328b2e36e1..d192295dcf 100644 --- a/django/contrib/localflavor/pe/forms.py +++ b/django/contrib/localflavor/pe/forms.py @@ -3,8 +3,8 @@ PE-specific Form helpers. """ -from django.newforms import ValidationError -from django.newforms.fields import RegexField, CharField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import RegexField, CharField, Select, EMPTY_VALUES from django.utils.translation import ugettext_lazy as _ class PEDepartmentSelect(Select): diff --git a/django/contrib/localflavor/pl/forms.py b/django/contrib/localflavor/pl/forms.py index 32d00cc3a8..8410c72a3c 100644 --- a/django/contrib/localflavor/pl/forms.py +++ b/django/contrib/localflavor/pl/forms.py @@ -4,8 +4,8 @@ Polish-specific form helpers import re -from django.newforms import ValidationError -from django.newforms.fields import Select, RegexField +from django.forms import ValidationError +from django.forms.fields import Select, RegexField from django.utils.translation import ugettext_lazy as _ class PLVoivodeshipSelect(Select): diff --git a/django/contrib/localflavor/sk/forms.py b/django/contrib/localflavor/sk/forms.py index d12927ecab..863a61217a 100644 --- a/django/contrib/localflavor/sk/forms.py +++ b/django/contrib/localflavor/sk/forms.py @@ -2,7 +2,7 @@ Slovak-specific form helpers """ -from django.newforms.fields import Select, RegexField +from django.forms.fields import Select, RegexField from django.utils.translation import ugettext_lazy as _ class SKRegionSelect(Select): diff --git a/django/contrib/localflavor/uk/forms.py b/django/contrib/localflavor/uk/forms.py index b3883f6477..7df736444a 100644 --- a/django/contrib/localflavor/uk/forms.py +++ b/django/contrib/localflavor/uk/forms.py @@ -4,8 +4,8 @@ UK-specific Form helpers import re -from django.newforms.fields import CharField, Select -from django.newforms import ValidationError +from django.forms.fields import CharField, Select +from django.forms import ValidationError from django.utils.translation import ugettext_lazy as _ class UKPostcodeField(CharField): diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py index a17062d61f..a744edce74 100644 --- a/django/contrib/localflavor/us/forms.py +++ b/django/contrib/localflavor/us/forms.py @@ -2,8 +2,8 @@ USA-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES from django.utils.encoding import smart_unicode from django.utils.translation import ugettext_lazy as _ import re diff --git a/django/contrib/localflavor/za/forms.py b/django/contrib/localflavor/za/forms.py index b3613b507d..7b7b714398 100644 --- a/django/contrib/localflavor/za/forms.py +++ b/django/contrib/localflavor/za/forms.py @@ -2,8 +2,8 @@ South Africa-specific Form helpers """ -from django.newforms import ValidationError -from django.newforms.fields import Field, RegexField, EMPTY_VALUES +from django.forms import ValidationError +from django.forms.fields import Field, RegexField, EMPTY_VALUES from django.utils.checksums import luhn from django.utils.translation import gettext as _ import re diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 879807d2d2..52eaa435a2 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -14,7 +14,7 @@ from django.dispatch import dispatcher from django.conf import settings from django.core import validators from django import oldforms -from django import newforms as forms +from django import forms from django.core.exceptions import ObjectDoesNotExist from django.utils.datastructures import DictWrapper from django.utils.functional import curry @@ -411,7 +411,7 @@ class Field(object): setattr(instance, self.name, data) def formfield(self, form_class=forms.CharField, **kwargs): - "Returns a django.newforms.Field instance for this database Field." + "Returns a django.forms.Field instance for this database Field." defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text} if self.choices: defaults['widget'] = forms.Select(choices=self.get_choices(include_blank=self.blank or not (self.has_default() or 'initial' in kwargs))) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index 594236b4c6..735dda4969 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -9,7 +9,7 @@ from django.utils.functional import curry from django.utils.encoding import smart_unicode from django.core import validators from django import oldforms -from django import newforms as forms +from django import forms from django.dispatch import dispatcher try: diff --git a/django/forms/__init__.py b/django/forms/__init__.py index 68d3d245a2..0d9c68f9e0 100644 --- a/django/forms/__init__.py +++ b/django/forms/__init__.py @@ -1 +1,17 @@ -from django.oldforms import * +""" +Django validation and HTML form handling. + +TODO: + Default value for field + Field labels + Nestable Forms + FatalValidationError -- short-circuits all other validators on a form + ValidationWarning + "This form field requires foo.js" and form.js_includes() +""" + +from util import ValidationError +from widgets import * +from fields import * +from forms import * +from models import * diff --git a/django/forms/extras/__init__.py b/django/forms/extras/__init__.py new file mode 100644 index 0000000000..a7f6a9b3f6 --- /dev/null +++ b/django/forms/extras/__init__.py @@ -0,0 +1 @@ +from widgets import * diff --git a/django/forms/extras/widgets.py b/django/forms/extras/widgets.py new file mode 100644 index 0000000000..ffa7ba2de2 --- /dev/null +++ b/django/forms/extras/widgets.py @@ -0,0 +1,79 @@ +""" +Extra HTML Widget classes +""" + +import datetime +import re + +from django.forms.widgets import Widget, Select +from django.utils.dates import MONTHS +from django.utils.safestring import mark_safe + +__all__ = ('SelectDateWidget',) + +RE_DATE = re.compile(r'(\d{4})-(\d\d?)-(\d\d?)$') + +class SelectDateWidget(Widget): + """ + A Widget that splits date input into three . + """ + return self.as_widget(TextInput(), attrs) + + def as_textarea(self, attrs=None): + "Returns a string of HTML for representing this as a ' % (flatatt(final_attrs), + conditional_escape(force_unicode(value)))) + +class DateTimeInput(Input): + input_type = 'text' + format = '%Y-%m-%d %H:%M:%S' # '2006-10-25 14:30:59' + + def __init__(self, attrs=None, format=None): + super(DateTimeInput, self).__init__(attrs) + if format: + self.format = format + + def render(self, name, value, attrs=None): + if value is None: + value = '' + elif hasattr(value, 'strftime'): + value = datetime_safe.new_datetime(value) + value = value.strftime(self.format) + return super(DateTimeInput, self).render(name, value, attrs) + +class CheckboxInput(Widget): + def __init__(self, attrs=None, check_test=bool): + super(CheckboxInput, self).__init__(attrs) + # check_test is a callable that takes a value and returns True + # if the checkbox should be checked for that value. + self.check_test = check_test + + def render(self, name, value, attrs=None): + final_attrs = self.build_attrs(attrs, type='checkbox', name=name) + try: + result = self.check_test(value) + except: # Silently catch exceptions + result = False + if result: + final_attrs['checked'] = 'checked' + if value not in ('', True, False, None): + # Only add the 'value' attribute if a value is non-empty. + final_attrs['value'] = force_unicode(value) + return mark_safe(u'' % flatatt(final_attrs)) + + def value_from_datadict(self, data, files, name): + if name not in data: + # A missing value means False because HTML form submission does not + # send results for unselected checkboxes. + return False + return super(CheckboxInput, self).value_from_datadict(data, files, name) + + def _has_changed(self, initial, data): + # Sometimes data or initial could be None or u'' which should be the + # same thing as False. + return bool(initial) != bool(data) + +class Select(Widget): + def __init__(self, attrs=None, choices=()): + super(Select, self).__init__(attrs) + # choices can be any iterable, but we may need to render this widget + # multiple times. Thus, collapse it into a list so it can be consumed + # more than once. + self.choices = list(choices) + + def render(self, name, value, attrs=None, choices=()): + if value is None: value = '' + final_attrs = self.build_attrs(attrs, name=name) + output = [u'' % flatatt(final_attrs)] + # Normalize to string. + str_value = force_unicode(value) + for option_value, option_label in chain(self.choices, choices): + option_value = force_unicode(option_value) + selected_html = (option_value == str_value) and u' selected="selected"' or '' + output.append(u'' % ( + escape(option_value), selected_html, + conditional_escape(force_unicode(option_label)))) + output.append(u'') + return mark_safe(u'\n'.join(output)) + +class NullBooleanSelect(Select): + """ + A Select Widget intended to be used with NullBooleanField. + """ + def __init__(self, attrs=None): + choices = ((u'1', ugettext('Unknown')), (u'2', ugettext('Yes')), (u'3', ugettext('No'))) + super(NullBooleanSelect, self).__init__(attrs, choices) + + def render(self, name, value, attrs=None, choices=()): + try: + value = {True: u'2', False: u'3', u'2': u'2', u'3': u'3'}[value] + except KeyError: + value = u'1' + return super(NullBooleanSelect, self).render(name, value, attrs, choices) + + def value_from_datadict(self, data, files, name): + value = data.get(name, None) + return {u'2': True, u'3': False, True: True, False: False}.get(value, None) + + def _has_changed(self, initial, data): + # Sometimes data or initial could be None or u'' which should be the + # same thing as False. + return bool(initial) != bool(data) + +class SelectMultiple(Widget): + def __init__(self, attrs=None, choices=()): + super(SelectMultiple, self).__init__(attrs) + # choices can be any iterable + self.choices = choices + + def render(self, name, value, attrs=None, choices=()): + if value is None: value = [] + final_attrs = self.build_attrs(attrs, name=name) + output = [u'') + return mark_safe(u'\n'.join(output)) + + def value_from_datadict(self, data, files, name): + if isinstance(data, MultiValueDict): + return data.getlist(name) + return data.get(name, None) + + def _has_changed(self, initial, data): + if initial is None: + initial = [] + if data is None: + data = [] + if len(initial) != len(data): + return True + for value1, value2 in zip(initial, data): + if force_unicode(value1) != force_unicode(value2): + return True + return False + +class RadioInput(StrAndUnicode): + """ + An object used by RadioFieldRenderer that represents a single + . + """ + + def __init__(self, name, value, attrs, choice, index): + self.name, self.value = name, value + self.attrs = attrs + self.choice_value = force_unicode(choice[0]) + self.choice_label = force_unicode(choice[1]) + self.index = index + + def __unicode__(self): + if 'id' in self.attrs: + label_for = ' for="%s_%s"' % (self.attrs['id'], self.index) + else: + label_for = '' + choice_label = conditional_escape(force_unicode(self.choice_label)) + return mark_safe(u'%s %s' % (label_for, self.tag(), choice_label)) + + def is_checked(self): + return self.value == self.choice_value + + def tag(self): + if 'id' in self.attrs: + self.attrs['id'] = '%s_%s' % (self.attrs['id'], self.index) + final_attrs = dict(self.attrs, type='radio', name=self.name, value=self.choice_value) + if self.is_checked(): + final_attrs['checked'] = 'checked' + return mark_safe(u'' % flatatt(final_attrs)) + +class RadioFieldRenderer(StrAndUnicode): + """ + An object used by RadioSelect to enable customization of radio widgets. + """ + + def __init__(self, name, value, attrs, choices): + self.name, self.value, self.attrs = name, value, attrs + self.choices = choices + + def __iter__(self): + for i, choice in enumerate(self.choices): + yield RadioInput(self.name, self.value, self.attrs.copy(), choice, i) + + def __getitem__(self, idx): + choice = self.choices[idx] # Let the IndexError propogate + return RadioInput(self.name, self.value, self.attrs.copy(), choice, idx) + + def __unicode__(self): + return self.render() + + def render(self): + """Outputs a
    for this set of radio fields.""" + return mark_safe(u'
      \n%s\n
    ' % u'\n'.join([u'
  • %s
  • ' + % force_unicode(w) for w in self])) + +class RadioSelect(Select): + renderer = RadioFieldRenderer + + def __init__(self, *args, **kwargs): + # Override the default renderer if we were passed one. + renderer = kwargs.pop('renderer', None) + if renderer: + self.renderer = renderer + super(RadioSelect, self).__init__(*args, **kwargs) + + def get_renderer(self, name, value, attrs=None, choices=()): + """Returns an instance of the renderer.""" + if value is None: value = '' + str_value = force_unicode(value) # Normalize to string. + final_attrs = self.build_attrs(attrs) + choices = list(chain(self.choices, choices)) + return self.renderer(name, str_value, final_attrs, choices) + + def render(self, name, value, attrs=None, choices=()): + return self.get_renderer(name, value, attrs, choices).render() + + def id_for_label(self, id_): + # RadioSelect is represented by multiple fields, + # each of which has a distinct ID. The IDs are made distinct by a "_X" + # suffix, where X is the zero-based index of the radio field. Thus, + # the label for a RadioSelect should reference the first one ('_0'). + if id_: + id_ += '_0' + return id_ + id_for_label = classmethod(id_for_label) + +class CheckboxSelectMultiple(SelectMultiple): + def render(self, name, value, attrs=None, choices=()): + if value is None: value = [] + has_id = attrs and 'id' in attrs + final_attrs = self.build_attrs(attrs, name=name) + output = [u'
      '] + # Normalize to strings + str_values = set([force_unicode(v) for v in value]) + for i, (option_value, option_label) in enumerate(chain(self.choices, choices)): + # If an ID attribute was given, add a numeric index as a suffix, + # so that the checkboxes don't all have the same ID attribute. + if has_id: + final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i)) + label_for = u' for="%s"' % final_attrs['id'] + else: + label_for = '' + + cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values) + option_value = force_unicode(option_value) + rendered_cb = cb.render(name, option_value) + option_label = conditional_escape(force_unicode(option_label)) + output.append(u'
    • %s %s
    • ' % (label_for, rendered_cb, option_label)) + output.append(u'
    ') + return mark_safe(u'\n'.join(output)) + + def id_for_label(self, id_): + # See the comment for RadioSelect.id_for_label() + if id_: + id_ += '_0' + return id_ + id_for_label = classmethod(id_for_label) + +class MultiWidget(Widget): + """ + A widget that is composed of multiple widgets. + + Its render() method is different than other widgets', because it has to + figure out how to split a single value for display in multiple widgets. + The ``value`` argument can be one of two things: + + * A list. + * A normal value (e.g., a string) that has been "compressed" from + a list of values. + + In the second case -- i.e., if the value is NOT a list -- render() will + first "decompress" the value into a list before rendering it. It does so by + calling the decompress() method, which MultiWidget subclasses must + implement. This method takes a single "compressed" value and returns a + list. + + When render() does its HTML rendering, each value in the list is rendered + with the corresponding widget -- the first value is rendered in the first + widget, the second value is rendered in the second widget, etc. + + Subclasses may implement format_output(), which takes the list of rendered + widgets and returns a string of HTML that formats them any way you'd like. + + You'll probably want to use this class with MultiValueField. + """ + def __init__(self, widgets, attrs=None): + self.widgets = [isinstance(w, type) and w() or w for w in widgets] + super(MultiWidget, self).__init__(attrs) + + def render(self, name, value, attrs=None): + # value is a list of values, each corresponding to a widget + # in self.widgets. + if not isinstance(value, list): + value = self.decompress(value) + output = [] + final_attrs = self.build_attrs(attrs) + id_ = final_attrs.get('id', None) + for i, widget in enumerate(self.widgets): + try: + widget_value = value[i] + except IndexError: + widget_value = None + if id_: + final_attrs = dict(final_attrs, id='%s_%s' % (id_, i)) + output.append(widget.render(name + '_%s' % i, widget_value, final_attrs)) + return mark_safe(self.format_output(output)) + + def id_for_label(self, id_): + # See the comment for RadioSelect.id_for_label() + if id_: + id_ += '_0' + return id_ + id_for_label = classmethod(id_for_label) + + def value_from_datadict(self, data, files, name): + return [widget.value_from_datadict(data, files, name + '_%s' % i) for i, widget in enumerate(self.widgets)] + + def _has_changed(self, initial, data): + if initial is None: + initial = [u'' for x in range(0, len(data))] + else: + initial = self.decompress(initial) + for widget, initial, data in zip(self.widgets, initial, data): + if widget._has_changed(initial, data): + return True + return False + + def format_output(self, rendered_widgets): + """ + Given a list of rendered widgets (as strings), returns a Unicode string + representing the HTML for the whole lot. + + This hook allows you to format the HTML design of the widgets, if + needed. + """ + return u''.join(rendered_widgets) + + def decompress(self, value): + """ + Returns a list of decompressed values for the given compressed value. + The given value can be assumed to be valid, but not necessarily + non-empty. + """ + raise NotImplementedError('Subclasses must implement this method.') + + def _get_media(self): + "Media for a multiwidget is the combination of all media of the subwidgets" + media = Media() + for w in self.widgets: + media = media + w.media + return media + media = property(_get_media) + +class SplitDateTimeWidget(MultiWidget): + """ + A Widget that splits datetime input into two boxes. + """ + def __init__(self, attrs=None): + widgets = (TextInput(attrs=attrs), TextInput(attrs=attrs)) + super(SplitDateTimeWidget, self).__init__(widgets, attrs) + + def decompress(self, value): + if value: + return [value.date(), value.time().replace(microsecond=0)] + return [None, None] + diff --git a/django/newforms/__init__.py b/django/newforms/__init__.py index 99631e4e8f..5f319f8c1b 100644 --- a/django/newforms/__init__.py +++ b/django/newforms/__init__.py @@ -1,18 +1,7 @@ -""" -Django validation and HTML form handling. - -TODO: - Default value for field - Field labels - Nestable Forms - FatalValidationError -- short-circuits all other validators on a form - ValidationWarning - "This form field requires foo.js" and form.js_includes() -""" - -from util import ValidationError -from widgets import * -from fields import * -from forms import * -from models import * -from formsets import * \ No newline at end of file +import warnings +warnings.warn( + category = DeprecationWarning, + message = "django.newforms is no longer new. Import django.forms instead.", + stacklevel = 2 +) +from django.forms import * \ No newline at end of file diff --git a/django/newforms/extras/__init__.py b/django/newforms/extras/__init__.py deleted file mode 100644 index a7f6a9b3f6..0000000000 --- a/django/newforms/extras/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from widgets import * diff --git a/django/newforms/extras/widgets.py b/django/newforms/extras/widgets.py deleted file mode 100644 index e3ef1d7f69..0000000000 --- a/django/newforms/extras/widgets.py +++ /dev/null @@ -1,79 +0,0 @@ -""" -Extra HTML Widget classes -""" - -import datetime -import re - -from django.newforms.widgets import Widget, Select -from django.utils.dates import MONTHS -from django.utils.safestring import mark_safe - -__all__ = ('SelectDateWidget',) - -RE_DATE = re.compile(r'(\d{4})-(\d\d?)-(\d\d?)$') - -class SelectDateWidget(Widget): - """ - A Widget that splits date input into three . - """ - return self.as_widget(TextInput(), attrs) - - def as_textarea(self, attrs=None): - "Returns a string of HTML for representing this as a ' % (flatatt(final_attrs), - conditional_escape(force_unicode(value)))) - -class DateTimeInput(Input): - input_type = 'text' - format = '%Y-%m-%d %H:%M:%S' # '2006-10-25 14:30:59' - - def __init__(self, attrs=None, format=None): - super(DateTimeInput, self).__init__(attrs) - if format: - self.format = format - - def render(self, name, value, attrs=None): - if value is None: - value = '' - elif hasattr(value, 'strftime'): - value = datetime_safe.new_datetime(value) - value = value.strftime(self.format) - return super(DateTimeInput, self).render(name, value, attrs) - -class CheckboxInput(Widget): - def __init__(self, attrs=None, check_test=bool): - super(CheckboxInput, self).__init__(attrs) - # check_test is a callable that takes a value and returns True - # if the checkbox should be checked for that value. - self.check_test = check_test - - def render(self, name, value, attrs=None): - final_attrs = self.build_attrs(attrs, type='checkbox', name=name) - try: - result = self.check_test(value) - except: # Silently catch exceptions - result = False - if result: - final_attrs['checked'] = 'checked' - if value not in ('', True, False, None): - # Only add the 'value' attribute if a value is non-empty. - final_attrs['value'] = force_unicode(value) - return mark_safe(u'' % flatatt(final_attrs)) - - def value_from_datadict(self, data, files, name): - if name not in data: - # A missing value means False because HTML form submission does not - # send results for unselected checkboxes. - return False - return super(CheckboxInput, self).value_from_datadict(data, files, name) - - def _has_changed(self, initial, data): - # Sometimes data or initial could be None or u'' which should be the - # same thing as False. - return bool(initial) != bool(data) - -class Select(Widget): - def __init__(self, attrs=None, choices=()): - super(Select, self).__init__(attrs) - # choices can be any iterable, but we may need to render this widget - # multiple times. Thus, collapse it into a list so it can be consumed - # more than once. - self.choices = list(choices) - - def render(self, name, value, attrs=None, choices=()): - if value is None: value = '' - final_attrs = self.build_attrs(attrs, name=name) - output = [u'' % flatatt(final_attrs)] - # Normalize to string. - str_value = force_unicode(value) - for option_value, option_label in chain(self.choices, choices): - option_value = force_unicode(option_value) - selected_html = (option_value == str_value) and u' selected="selected"' or '' - output.append(u'' % ( - escape(option_value), selected_html, - conditional_escape(force_unicode(option_label)))) - output.append(u'') - return mark_safe(u'\n'.join(output)) - -class NullBooleanSelect(Select): - """ - A Select Widget intended to be used with NullBooleanField. - """ - def __init__(self, attrs=None): - choices = ((u'1', ugettext('Unknown')), (u'2', ugettext('Yes')), (u'3', ugettext('No'))) - super(NullBooleanSelect, self).__init__(attrs, choices) - - def render(self, name, value, attrs=None, choices=()): - try: - value = {True: u'2', False: u'3', u'2': u'2', u'3': u'3'}[value] - except KeyError: - value = u'1' - return super(NullBooleanSelect, self).render(name, value, attrs, choices) - - def value_from_datadict(self, data, files, name): - value = data.get(name, None) - return {u'2': True, u'3': False, True: True, False: False}.get(value, None) - - def _has_changed(self, initial, data): - # Sometimes data or initial could be None or u'' which should be the - # same thing as False. - return bool(initial) != bool(data) - -class SelectMultiple(Widget): - def __init__(self, attrs=None, choices=()): - super(SelectMultiple, self).__init__(attrs) - # choices can be any iterable - self.choices = choices - - def render(self, name, value, attrs=None, choices=()): - if value is None: value = [] - final_attrs = self.build_attrs(attrs, name=name) - output = [u'') - return mark_safe(u'\n'.join(output)) - - def value_from_datadict(self, data, files, name): - if isinstance(data, MultiValueDict): - return data.getlist(name) - return data.get(name, None) - - def _has_changed(self, initial, data): - if initial is None: - initial = [] - if data is None: - data = [] - if len(initial) != len(data): - return True - for value1, value2 in zip(initial, data): - if force_unicode(value1) != force_unicode(value2): - return True - return False - -class RadioInput(StrAndUnicode): - """ - An object used by RadioFieldRenderer that represents a single - . - """ - - def __init__(self, name, value, attrs, choice, index): - self.name, self.value = name, value - self.attrs = attrs - self.choice_value = force_unicode(choice[0]) - self.choice_label = force_unicode(choice[1]) - self.index = index - - def __unicode__(self): - if 'id' in self.attrs: - label_for = ' for="%s_%s"' % (self.attrs['id'], self.index) - else: - label_for = '' - choice_label = conditional_escape(force_unicode(self.choice_label)) - return mark_safe(u'%s %s' % (label_for, self.tag(), choice_label)) - - def is_checked(self): - return self.value == self.choice_value - - def tag(self): - if 'id' in self.attrs: - self.attrs['id'] = '%s_%s' % (self.attrs['id'], self.index) - final_attrs = dict(self.attrs, type='radio', name=self.name, value=self.choice_value) - if self.is_checked(): - final_attrs['checked'] = 'checked' - return mark_safe(u'' % flatatt(final_attrs)) - -class RadioFieldRenderer(StrAndUnicode): - """ - An object used by RadioSelect to enable customization of radio widgets. - """ - - def __init__(self, name, value, attrs, choices): - self.name, self.value, self.attrs = name, value, attrs - self.choices = choices - - def __iter__(self): - for i, choice in enumerate(self.choices): - yield RadioInput(self.name, self.value, self.attrs.copy(), choice, i) - - def __getitem__(self, idx): - choice = self.choices[idx] # Let the IndexError propogate - return RadioInput(self.name, self.value, self.attrs.copy(), choice, idx) - - def __unicode__(self): - return self.render() - - def render(self): - """Outputs a
      for this set of radio fields.""" - return mark_safe(u'
        \n%s\n
      ' % u'\n'.join([u'
    • %s
    • ' - % force_unicode(w) for w in self])) - -class RadioSelect(Select): - renderer = RadioFieldRenderer - - def __init__(self, *args, **kwargs): - # Override the default renderer if we were passed one. - renderer = kwargs.pop('renderer', None) - if renderer: - self.renderer = renderer - super(RadioSelect, self).__init__(*args, **kwargs) - - def get_renderer(self, name, value, attrs=None, choices=()): - """Returns an instance of the renderer.""" - if value is None: value = '' - str_value = force_unicode(value) # Normalize to string. - final_attrs = self.build_attrs(attrs) - choices = list(chain(self.choices, choices)) - return self.renderer(name, str_value, final_attrs, choices) - - def render(self, name, value, attrs=None, choices=()): - return self.get_renderer(name, value, attrs, choices).render() - - def id_for_label(self, id_): - # RadioSelect is represented by multiple fields, - # each of which has a distinct ID. The IDs are made distinct by a "_X" - # suffix, where X is the zero-based index of the radio field. Thus, - # the label for a RadioSelect should reference the first one ('_0'). - if id_: - id_ += '_0' - return id_ - id_for_label = classmethod(id_for_label) - -class CheckboxSelectMultiple(SelectMultiple): - def render(self, name, value, attrs=None, choices=()): - if value is None: value = [] - has_id = attrs and 'id' in attrs - final_attrs = self.build_attrs(attrs, name=name) - output = [u'
        '] - # Normalize to strings - str_values = set([force_unicode(v) for v in value]) - for i, (option_value, option_label) in enumerate(chain(self.choices, choices)): - # If an ID attribute was given, add a numeric index as a suffix, - # so that the checkboxes don't all have the same ID attribute. - if has_id: - final_attrs = dict(final_attrs, id='%s_%s' % (attrs['id'], i)) - label_for = u' for="%s"' % final_attrs['id'] - else: - label_for = '' - - cb = CheckboxInput(final_attrs, check_test=lambda value: value in str_values) - option_value = force_unicode(option_value) - rendered_cb = cb.render(name, option_value) - option_label = conditional_escape(force_unicode(option_label)) - output.append(u'
      • %s %s
      • ' % (label_for, rendered_cb, option_label)) - output.append(u'
      ') - return mark_safe(u'\n'.join(output)) - - def id_for_label(self, id_): - # See the comment for RadioSelect.id_for_label() - if id_: - id_ += '_0' - return id_ - id_for_label = classmethod(id_for_label) - -class MultiWidget(Widget): - """ - A widget that is composed of multiple widgets. - - Its render() method is different than other widgets', because it has to - figure out how to split a single value for display in multiple widgets. - The ``value`` argument can be one of two things: - - * A list. - * A normal value (e.g., a string) that has been "compressed" from - a list of values. - - In the second case -- i.e., if the value is NOT a list -- render() will - first "decompress" the value into a list before rendering it. It does so by - calling the decompress() method, which MultiWidget subclasses must - implement. This method takes a single "compressed" value and returns a - list. - - When render() does its HTML rendering, each value in the list is rendered - with the corresponding widget -- the first value is rendered in the first - widget, the second value is rendered in the second widget, etc. - - Subclasses may implement format_output(), which takes the list of rendered - widgets and returns a string of HTML that formats them any way you'd like. - - You'll probably want to use this class with MultiValueField. - """ - def __init__(self, widgets, attrs=None): - self.widgets = [isinstance(w, type) and w() or w for w in widgets] - super(MultiWidget, self).__init__(attrs) - - def render(self, name, value, attrs=None): - # value is a list of values, each corresponding to a widget - # in self.widgets. - if not isinstance(value, list): - value = self.decompress(value) - output = [] - final_attrs = self.build_attrs(attrs) - id_ = final_attrs.get('id', None) - for i, widget in enumerate(self.widgets): - try: - widget_value = value[i] - except IndexError: - widget_value = None - if id_: - final_attrs = dict(final_attrs, id='%s_%s' % (id_, i)) - output.append(widget.render(name + '_%s' % i, widget_value, final_attrs)) - return mark_safe(self.format_output(output)) - - def id_for_label(self, id_): - # See the comment for RadioSelect.id_for_label() - if id_: - id_ += '_0' - return id_ - id_for_label = classmethod(id_for_label) - - def value_from_datadict(self, data, files, name): - return [widget.value_from_datadict(data, files, name + '_%s' % i) for i, widget in enumerate(self.widgets)] - - def _has_changed(self, initial, data): - if initial is None: - initial = [u'' for x in range(0, len(data))] - else: - initial = self.decompress(initial) - for widget, initial, data in zip(self.widgets, initial, data): - if widget._has_changed(initial, data): - return True - return False - - def format_output(self, rendered_widgets): - """ - Given a list of rendered widgets (as strings), returns a Unicode string - representing the HTML for the whole lot. - - This hook allows you to format the HTML design of the widgets, if - needed. - """ - return u''.join(rendered_widgets) - - def decompress(self, value): - """ - Returns a list of decompressed values for the given compressed value. - The given value can be assumed to be valid, but not necessarily - non-empty. - """ - raise NotImplementedError('Subclasses must implement this method.') - - def _get_media(self): - "Media for a multiwidget is the combination of all media of the subwidgets" - media = Media() - for w in self.widgets: - media = media + w.media - return media - media = property(_get_media) - -class SplitDateTimeWidget(MultiWidget): - """ - A Widget that splits datetime input into two boxes. - """ - def __init__(self, attrs=None): - widgets = (TextInput(attrs=attrs), TextInput(attrs=attrs)) - super(SplitDateTimeWidget, self).__init__(widgets, attrs) - - def decompress(self, value): - if value: - return [value.date(), value.time().replace(microsecond=0)] - return [None, None] - diff --git a/django/views/generic/create_update.py b/django/views/generic/create_update.py index a51661c4a7..4fe639f321 100644 --- a/django/views/generic/create_update.py +++ b/django/views/generic/create_update.py @@ -1,4 +1,4 @@ -from django.newforms.models import ModelFormMetaclass, ModelForm +from django.forms.models import ModelFormMetaclass, ModelForm from django.template import RequestContext, loader from django.http import Http404, HttpResponse, HttpResponseRedirect from django.core.xheaders import populate_xheaders diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py index dfb17b8344..081cffb807 100644 --- a/tests/modeltests/many_to_one/models.py +++ b/tests/modeltests/many_to_one/models.py @@ -155,7 +155,7 @@ False [, ] # And should work fine with the unicode that comes out of -# newforms.Form.cleaned_data +# forms.Form.cleaned_data >>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_reporter.last_name='%s'" % u'Smith']) [, ] diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index 6838f11d4e..cc9efd0f94 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -79,8 +79,8 @@ class ImageFile(models.Model): return self.description __test__ = {'API_TESTS': """ ->>> from django import newforms as forms ->>> from django.newforms.models import ModelForm +>>> from django import forms +>>> from django.forms.models import ModelForm >>> from django.core.files.uploadedfile import SimpleUploadedFile The bare bones, absolutely nothing custom, basic case. @@ -113,7 +113,7 @@ Replacing a field. ... model = Category >>> CategoryForm.base_fields['url'].__class__ - + Using 'fields'. @@ -211,7 +211,7 @@ We can also subclass the Meta inner class to change the fields list. # Old form_for_x tests ####################################################### ->>> from django.newforms import ModelForm, CharField +>>> from django.forms import ModelForm, CharField >>> import datetime >>> Category.objects.all() @@ -605,7 +605,7 @@ the data in the database when the form is instantiated. # ModelChoiceField ############################################################ ->>> from django.newforms import ModelChoiceField, ModelMultipleChoiceField +>>> from django.forms import ModelChoiceField, ModelMultipleChoiceField >>> f = ModelChoiceField(Category.objects.all()) >>> list(f.choices) diff --git a/tests/modeltests/model_formsets/models.py b/tests/modeltests/model_formsets/models.py index 84265450fc..5958b8c27a 100644 --- a/tests/modeltests/model_formsets/models.py +++ b/tests/modeltests/model_formsets/models.py @@ -26,7 +26,7 @@ __test__ = {'API_TESTS': """ >>> from datetime import date ->>> from django.newforms.models import modelformset_factory +>>> from django.forms.models import modelformset_factory >>> qs = Author.objects.all() >>> AuthorFormSet = modelformset_factory(Author, extra=3) @@ -227,7 +227,7 @@ used. We can also create a formset that is tied to a parent model. This is how the admin system's edit inline functionality works. ->>> from django.newforms.models import inlineformset_factory +>>> from django.forms.models import inlineformset_factory >>> AuthorBooksFormSet = inlineformset_factory(Author, Book, can_delete=False, extra=3) >>> author = Author.objects.get(name='Charles Baudelaire') diff --git a/tests/modeltests/test_client/views.py b/tests/modeltests/test_client/views.py index f4eab6462d..111c72e7f5 100644 --- a/tests/modeltests/test_client/views.py +++ b/tests/modeltests/test_client/views.py @@ -4,8 +4,8 @@ from django.core.mail import EmailMessage, SMTPConnection from django.template import Context, Template from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound from django.contrib.auth.decorators import login_required, permission_required -from django.newforms.forms import Form -from django.newforms import fields +from django.forms.forms import Form +from django.forms import fields from django.shortcuts import render_to_response def get_view(request): diff --git a/tests/regressiontests/forms/error_messages.py b/tests/regressiontests/forms/error_messages.py index 580326f894..ec91b57a06 100644 --- a/tests/regressiontests/forms/error_messages.py +++ b/tests/regressiontests/forms/error_messages.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- tests = r""" ->>> from django.newforms import * +>>> from django.forms import * >>> from django.core.files.uploadedfile import SimpleUploadedFile # CharField ################################################################### diff --git a/tests/regressiontests/forms/extra.py b/tests/regressiontests/forms/extra.py index a8b369715d..80f7ef6535 100644 --- a/tests/regressiontests/forms/extra.py +++ b/tests/regressiontests/forms/extra.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- tests = r""" ->>> from django.newforms import * +>>> from django.forms import * >>> from django.utils.encoding import force_unicode >>> import datetime >>> import time @@ -14,12 +14,12 @@ tests = r""" # Extra stuff # ############### -The newforms library comes with some extra, higher-level Field and Widget +The forms library comes with some extra, higher-level Field and Widget classes that demonstrate some of the library's abilities. # SelectDateWidget ############################################################ ->>> from django.newforms.extras import SelectDateWidget +>>> from django.forms.extras import SelectDateWidget >>> w = SelectDateWidget(years=('2007','2008','2009','2010','2011','2012','2013','2014','2015','2016')) >>> print w.render('mydate', '')