From 89d1270e51e0a04f162f6ba9ff955859f17d1bae Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Thu, 30 Nov 2006 17:48:54 +0000 Subject: [PATCH] newforms: Added some more documentation to unit tests git-svn-id: http://code.djangoproject.com/svn/django/trunk@4147 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 2fb468ace2..f52635f875 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -4,6 +4,14 @@ r""" >>> import datetime >>> import re +########### +# Widgets # +########### + +Each Widget class corresponds to an HTML form widget. A Widget knows how to +render itself, given a field name and some data. Widgets don't perform +validation. + # TextInput Widget ############################################################ >>> w = TextInput() @@ -582,6 +590,25 @@ If 'choices' is passed to both the constructor and render(), then they'll both b >>> w.render('nums', ['ŠĐĆŽćžšđ'], choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')]) u'' +########## +# Fields # +########## + +Each Field class does some sort of validation. Each Field has a clean() method, +which either raises django.newforms.ValidationError or returns the "clean" +data -- usually a Unicode object, but, in some rare cases, a list. + +Each Field's __init__() takes at least these parameters: + required -- Boolean that specifies whether the field is required. + True by default. + widget -- A Widget class, or instance of a Widget class, that should be + used for this Field when displaying it. Each Field has a default + Widget that it'll use if you don't specify this. In most cases, + the default widget is TextInput. + +Other than that, the Field subclasses have class-specific options for +__init__(). For example, CharField has a max_length option. + # CharField ################################################################### >>> f = CharField() @@ -1238,6 +1265,14 @@ u'' >>> f.clean(None) u'' +######### +# Forms # +######### + +A Form is a collection of Fields. It knows how to validate a set of data and it +knows how to render itself in a couple of default ways (e.g., an HTML table). +You can pass it data in __init__(), as a dictionary. + # Form ######################################################################## >>> class Person(Form):