| 1 | # -*- coding: utf-8 -*- |
| 2 | |
| 3 | tests = r""" |
| 4 | >>> from django.newforms import * |
| 5 | >>> class TestForm(Form): |
| 6 | ... f1=CharField(max_length=10) |
| 7 | ... |
| 8 | >>> TestForm(auto_id=False).as_p() |
| 9 | u'<p>F1: <input type="text" name="f1" maxlength="10" /></p>' |
| 10 | >>> class TestForm(Form): |
| 11 | ... f1=CharField(max_length=10) |
| 12 | ... class Meta: |
| 13 | ... fields_order=['baz'] |
| 14 | ... |
| 15 | Traceback (most recent call last): |
| 16 | ... |
| 17 | CommandError: f1 not present in TestForm.Meta.fields_order |
| 18 | >>> class TestForm(Form): |
| 19 | ... f1=CharField(max_length=10) |
| 20 | ... f2=CharField(max_length=10) |
| 21 | ... class Meta: |
| 22 | ... fields_order=['f1'] |
| 23 | ... |
| 24 | Traceback (most recent call last): |
| 25 | ... |
| 26 | CommandError: f2 not present in TestForm.Meta.fields_order |
| 27 | >>> class TestForm(Form): |
| 28 | ... f1=CharField(max_length=10) |
| 29 | ... class Meta: |
| 30 | ... fields_order=['f1'] |
| 31 | ... |
| 32 | >>> TestForm(auto_id=False).as_p() |
| 33 | u'<p>F1: <input type="text" name="f1" maxlength="10" /></p>' |
| 34 | >>> class TestForm(Form): |
| 35 | ... f1=CharField(max_length=10) |
| 36 | ... f2=CharField(max_length=10) |
| 37 | ... class Meta: |
| 38 | ... fields_order=['f1','f2'] |
| 39 | ... |
| 40 | >>> TestForm(auto_id=False).as_p() |
| 41 | u'<p>F1: <input type="text" name="f1" maxlength="10" /></p>\n<p>F2: <input type="text" name="f2" maxlength="10" /></p>' |
| 42 | >>> class TestForm(Form): |
| 43 | ... f1=CharField(max_length=10) |
| 44 | ... f2=CharField(max_length=10) |
| 45 | ... class Meta: |
| 46 | ... fields_order=['f2','f1'] |
| 47 | ... |
| 48 | >>> TestForm(auto_id=False).as_p() |
| 49 | u'<p>F2: <input type="text" name="f2" maxlength="10" /></p>\n<p>F1: <input type="text" name="f1" maxlength="10" /></p>' |
| 50 | >>> class SomeForm(TestForm): |
| 51 | ... f3=CharField(max_length=10) |
| 52 | ... |
| 53 | >>> TestForm(auto_id=False).as_p() |
| 54 | u'<p>F2: <input type="text" name="f2" maxlength="10" /></p>\n<p>F1: <input type="text" name="f1" maxlength="10" /></p>' |
| 55 | >>> SomeForm(auto_id=False).as_p() |
| 56 | u'<p>F2: <input type="text" name="f2" maxlength="10" /></p>\n<p>F1: <input type="text" name="f1" maxlength="10" /></p>\n<p>F3: <input type="text" name="f3" maxlength="10" /></p>' |
| 57 | >>> class SomeForm(TestForm): |
| 58 | ... f3=CharField(max_length=10) |
| 59 | ... class Meta: |
| 60 | ... fields_order=['f3'] |
| 61 | ... |
| 62 | Traceback (most recent call last): |
| 63 | ... |
| 64 | CommandError: f2 not present in SomeForm.Meta.fields_order |
| 65 | >>> class SomeForm(TestForm): |
| 66 | ... f3=CharField(max_length=10) |
| 67 | ... class Meta: |
| 68 | ... fields_order=['f3','f2','f1'] |
| 69 | ... |
| 70 | >>> SomeForm(auto_id=False).as_p() |
| 71 | u'<p>F3: <input type="text" name="f3" maxlength="10" /></p>\n<p>F2: <input type="text" name="f2" maxlength="10" /></p>\n<p>F1: <input type="text" name="f1" maxlength="10" /></p>' |
| 72 | """ |