| 1 | from django.conf import settings |
| 2 | from django.db.models.fields import Field |
| 3 | from django.contrib.localflavor.au import forms |
| 4 | |
| 5 | class AUStateField(Field): |
| 6 | def get_internal_type(self): |
| 7 | return "AUStateField" |
| 8 | |
| 9 | def db_type(self): |
| 10 | if settings.DATABASE_ENGINE == 'oracle': |
| 11 | return 'CHAR(3)' |
| 12 | else: |
| 13 | return 'varchar(3)' |
| 14 | |
| 15 | def formfield(self, **kwargs): |
| 16 | defaults = {'widget': forms.AUStateSelect} |
| 17 | defaults.update(kwargs) |
| 18 | return super(AUStateField, self).formfield(**defaults) |
| 19 | |
| 20 | class AUPhoneNumberField(Field): |
| 21 | def get_internal_type(self): |
| 22 | return "AUPhoneNumberField" |
| 23 | |
| 24 | def db_type(self): |
| 25 | if settings.DATABASE_ENGINE == 'oracle': |
| 26 | return 'VARCHAR2(10)' |
| 27 | else: |
| 28 | return 'varchar(10)' |
| 29 | |
| 30 | def formfield(self, **kwargs): |
| 31 | defaults = {'form_class': forms.AUPhoneNumberField} |
| 32 | defaults.update(kwargs) |
| 33 | return super(AUPhoneNumberField, self).formfield(**defaults) |
| 34 | |
| 35 | |
| 36 | class AUPostCodeField(Field): |
| 37 | def get_internal_type(self): |
| 38 | return "AUPostCodeField" |
| 39 | |
| 40 | def db_type(self): |
| 41 | if settings.DATABASE_ENGINE == 'oracle': |
| 42 | return 'CHAR(4)' |
| 43 | else: |
| 44 | return 'varchar(4)' |
| 45 | |
| 46 | def formfield(self, **kwargs): |
| 47 | defaults = {'form_class': forms.AUPostCodeField} |
| 48 | defaults.update(kwargs) |
| 49 | return super(AUPostCodeField, self).formfield(**defaults) |