diff --git a/django/newforms/forms.py b/django/newforms/forms.py index 9f855dc4f5..feef889d83 100644 --- a/django/newforms/forms.py +++ b/django/newforms/forms.py @@ -36,7 +36,7 @@ class Form(StrAndUnicode): "A collection of Fields, plus their associated data." __metaclass__ = DeclarativeFieldsMetaclass - def __init__(self, data=None, auto_id=False): # TODO: prefix stuff + def __init__(self, data=None, auto_id='id_%s'): # TODO: prefix stuff self.ignore_errors = data is None self.data = data or {} self.auto_id = auto_id diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index e362dee671..8b71bf6adc 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -1327,25 +1327,25 @@ u'' >>> p.clean_data {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} >>> print p['first_name'] - + >>> print p['last_name'] - + >>> print p['birthday'] - + >>> for boundfield in p: ... print boundfield - - - + + + >>> for boundfield in p: ... print boundfield.label, boundfield.data First name John Last name Lennon Birthday 1940-10-9 >>> print p -First name: -Last name: -Birthday: + + + Empty dictionaries are valid, too. >>> p = Person({}) @@ -1355,29 +1355,29 @@ Empty dictionaries are valid, too. False >>> print p -First name: + -Last name: + -Birthday: + >>> print p.as_table() -First name: + -Last name: + -Birthday: + >>> print p.as_ul() -
  • First name:
  • -
  • Last name:
  • -
  • Birthday:
  • +
  • +
  • +
  • >>> print p.as_p()

    -

    First name:

    +

    -

    Last name:

    +

    -

    Birthday:

    +

    If you don't pass any values to the Form's __init__(), or if you pass None, the Form won't do any validation. Form.errors will be an empty dictionary *but* @@ -1388,30 +1388,30 @@ Form.is_valid() will return False. >>> p.is_valid() False >>> print p -First name: -Last name: -Birthday: + + + >>> print p.as_table() -First name: -Last name: -Birthday: + + + >>> print p.as_ul() -
  • First name:
  • -
  • Last name:
  • -
  • Birthday:
  • +
  • +
  • +
  • >>> print p.as_p() -

    First name:

    -

    Last name:

    -

    Birthday:

    +

    +

    +

    Unicode values are handled properly. >>> p = Person({'first_name': u'John', 'last_name': u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111', 'birthday': '1940-10-9'}) >>> p.as_table() -u'First name:\nLast name:\nBirthday:' +u'\n\n' >>> p.as_ul() -u'
  • First name:
  • \n
  • Last name:
  • \n
  • Birthday:
  • ' +u'
  • \n
  • \n
  • ' >>> p.as_p() -u'

    First name:

    \n

    Last name:

    \n

    Birthday:

    ' +u'

    \n

    \n

    ' >>> p = Person({'last_name': u'Lennon'}) >>> p.errors @@ -1437,29 +1437,29 @@ u'* This field is required.' >>> p = Person() >>> print p['first_name'] - + >>> print p['last_name'] - + >>> print p['birthday'] - + "auto_id" tells the Form to add an "id" attribute to each form element. If it's a string that contains '%s', Django will use that as a format string into which the field's name will be inserted. It will also put a @@ -1627,20 +1627,20 @@ MultipleChoiceField is a special case, as its data is required to be a list: >>> class SongForm(Form): ... name = CharField() ... composers = MultipleChoiceField() ->>> f = SongForm() +>>> f = SongForm(auto_id=False) >>> print f['composers'] >>> class SongForm(Form): ... name = CharField() ... composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')]) ->>> f = SongForm() +>>> f = SongForm(auto_id=False) >>> print f['composers'] ->>> f = SongForm({'name': 'Yesterday', 'composers': ['P']}) +>>> f = SongForm({'name': 'Yesterday', 'composers': ['P']}, auto_id=False) >>> print f['name'] >>> print f['composers'] @@ -1653,19 +1653,19 @@ MultipleChoiceField can also be used with the CheckboxSelectMultiple widget. >>> class SongForm(Form): ... name = CharField() ... composers = MultipleChoiceField(choices=[('J', 'John Lennon'), ('P', 'Paul McCartney')], widget=CheckboxSelectMultiple) ->>> f = SongForm() +>>> f = SongForm(auto_id=False) >>> print f['composers'] ->>> f = SongForm({'composers': ['J']}) +>>> f = SongForm({'composers': ['J']}, auto_id=False) >>> print f['composers'] ->>> f = SongForm({'composers': ['J', 'P']}) +>>> f = SongForm({'composers': ['J', 'P']}, auto_id=False) >>> print f['composers']