| 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 post code in the format XXXX.'] |
| 900 | >>> f.clean('20001') |
| 901 | Traceback (most recent call last): |
| 902 | ... |
| 903 | ValidationError: [u'Enter a post code in the format XXXX.'] |
| 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 post code in the format XXXX.'] |
| 922 | >>> f.clean('20001') |
| 923 | Traceback (most recent call last): |
| 924 | ... |
| 925 | ValidationError: [u'Enter a post code in the format XXXX.'] |
| 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('123') |
| 947 | Traceback (most recent call last): |
| 948 | ... |
| 949 | ValidationError: [u'Phone numbers must consist of 10 digits. Parentheses, white space and hyphens are allowed.'] |
| 950 | >>> f.clean('1800DJANGO') |
| 951 | Traceback (most recent call last): |
| 952 | ... |
| 953 | ValidationError: [u'Phone numbers must consist of 10 digits. Parentheses, white space and hyphens are allowed.'] |
| 954 | >>> f.clean(None) |
| 955 | Traceback (most recent call last): |
| 956 | ... |
| 957 | ValidationError: [u'This field is required.'] |
| 958 | >>> f.clean('') |
| 959 | Traceback (most recent call last): |
| 960 | ... |
| 961 | ValidationError: [u'This field is required.'] |
| 962 | |
| 963 | >>> f = AUPhoneNumberField(required=False) |
| 964 | >>> f.clean('1234567890') |
| 965 | u'1234567890' |
| 966 | >>> f.clean('0213456789') |
| 967 | u'0213456789' |
| 968 | >>> f.clean('02 13 45 67 89') |
| 969 | u'0213456789' |
| 970 | >>> f.clean('(02) 1345 6789') |
| 971 | u'0213456789' |
| 972 | >>> f.clean('123') |
| 973 | Traceback (most recent call last): |
| 974 | ... |
| 975 | ValidationError: [u'Phone numbers must consist of 10 digits. Parentheses, white space and hyphens are allowed.'] |
| 976 | >>> f.clean('1800DJANGO') |
| 977 | Traceback (most recent call last): |
| 978 | ... |
| 979 | ValidationError: [u'Phone numbers must consist of 10 digits. Parentheses, white space and hyphens are allowed.'] |
| 980 | >>> f.clean(None) |
| 981 | u'' |
| 982 | >>> f.clean('') |
| 983 | u'' |
| 984 | |
| 985 | ## AUStateSelect ############################################################# |
| 986 | |
| 987 | AUStateSelect is a Select widget that uses a list of Australian |
| 988 | states/territories as its choices. |
| 989 | |
| 990 | >>> from django.contrib.localflavor.au.forms import AUStateSelect |
| 991 | >>> f = AUStateSelect() |
| 992 | >>> print f.render('state', 'NSW') |
| 993 | <select name="state"> |
| 994 | <option value="ACT">Australian Capital Territory</option> |
| 995 | <option value="NSW" selected="selected">New South Wales</option> |
| 996 | <option value="NT">Northern Territory</option> |
| 997 | <option value="QLD">Queensland</option> |
| 998 | <option value="SA">South Australia</option> |
| 999 | <option value="TAS">Tasmania</option> |
| 1000 | <option value="VIC">Victoria</option> |
| 1001 | <option value="WA">Western Australia</option> |
| 1002 | </select> |