Code

Ticket #11251: au-models.diff

File au-models.diff, 2.6 KB (added by Simon Meers <DrMeers@…>, 5 years ago)

Patch which provides django.contrib.localflavor.au.models and associated documentation.

Line 
1Index: django/contrib/localflavor/au/models.py
2===================================================================
3--- django/contrib/localflavor/au/models.py     (revision 0)
4+++ django/contrib/localflavor/au/models.py     (revision 0)
5@@ -0,0 +1,49 @@
6+from django.conf import settings
7+from django.db.models.fields import Field
8+from django.contrib.localflavor.au import forms
9+
10+class AUStateField(Field):
11+    def get_internal_type(self):
12+        return "AUStateField"
13+       
14+    def db_type(self):
15+        if settings.DATABASE_ENGINE == 'oracle':
16+            return 'CHAR(3)'
17+        else:
18+            return 'varchar(3)'
19+   
20+    def formfield(self, **kwargs):
21+        defaults = {'widget': forms.AUStateSelect}
22+        defaults.update(kwargs)
23+        return super(AUStateField, self).formfield(**defaults)
24+
25+class AUPhoneNumberField(Field):
26+    def get_internal_type(self):
27+        return "AUPhoneNumberField"
28+
29+    def db_type(self):
30+        if settings.DATABASE_ENGINE == 'oracle':
31+            return 'VARCHAR2(10)'
32+        else:
33+            return 'varchar(10)'
34+
35+    def formfield(self, **kwargs):
36+        defaults = {'form_class': forms.AUPhoneNumberField}
37+        defaults.update(kwargs)
38+        return super(AUPhoneNumberField, self).formfield(**defaults)
39+
40+
41+class AUPostCodeField(Field):
42+    def get_internal_type(self):
43+        return "AUPostCodeField"
44+
45+    def db_type(self):
46+        if settings.DATABASE_ENGINE == 'oracle':
47+            return 'CHAR(4)'
48+        else:
49+            return 'varchar(4)'
50+
51+    def formfield(self, **kwargs):
52+        defaults = {'form_class': forms.AUPostCodeField}
53+        defaults.update(kwargs)
54+        return super(AUPostCodeField, self).formfield(**defaults)
55Index: docs/ref/contrib/localflavor.txt
56===================================================================
57--- docs/ref/contrib/localflavor.txt    (revision 10891)
58+++ docs/ref/contrib/localflavor.txt    (working copy)
59@@ -157,6 +157,21 @@
60     A ``Select`` widget that uses a list of Australian states/territories as its
61     choices.
62 
63+.. class:: au.models.AUPhoneNumberField
64+
65+    A model field that checks that the value is a valid Australian phone
66+    number (ten digits).
67+
68+.. class:: au.models.AUStateField
69+
70+    A model field that forms represent as a ``forms.AUStateField`` field and
71+    stores the three-letter Australian state abbreviation in the database.
72+
73+.. class:: au.models.AUPostCodeField
74+
75+    A model field that forms represent as a ``forms.AUPostCodeField`` field
76+    and stores the four-digit Australian postcode in the database.
77+
78 Austria (``at``)
79 ================
80