Changeset 4973
- Timestamp:
- 04/09/07 06:09:17 (2 years ago)
- Files:
-
- django/branches/unicode (modified) (1 prop)
- django/branches/unicode/AUTHORS (modified) (1 diff)
- django/branches/unicode/django/contrib/localflavor/au (copied) (copied from django/trunk/django/contrib/localflavor/au)
- django/branches/unicode/django/contrib/localflavor/au/au_states.py (copied) (copied from django/trunk/django/contrib/localflavor/au/au_states.py)
- django/branches/unicode/django/contrib/localflavor/au/forms.py (copied) (copied from django/trunk/django/contrib/localflavor/au/forms.py)
- django/branches/unicode/django/contrib/localflavor/au/__init__.py (copied) (copied from django/trunk/django/contrib/localflavor/au/__init__.py)
- django/branches/unicode/django/contrib/localflavor/br/br_states.py (modified) (1 diff)
- django/branches/unicode/django/contrib/localflavor/fi/forms.py (modified) (2 diffs)
- django/branches/unicode/django/contrib/localflavor/us (copied) (copied from django/trunk/django/contrib/localflavor/us)
- django/branches/unicode/django/contrib/localflavor/usa (deleted)
- django/branches/unicode/django/contrib/localflavor/us/forms.py (copied) (copied from django/trunk/django/contrib/localflavor/us/forms.py)
- django/branches/unicode/django/contrib/localflavor/us/__init__.py (copied) (copied from django/trunk/django/contrib/localflavor/us/__init__.py)
- django/branches/unicode/django/contrib/localflavor/us/us_states.py (copied) (copied from django/trunk/django/contrib/localflavor/us/us_states.py)
- django/branches/unicode/django/db/models/fields/__init__.py (modified) (1 diff)
- django/branches/unicode/django/newforms/widgets.py (modified) (1 diff)
- django/branches/unicode/django/views/debug.py (modified) (2 diffs)
- django/branches/unicode/docs/django-admin.txt (modified) (7 diffs)
- django/branches/unicode/docs/documentation.txt (modified) (2 diffs)
- django/branches/unicode/docs/legacy_databases.txt (modified) (2 diffs)
- django/branches/unicode/docs/modpython.txt (modified) (4 diffs)
- django/branches/unicode/docs/request_response.txt (modified) (1 diff)
- django/branches/unicode/docs/url_dispatch.txt (modified) (4 diffs)
- django/branches/unicode/tests/modeltests/model_forms/models.py (modified) (5 diffs)
- django/branches/unicode/tests/regressiontests/forms/localflavor.py (modified) (6 diffs)
- django/branches/unicode/tests/regressiontests/forms/tests.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/unicode
- Property svnmerge-integrated changed from /django/trunk:1-4951 to /django/trunk:1-4971
django/branches/unicode/AUTHORS
r4937 r4973 89 89 Marc Fargas <telenieko@telenieko.com> 90 90 favo@exoweb.net 91 Matthew Flanagan <http://wadofstuff.blogspot.com> 91 92 Eric Floehr <eric@intellovations.com> 92 93 Jorge Gajon <gajon@gajon.org> django/branches/unicode/django/contrib/localflavor/br/br_states.py
r4874 r4973 1 1 # -*- coding: utf-8 -*- 2 2 """ 3 A brazilian mapping of state misspellings/abbreviations to normalized 4 abbreviations, and an alphabetical list of states for use as `choices 5 in a formfield. 3 An alphabetical list of Brazilian states for use as `choices` in a formfield. 6 4 7 This exists in this standalone file so that it's only imported into 8 memorywhen explicitly needed.5 This exists in this standalone file so that it's only imported into memory 6 when explicitly needed. 9 7 """ 10 8 django/branches/unicode/django/contrib/localflavor/fi/forms.py
r4868 r4973 27 27 super(FISocialSecurityNumber, self).clean(value) 28 28 if value in EMPTY_VALUES: 29 return u''30 29 return u'' 30 31 31 checkmarks = "0123456789ABCDEFHJKLMNPRSTUVWXY" 32 32 result = re.match(r"""^ … … 36 36 [A+-] 37 37 (?P<serial>(\d{3})) 38 (?P<chec hsum>[%s])$""" % checkmarks, value, re.VERBOSE | re.IGNORECASE)38 (?P<checksum>[%s])$""" % checkmarks, value, re.VERBOSE | re.IGNORECASE) 39 39 if not result: 40 40 raise ValidationError(gettext(u'Enter a valid Finnish social security number.')) 41 checksum = int(result.groupdict()['date'] + result.groupdict()['serial'])42 43 if checkmarks[checksum % len(checkmarks)] == result.groupdict()['chechsum'].upper():41 gd = result.groupdict() 42 checksum = int(gd['date'] + gd['serial']) 43 if checkmarks[checksum % len(checkmarks)] == gd['checksum'].upper(): 44 44 return u'%s' % value.upper() 45 46 45 raise ValidationError(gettext(u'Enter a valid Finnish social security number.')) 47 django/branches/unicode/django/db/models/fields/__init__.py
r4752 r4973 762 762 763 763 def formfield(self, **kwargs): 764 from django.contrib.localflavor.us a.forms import USPhoneNumberField764 from django.contrib.localflavor.us.forms import USPhoneNumberField 765 765 defaults = {'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text} 766 766 defaults.update(kwargs) django/branches/unicode/django/newforms/widgets.py
r4918 r4973 122 122 123 123 class Textarea(Widget): 124 def __init__(self, attrs=None): 125 # The 'rows' and 'cols' attributes are required for HTML correctness. 126 self.attrs = {'cols': '40', 'rows': '10'} 127 if attrs: 128 self.attrs.update(attrs) 129 124 130 def render(self, name, value, attrs=None): 125 131 if value is None: value = '' django/branches/unicode/django/views/debug.py
r4265 r4973 145 145 c = Context({ 146 146 'root_urlconf': settings.ROOT_URLCONF, 147 'request_path': request.path[1:], # Trim leading slash 147 148 'urlpatterns': tried, 148 149 'reason': str(exception), … … 592 593 {% endfor %} 593 594 </ol> 594 <p>The current URL, <code>{{ request .path|escape }}</code>, didn't match any of these.</p>595 <p>The current URL, <code>{{ request_path|escape }}</code>, didn't match any of these.</p> 595 596 {% else %} 596 597 <p>{{ reason|escape }}</p> django/branches/unicode/docs/django-admin.txt
r4937 r4973 30 30 Django settings files. 31 31 32 The command-line examples throughout this document use ``django-admin.py`` to 33 be consistent, but any example can use ``manage.py`` just as well. 34 32 35 Usage 33 36 ===== … … 101 104 ------------------------------ 102 105 103 Output to standard output all data in the database associated with the named 106 Output to standard output all data in the database associated with the named 104 107 application(s). 105 108 106 109 By default, the database will be dumped in JSON format. If you want the output 107 to be in another format, use the ``--format`` option (e.g., ``format=xml``). 108 You may specify any Django serialization backend (including any user specified 110 to be in another format, use the ``--format`` option (e.g., ``format=xml``). 111 You may specify any Django serialization backend (including any user specified 109 112 serialization backends named in the ``SERIALIZATION_MODULES`` setting). 110 113 111 114 If no application name is provided, all installed applications will be dumped. 112 115 113 The output of ``dumpdata`` can be used as input for ``loaddata``. 116 The output of ``dumpdata`` can be used as input for ``loaddata``. 114 117 115 118 flush 116 119 ----- 117 120 118 Return the database to the state it was in immediately after syncdb was 119 executed. This means that all data will be removed from the database, any 121 Return the database to the state it was in immediately after syncdb was 122 executed. This means that all data will be removed from the database, any 120 123 post-synchronization handlers will be re-executed, and the ``initial_data`` 121 124 fixture will be re-installed. … … 179 182 180 183 Django will load any and all fixtures it finds in these locations that match 181 the provided fixture names. 182 183 If the named fixture has a file extension, only fixtures of that type 184 the provided fixture names. 185 186 If the named fixture has a file extension, only fixtures of that type 184 187 will be loaded. For example:: 185 188 186 189 django-admin.py loaddata mydata.json 187 188 would only load JSON fixtures called ``mydata``. The fixture extension 189 must correspond to the registered name of a serializer (e.g., ``json`` or 190 191 would only load JSON fixtures called ``mydata``. The fixture extension 192 must correspond to the registered name of a serializer (e.g., ``json`` or 190 193 ``xml``). 191 194 192 If you omit the extension, Django will search all available fixture types 195 If you omit the extension, Django will search all available fixture types 193 196 for a matching fixture. For example:: 194 197 195 198 django-admin.py loaddata mydata 196 199 197 200 would look for any fixture of any fixture type called ``mydata``. If a fixture 198 201 directory contained ``mydata.json``, that fixture would be loaded 199 as a JSON fixture. However, if two fixtures with the same name but different 200 fixture type are discovered (for example, if ``mydata.json`` and 201 ``mydata.xml`` were found in the same fixture directory), fixture 202 installation will be aborted, and any data installed in the call to 202 as a JSON fixture. However, if two fixtures with the same name but different 203 fixture type are discovered (for example, if ``mydata.json`` and 204 ``mydata.xml`` were found in the same fixture directory), fixture 205 installation will be aborted, and any data installed in the call to 203 206 ``loaddata`` will be removed from the database. 204 207 205 The fixtures that are named can include directory components. These 208 The fixtures that are named can include directory components. These 206 209 directories will be included in the search path. For example:: 207 210 208 211 django-admin.py loaddata foo/bar/mydata.json 209 210 would search ``<appname>/fixtures/foo/bar/mydata.json`` for each installed 211 application, ``<dirname>/foo/bar/mydata.json`` for each directory in 212 213 would search ``<appname>/fixtures/foo/bar/mydata.json`` for each installed 214 application, ``<dirname>/foo/bar/mydata.json`` for each directory in 212 215 ``FIXTURE_DIRS``, and the literal path ``foo/bar/mydata.json``. 213 216 … … 220 223 .. admonition:: MySQL and Fixtures 221 224 222 Unfortunately, MySQL isn't capable of completely supporting all the 225 Unfortunately, MySQL isn't capable of completely supporting all the 223 226 features of Django fixtures. If you use MyISAM tables, MySQL doesn't 224 support transactions or constraints, so you won't get a rollback if 225 multiple transaction files are found, or validation of fixture data. 226 If you use InnoDB tables, you won't be able to have any forward 227 references in your data files - MySQL doesn't provide a mechanism to 228 defer checking of row constraints until a transaction is committed. 229 227 support transactions or constraints, so you won't get a rollback if 228 multiple transaction files are found, or validation of fixture data. 229 If you use InnoDB tables, you won't be able to have any forward 230 references in your data files - MySQL doesn't provide a mechanism to 231 defer checking of row constraints until a transaction is committed. 232 230 233 reset [appname appname ...] 231 234 --------------------------- … … 398 401 give you the option of creating a superuser immediately. 399 402 400 ``syncdb`` will also search for and install any fixture named ``initial_data``. 401 See the documentation for ``loaddata`` for details on the specification of 403 ``syncdb`` will also search for and install any fixture named ``initial_data``. 404 See the documentation for ``loaddata`` for details on the specification of 402 405 fixture data files. 403 406 … … 472 475 django-admin.py dumpdata --indent=4 473 476 474 Specifies the number of spaces that will be used for indentation when 477 Specifies the number of spaces that will be used for indentation when 475 478 pretty-printing output. By default, output will *not* be pretty-printed. 476 479 Pretty-printing will only be enabled if the indent option is provided. … … 513 516 514 517 Example usage:: 515 django-admin.py manage.py --adminmedia=/tmp/new-admin-style/ 518 519 django-admin.py --adminmedia=/tmp/new-admin-style/ 516 520 517 521 Tells Django where to find the various CSS and JavaScript files for the admin django/branches/unicode/docs/documentation.txt
r3561 r4973 43 43 The most recent version of the Django documentation lives at 44 44 http://www.djangoproject.com/documentation/ . These HTML pages are generated 45 automatically from the text files in source control every 15 minutes. That46 means they reflect the "latest and greatest" in Django -- they include the very 47 latestcorrections and additions, and they discuss the latest Django features,45 automatically from the text files in source control. That means they reflect 46 the "latest and greatest" in Django -- they include the very latest 47 corrections and additions, and they discuss the latest Django features, 48 48 which may only be available to users of the Django development version. (See 49 49 "Differences between versions" below.) 50 50 51 A key advantage of the Web-based documentation is the comment section at the 52 bottom of each document. This is an area for anybody to submit changes, 53 corrections and suggestions about the given document. The Django developers 54 frequently monitor the comments there and use them to improve the documentation 55 for everybody. 51 We encourage you to help improve the docs by submitting changes, corrections 52 and suggestions in the `ticket system`_. The Django developers actively monitor 53 the ticket system and use your feedback to improve the documentation for 54 everybody. 56 55 57 We encourage you to help improve the docs: it's easy! Note, however, that 58 comments should explicitly relate to the documentation, rather than asking 59 broad tech-support questions. If you need help with your particular Django 60 setup, try the `django-users mailing list`_ instead of posting a comment to the 61 documentation. 56 Note, however, that tickets should explicitly relate to the documentation, 57 rather than asking broad tech-support questions. If you need help with your 58 particular Django setup, try the `django-users mailing list`_ or the 59 `#django IRC channel`_ instead. 62 60 61 .. _ticket system: http://code.djangoproject.com/simpleticket?component=Documentation 63 62 .. _django-users mailing list: http://groups.google.com/group/django-users 63 .. _#django IRC channel: irc://irc.freenode.net/django 64 64 65 65 In plain text … … 135 135 and links to the current version of that document. 136 136 137 * Once a document is frozen for a Django release, we remove comments from138 that page, in favor of having comments on the latest version of that139 document. This is for the sake of maintainability and usability, so that140 users have one, and only one, place to leave comments on a particular141 document. We realize that some people may be stuck on a previous version142 of Django, but we believe the usability problems with multiple versions143 of a document the outweigh the benefits.144 145 137 * The `main documentation Web page`_ includes links to documentation for 146 138 all previous versions. django/branches/unicode/docs/legacy_databases.txt
r4420 r4973 40 40 database. You can view the output by running this command:: 41 41 42 django-admin.py inspectdb --settings=path.to.settings42 python manage.py inspectdb 43 43 44 44 Save this as a file by using standard Unix output redirection:: 45 45 46 django-admin.py inspectdb --settings=path.to.settings> models.py46 python manage.py inspectdb > models.py 47 47 48 48 This feature is meant as a shortcut, not as definitive model generation. See … … 61 61 records such as admin permissions and content types:: 62 62 63 django-admin.py init --settings=path.to.settings63 python manage.py syncdb 64 64 65 65 See whether it worked django/branches/unicode/docs/modpython.txt
r4897 r4973 58 58 .. caution:: 59 59 60 I s you are using Windows, remember that the path will contain backslashes.60 If you're using Windows, remember that the path will contain backslashes. 61 61 This string is passed through Python's string parser twice, so you need to 62 62 escape each backslash **twice**:: … … 64 64 PythonPath "['c:\\\\path\\\\to\\\\project'] + sys.path" 65 65 66 oruse raw strings::66 Or, use raw strings:: 67 67 68 68 PythonPath "[r'c:\\path\\to\\project'] + sys.path" 69 70 69 71 70 You can also add directives such as ``PythonAutoReload Off`` for performance. … … 162 161 particular part of the site:: 163 162 164 <Location "/media /">163 <Location "/media"> 165 164 SetHandler None 166 165 </Location> … … 179 178 </Location> 180 179 181 <Location " media">180 <Location "/media"> 182 181 SetHandler None 183 182 </Location> django/branches/unicode/docs/request_response.txt
r4890 r4973 484 484 called ``404.html`` and located in the top level of your template tree. 485 485 486 Customi ng error views487 --------------------- 486 Customizing error views 487 ----------------------- 488 488 489 489 The 404 (page not found) view django/branches/unicode/docs/url_dispatch.txt
r4903 r4973 193 193 url 194 194 --- 195 **New in development version** 196 197 The ``url()`` function can be used instead of a tuple as an argument to 198 ``patterns()``. This is convenient if you wish to specify a name without the 195 196 **New in Django development version** 197 198 You can use the ``url()`` function, instead of a tuple, as an argument to 199 ``patterns()``. This is convenient if you want to specify a name without the 199 200 optional extra arguments dictionary. For example:: 200 201 … … 499 500 =================== 500 501 501 **New in development version** 502 503 It is fairly common to use the same view function in multiple URL patterns in 504 your URLConf. This leads to problems when you come to do reverse URL matching, 505 because the ``permalink()`` decorator and ``{% url %}`` template tag use the 506 name of the view function to find a match. 507 508 To solve this problem, you can give a name to each of your URL patterns in 509 order to distinguish them from other patterns using the same views and 510 parameters. You can then use this name wherever you would otherwise use the 511 name of the view function. For example, if you URLConf contains:: 502 **New in Django development version** 503 504 It's fairly common to use the same view function in multiple URL patterns in 505 your URLconf. For example, these two URL patterns both point to the ``archive`` 506 view:: 507 508 urlpatterns = patterns('', 509 (r'/archive/(\d{4})/$', archive), 510 (r'/archive-summary/(\d{4})/$', archive, {'summary': True}), 511 ) 512 513 This is completely valid, but it leads to problems when you try to do reverse 514 URL matching (through the ``permalink()`` decorator or the ``{% url %}`` 515 template tag). Continuing this example, if you wanted to retrieve the URL for 516 the ``archive`` view, Django's reverse URL matcher would get confused, because 517 *two* URLpatterns point at that view. 518 519 To solve this problem, Django supports **named URL patterns**. That is, you can 520 give a name to a URL pattern in order to distinguish it from other patterns 521 using the same view and parameters. Then, you can use this name in reverse URL 522 matching. 523 524 Here's the above example, rewritten to used named URL patterns:: 512 525 513 526 urlpatterns = patterns('', … … 516 529 ) 517 530 518 ...you could refer to either the summary archive view in a template as:: 531 With these names in place (``full-archive`` and ``arch-summary``), you can 532 target each pattern individually by using its name:: 519 533 520 534 {% url arch-summary 1945 %} 535 {% url full-archive 2007 %} 521 536 522 537 Even though both URL patterns refer to the ``archive`` view here, using the … … 528 543 .. note:: 529 544 530 Make sure that when you name your URLs, you use names that are unlikely to 531 clash with any other application's choice of names. If you call your URL 532 pattern *comment* and another application does the same thing, there is no 533 guarantee which URL will be inserted into your template when you use this 534 name. Putting a prefix on your URL names, perhaps derived from 535 the application name, will decrease the chances of collision. Something 536 like *myapp-comment* is recommended over simply *comment*. 537 545 When you name your URL patterns, make sure you use names that are unlikely 546 to clash with any other application's choice of names. If you call your URL 547 pattern ``comment``, and another application does the same thing, there's 548 no guarantee which URL will be inserted into your template when you use 549 this name. 550 551 Putting a prefix on your URL names, perhaps derived from the application 552 name, will decrease the chances of collision. We recommend something like 553 ``myapp-comment`` instead of ``comment``. django/branches/unicode/tests/modeltests/model_forms/models.py
r4971 r4973 160 160 <option value="2">Bob Woodward</option> 161 161 </select></td></tr> 162 <tr><th>Article:</th><td><textarea name="article"></textarea></td></tr>162 <tr><th>Article:</th><td><textarea rows="10" cols="40" name="article"></textarea></td></tr> 163 163 <tr><th>Categories:</th><td><select multiple="multiple" name="categories"> 164 164 <option value="1">Entertainment</option> … … 200 200 <option value="2">Bob Woodward</option> 201 201 </select></li> 202 <li>Article: <textarea name="article">Hello.</textarea></li>202 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 203 203 <li>Categories: <select multiple="multiple" name="categories"> 204 204 <option value="1">Entertainment</option> … … 232 232 <option value="2">Bob Woodward</option> 233 233 </select></li> 234 <li>Article: <textarea name="article">Hello.</textarea></li>234 <li>Article: <textarea rows="10" cols="40" name="article">Hello.</textarea></li> 235 235 <li>Categories: <select multiple="multiple" name="categories"> 236 236 <option value="1" selected="selected">Entertainment</option> … … 310 310 <option value="2">Bob Woodward</option> 311 311 </select></li> 312 <li>Article: <textarea name="article"></textarea></li>312 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li> 313 313 <li>Categories: <select multiple="multiple" name="categories"> 314 314 <option value="1">Entertainment</option> … … 329 329 <option value="3">Carl Bernstein</option> 330 330 </select></li> 331 <li>Article: <textarea name="article"></textarea></li>331 <li>Article: <textarea rows="10" cols="40" name="article"></textarea></li> 332 332 <li>Categories: <select multiple="multiple" name="categories"> 333 333 <option value="1">Entertainment</option> django/branches/unicode/tests/regressiontests/forms/localflavor.py
r4939 r4973 7 7 USZipCodeField validates that the data is either a five-digit U.S. zip code or 8 8 a zip+4. 9 >>> from django.contrib.localflavor.us a.forms import USZipCodeField9 >>> from django.contrib.localflavor.us.forms import USZipCodeField 10 10 >>> f = USZipCodeField() 11 11 >>> f.clean('60606') … … 68 68 USPhoneNumberField validates that the data is a valid U.S. phone number, 69 69 including the area code. It's normalized to XXX-XXX-XXXX format. 70 >>> from django.contrib.localflavor.us a.forms import USPhoneNumberField70 >>> from django.contrib.localflavor.us.forms import USPhoneNumberField 71 71 >>> f = USPhoneNumberField() 72 72 >>> f.clean('312-555-1212') … … 137 137 USStateField validates that the data is either an abbreviation or name of a 138 138 U.S. state. 139 >>> from django.contrib.localflavor.us a.forms import USStateField139 >>> from django.contrib.localflavor.us.forms import USStateField 140 140 >>> f = USStateField() 141 141 >>> f.clean('il') … … 182 182 USStateSelect is a Select widget that uses a list of U.S. states/territories 183 183 as its choices. 184 >>> from django.contrib.localflavor.us a.forms import USStateSelect184 >>> from django.contrib.localflavor.us.forms import USStateSelect 185 185 >>> w = USStateSelect() 186 186 >>> print w.render('state', 'IL') … … 248 248 249 249 # USSocialSecurityNumberField ################################################# 250 >>> from django.contrib.localflavor.us a.forms import USSocialSecurityNumberField250 >>> from django.contrib.localflavor.us.forms import USSocialSecurityNumberField 251 251 >>> f = USSocialSecurityNumberField() 252 252 >>> f.clean('987-65-4330') … … 883 883 ... 884 884 ValidationError: [u'Enter a valid German identity card number in XXXXXXXXXXX-XXXXXXX-XXXXXXX-X format.'] 885 886 ## AUPostCodeField ########################################################## 887 888 A field that accepts a four digit Australian post code. 889 890 >>> from django.contrib.localflavor.au.forms import AUPostCodeField 891 >>> f = AUPostCodeField() 892 >>> f.clean('1234') 893 u'1234' 894 >>> f.clean('2000') 895 u'2000' 896 >>> f.clean('abcd') 897 Traceback (most recent call last): 898 ... 899 ValidationError: [u'Enter a 4 digit post code.'] 900 >>> f.clean('20001') 901 Traceback (most recent call last): 902 ... 903 ValidationError: [u'Enter a 4 digit post code.'] 904 >>> f.clean(None) 905 Traceback (most recent call last): 906 ... 907 ValidationError: [u'This field is required.'] 908 >>> f.clean('') 909 Traceback (most recent call last): 910 ... 911 ValidationError: [u'This field is required.'] 912 913 >>> f = AUPostCodeField(required=False) 914 >>> f.clean('1234') 915 u'1234' 916 >>> f.clean('2000') 917 u'2000' 918 >>> f.clean('abcd') 919 Traceback (most recent call last): 920 ... 921 ValidationError: [u'Enter a 4 digit post code.'] 922 >>> f.clean('20001') 923 Traceback (most recent call last): 924 ... 925 ValidationError: [u'Enter a 4 digit post code.'] 926 >>> f.clean(None) 927 u'' 928 >>> f.clean('') 929 u'' 930 931 ## AUPhoneNumberField ######################################################## 932 933 A field that accepts a 10 digit Australian phone number. 934 llows spaces and parentheses around area code. 935 936 >>> from django.contrib.localflavor.au.forms import AUPhoneNumberField 937 >>> f = AUPhoneNumberField() 938 >>> f.clean('1234567890') 939 u'1234567890' 940 >>> f.clean('0213456789') 941 u'0213456789' 942 >>> f.clean('02 13 45 67 89') 943 u'0213456789' 944 >>> f.clean('(02) 1345 6789') 945 u'0213456789' 946 >>> f.clean('(02) 1345-6789') 947 u'0213456789' 948 >>> f.clean('(02)1345-6789') 949 u'0213456789' 950 >>> f.clean('0408 123 456') 951 u'0408123456' 952 >>> f.clean('123') 953 Traceback (most recent call last): 954 ... 955 ValidationError: [u'Phone numbers must contain 10 digits.'] 956 >>> f.clean('1800DJANGO') 957 Traceback (most recent call last): 958 ... 959 ValidationError: [u'Phone numbers must contain 10 digits.'] 960 >>> f.clean(None) 961 Traceback (most recent call last): 962 ... 963 ValidationError: [u'This field is required.'] 964 >>> f.clean('') 965 Traceback (most recent call last): 966 ... 967 ValidationError: [u'This field is required.'] 968 969 >>> f = AUPhoneNumberField(required=False) 970 >>> f.clean('1234567890') 971 u'1234567890' 972 >>> f.clean('0213456789') 973 u'0213456789' 974 >>> f.clean('02 13 45 67 89') 975 u'0213456789' 976 >>> f.clean('(02) 1345 6789') 977 u'0213456789' 978 >>> f.clean('(02) 1345-6789') 979 u'0213456789' 980 >>> f.clean('(02)1345-6789') 981 u'0213456789' 982 >>> f.clean('0408 123 456') 983 u'0408123456' 984 >>> f.clean('123') 985 Traceback (most recent call last): 986 ... 987 ValidationError: [u'Phone numbers must contain 10 digits.'] 988 >>> f.clean('1800DJANGO') 989 Traceback (most recent call last): 990 ... 991 ValidationError: [u'Phone numbers must contain 10 digits.'] 992 >>> f.clean(None) 993 u'' 994 >>> f.clean('') 995 u'' 996 997 ## AUStateSelect ############################################################# 998 999 AUStateSelect is a Select widget that uses a list of Australian 1000 states/territories as its choices. 1001 1002 >>> from django.contrib.localflavor.au.forms import AUStateSelect 1003 >>> f = AUStateSelect() 1004 >>> print f.render('state', 'NSW') 1005 <select name="state"> 1006 <option value="ACT">Australian Capital Territory</option> 1007 <option value="NSW" selected="selected">New South Wales</option> 1008 <option value="NT">Northern Territory</option> 1009 <option value="QLD">Queensland</option> 1010 <option value="SA">South Australia</option> 1011 <option value="TAS">Tasmania</option> 1012 <option value="VIC">Victoria</option> 1013 <option value="WA">Western Australia</option> 1014 </select> 885 1015 """ django/branches/unicode/tests/regressiontests/forms/tests.py
r4930 r4973 194 194 >>> w = Textarea() 195 195 >>> w.render('msg', '') 196 u'<textarea name="msg"></textarea>'196 u'<textarea rows="10" cols="40" name="msg"></textarea>' 197 197 >>> w.render('msg', None) 198 u'<textarea name="msg"></textarea>'198 u'<textarea rows="10" cols="40" name="msg"></textarea>' 199 199 >>> w.render('msg', 'value') 200 u'<textarea name="msg">value</textarea>'200 u'<textarea rows="10" cols="40" name="msg">value</textarea>' 201 201 >>> w.render('msg', 'some "quoted" & ampersanded value') 202 u'<textarea name="msg">some "quoted" & ampersanded value</textarea>'203 >>> w.render('msg', 'value', attrs={'class': 'pretty' })204 u'<textarea name="msg" class="pretty">value</textarea>'202 u'<textarea rows="10" cols="40" name="msg">some "quoted" & ampersanded value</textarea>' 203 >>> w.render('msg', 'value', attrs={'class': 'pretty', 'rows': 20}) 204 u'<textarea class="pretty" rows="20" cols="40" name="msg">value</textarea>' 205 205 206 206 You can also pass 'attrs' to the constructor: 207 207 >>> w = Textarea(attrs={'class': 'pretty'}) 208 208 >>> w.render('msg', '') 209 u'<textarea class="pretty" name="msg"></textarea>'209 u'<textarea rows="10" cols="40" name="msg" class="pretty"></textarea>' 210 210 >>> w.render('msg', 'example') 211 u'<textarea class="pretty" name="msg">example</textarea>'211 u'<textarea rows="10" cols="40" name="msg" class="pretty">example</textarea>' 212 212 213 213 'attrs' passed to render() get precedence over those passed to the constructor: 214 214 >>> w = Textarea(attrs={'class': 'pretty'}) 215 215 >>> w.render('msg', '', attrs={'class': 'special'}) 216 u'<textarea class="special" name="msg"></textarea>'216 u'<textarea rows="10" cols="40" name="msg" class="special"></textarea>' 217 217 218 218 >>> w.render('msg', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'}) 219 u'<textarea class="fun" name="msg">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>'219 u'<textarea rows="10" cols="40" name="msg" class="fun">\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111</textarea>' 220 220 221 221 # CheckboxInput Widget ######################################################## … … 1967 1967 <input type="text" name="subject" /> 1968 1968 >>> print f['message'] 1969 <textarea name="message"></textarea>1969 <textarea rows="10" cols="40" name="message"></textarea> 1970 1970 1971 1971 as_textarea(), as_text() and as_hidden() are shortcuts for changing the output 1972 1972 widget type: 1973 1973 >>> f['subject'].as_textarea() 1974 u'<textarea name="subject"></textarea>'1974 u'<textarea rows="10" cols="40" name="subject"></textarea>' 1975 1975 >>> f['message'].as_text() 1976 1976 u'<input type="text" name="message" />' … … 1992 1992 >>> f = ContactForm({'subject': 'Hello', 'message': 'I love you.'}, auto_id=False) 1993 1993 >>> f['subject'].as_textarea() 1994 u'<textarea name="subject">Hello</textarea>'1994 u'<textarea rows="10" cols="40" name="subject">Hello</textarea>' 1995 1995 >>> f['message'].as_text() 1996 1996 u'<input type="text" name="message" value="I love you." />'
