Django

Code

Changeset 4147

Show
Ignore:
Timestamp:
11/30/06 11:48:54 (2 years ago)
Author:
adrian
Message:

newforms: Added some more documentation to unit tests

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/tests/regressiontests/forms/tests.py

    r4146 r4147  
    44>>> import datetime 
    55>>> import re 
     6 
     7########### 
     8# Widgets # 
     9########### 
     10 
     11Each Widget class corresponds to an HTML form widget. A Widget knows how to 
     12render itself, given a field name and some data. Widgets don't perform 
     13validation. 
    614 
    715# TextInput Widget ############################################################ 
     
    582590>>> w.render('nums', ['ŠĐĆŽćžšđ'], choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')]) 
    583591u'<ul>\n<li><label><input type="checkbox" name="nums1" /> 1</label></li>\n<li><label><input type="checkbox" name="nums2" /> 2</label></li>\n<li><label><input type="checkbox" name="nums3" /> 3</label></li>\n<li><label><input checked="checked" type="checkbox" name="nums\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /> \u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</label></li>\n<li><label><input type="checkbox" name="nums\u0107\u017e\u0161\u0111" /> abc\u0107\u017e\u0161\u0111</label></li>\n</ul>' 
     592 
     593########## 
     594# Fields # 
     595########## 
     596 
     597Each Field class does some sort of validation. Each Field has a clean() method, 
     598which either raises django.newforms.ValidationError or returns the "clean" 
     599data -- usually a Unicode object, but, in some rare cases, a list. 
     600 
     601Each Field's __init__() takes at least these parameters: 
     602    required -- Boolean that specifies whether the field is required. 
     603                True by default. 
     604    widget -- A Widget class, or instance of a Widget class, that should be 
     605              used for this Field when displaying it. Each Field has a default 
     606              Widget that it'll use if you don't specify this. In most cases, 
     607              the default widget is TextInput. 
     608 
     609Other than that, the Field subclasses have class-specific options for 
     610__init__(). For example, CharField has a max_length option. 
    584611 
    585612# CharField ################################################################### 
     
    12381265>>> f.clean(None) 
    12391266u'' 
     1267 
     1268######### 
     1269# Forms # 
     1270######### 
     1271 
     1272A Form is a collection of Fields. It knows how to validate a set of data and it 
     1273knows how to render itself in a couple of default ways (e.g., an HTML table). 
     1274You can pass it data in __init__(), as a dictionary. 
    12401275 
    12411276# Form ########################################################################