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