Author: adrian
Date: 2007-01-27 16:16:16 -0600 (Sat, 27 Jan 2007)
New Revision: 4438

Modified:
   django/trunk/tests/regressiontests/forms/tests.py
Log:
newforms: Added a unit test that tests dynamic field addition with base fields 
defined on the class

Modified: django/trunk/tests/regressiontests/forms/tests.py
===================================================================
--- django/trunk/tests/regressiontests/forms/tests.py   2007-01-27 22:06:56 UTC 
(rev 4437)
+++ django/trunk/tests/regressiontests/forms/tests.py   2007-01-27 22:16:16 UTC 
(rev 4438)
@@ -2312,6 +2312,28 @@
 <tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
 <tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
 
+>>> class MyForm(Form):
+...     default_field_1 = CharField()
+...     default_field_2 = CharField()
+...     def __init__(self, data=None, auto_id=False, field_list=[]):
+...         Form.__init__(self, data, auto_id)
+...         for field in field_list:
+...             self.fields[field[0]] = field[1]
+>>> field_list = [('field1', CharField()), ('field2', CharField())]
+>>> my_form = MyForm(field_list=field_list)
+>>> print my_form
+<tr><th>Default field 1:</th><td><input type="text" name="default_field_1" 
/></td></tr>
+<tr><th>Default field 2:</th><td><input type="text" name="default_field_2" 
/></td></tr>
+<tr><th>Field1:</th><td><input type="text" name="field1" /></td></tr>
+<tr><th>Field2:</th><td><input type="text" name="field2" /></td></tr>
+>>> field_list = [('field3', CharField()), ('field4', CharField())]
+>>> my_form = MyForm(field_list=field_list)
+>>> print my_form
+<tr><th>Default field 1:</th><td><input type="text" name="default_field_1" 
/></td></tr>
+<tr><th>Default field 2:</th><td><input type="text" name="default_field_2" 
/></td></tr>
+<tr><th>Field3:</th><td><input type="text" name="field3" /></td></tr>
+<tr><th>Field4:</th><td><input type="text" name="field4" /></td></tr>
+
 HiddenInput widgets are displayed differently in the as_table(), as_ul()
 and as_p() output of a Form -- their verbose names are not displayed, and a
 separate row is not displayed. They're displayed in the last row of the


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to