Skip to content

Commit

Permalink
Add deconstruct to all model fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
benkonrath committed Apr 11, 2016
1 parent 65211d0 commit 8ffa807
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 38 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Modifications to existing flavors:
- Fix bug in ESIdentityCardNumberField where some valid values for NIE numbers were not
validating.
(`gh-217 <https://github.com/django/django-localflavor/pull/217>`_)
- Add deconstruct method to all model fields.
(`gh-162 <https://github.com/django/django-localflavor/pull/162>`_)
(`gh-224 <https://github.com/django/django-localflavor/pull/224>`_)

Other changes:

Expand Down
18 changes: 17 additions & 1 deletion localflavor/au/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db.models.fields import CharField
from django.db.models import CharField
from django.utils.translation import ugettext_lazy as _

from . import forms
Expand All @@ -18,6 +18,12 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 3
super(AUStateField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(AUStateField, self).deconstruct()
del kwargs['choices']
del kwargs['max_length']
return name, path, args, kwargs


class AUPostCodeField(CharField):
"""
Expand All @@ -31,6 +37,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 4
super(AUPostCodeField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(AUPostCodeField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': forms.AUPostCodeField}
defaults.update(kwargs)
Expand All @@ -48,6 +59,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 20
super(AUPhoneNumberField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(AUPhoneNumberField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': forms.AUPhoneNumberField}
defaults.update(kwargs)
Expand Down
10 changes: 10 additions & 0 deletions localflavor/bg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 10
super(BGEGNField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(BGEGNField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs


class BGEIKField(models.CharField):
"""
Expand All @@ -31,3 +36,8 @@ class BGEIKField(models.CharField):
def __init__(self, *args, **kwargs):
kwargs['max_length'] = 13
super(BGEIKField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(BGEIKField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs
6 changes: 6 additions & 0 deletions localflavor/br/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ def __init__(self, *args, **kwargs):
kwargs['choices'] = STATE_CHOICES
kwargs['max_length'] = 2
super(BRStateField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(BRStateField, self).deconstruct()
del kwargs['choices']
del kwargs['max_length']
return name, path, args, kwargs
8 changes: 7 additions & 1 deletion localflavor/ec/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.translation import ugettext_lazy as _
from django.db.models.fields import CharField
from django.db.models import CharField

from .ec_provinces import PROVINCE_CHOICES

Expand All @@ -17,3 +17,9 @@ def __init__(self, *args, **kwargs):
kwargs['choices'] = PROVINCE_CHOICES
kwargs['max_length'] = 2
super(ECProvinceField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(ECProvinceField, self).deconstruct()
del kwargs['choices']
del kwargs['max_length']
return name, path, args, kwargs
12 changes: 11 additions & 1 deletion localflavor/fr/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.translation import ugettext_lazy as _
from django.db.models.fields import CharField
from django.db.models import CharField


class FRSIRENField(CharField):
Expand All @@ -15,6 +15,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 9
super(FRSIRENField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(FRSIRENField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
from . import forms
defaults = {'form_class': forms.FRSIRENField}
Expand All @@ -35,6 +40,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 14
super(FRSIRETField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(FRSIRETField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
from . import forms
defaults = {'form_class': forms.FRSIRETField}
Expand Down
12 changes: 12 additions & 0 deletions localflavor/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ def __init__(self, use_nordea_extensions=False, include_countries=None, *args, *
self.include_countries = include_countries
self.validators.append(IBANValidator(use_nordea_extensions, include_countries))

def deconstruct(self):
name, path, args, kwargs = super(IBANField, self).deconstruct()
del kwargs['max_length']
args.append(self.use_nordea_extensions)
args.append(self.include_countries)
return name, path, args, kwargs

def to_python(self, value):
value = super(IBANField, self).to_python(value)
if value is not None:
Expand Down Expand Up @@ -75,6 +82,11 @@ def __init__(self, *args, **kwargs):
super(BICField, self).__init__(*args, **kwargs)
self.validators.append(BICValidator())

def deconstruct(self):
name, path, args, kwargs = super(BICField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def to_python(self, value):
# BIC is always written in upper case.
# https://www2.swift.com/uhbonline/books/public/en_uk/bic_policy/bic_policy.pdf
Expand Down
8 changes: 7 additions & 1 deletion localflavor/in_/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.translation import ugettext_lazy as _
from django.db.models.fields import CharField
from django.db.models import CharField

from .in_states import STATE_CHOICES

Expand All @@ -15,3 +15,9 @@ def __init__(self, *args, **kwargs):
kwargs['choices'] = STATE_CHOICES
kwargs['max_length'] = 2
super(INStateField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(INStateField, self).deconstruct()
del kwargs['choices']
del kwargs['max_length']
return name, path, args, kwargs
18 changes: 17 additions & 1 deletion localflavor/mk/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db.models.fields import CharField
from django.db.models import CharField
from django.utils.translation import ugettext_lazy as _

from .mk_choices import MK_MUNICIPALITIES
Expand All @@ -17,6 +17,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 8
super(MKIdentityCardNumberField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(MKIdentityCardNumberField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': MKIdentityCardNumberFormField}
defaults.update(kwargs)
Expand All @@ -35,6 +40,12 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 2
super(MKMunicipalityField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(MKMunicipalityField, self).deconstruct()
del kwargs['choices']
del kwargs['max_length']
return name, path, args, kwargs


class UMCNField(CharField):
"""
Expand All @@ -56,6 +67,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 13
super(UMCNField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(UMCNField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': UMCNFormField}
defaults.update(kwargs)
Expand Down
7 changes: 0 additions & 7 deletions localflavor/models.py

This file was deleted.

28 changes: 27 additions & 1 deletion localflavor/mx/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.utils.translation import ugettext_lazy as _
from django.db.models.fields import CharField
from django.db.models import CharField

from .mx_states import STATE_CHOICES
from .forms import (MXRFCField as MXRFCFormField,
Expand All @@ -19,6 +19,12 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 3
super(MXStateField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(MXStateField, self).deconstruct()
del kwargs['choices']
del kwargs['max_length']
return name, path, args, kwargs


class MXZipCodeField(CharField):
"""
Expand All @@ -31,6 +37,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 5
super(MXZipCodeField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(MXZipCodeField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': MXZipCodeFormField}
defaults.update(kwargs)
Expand All @@ -48,6 +59,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 13
super(MXRFCField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(MXRFCField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': MXRFCFormField}
defaults.update(kwargs)
Expand All @@ -65,6 +81,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 18
super(MXCURPField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(MXCURPField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': MXCURPFormField}
defaults.update(kwargs)
Expand All @@ -82,6 +103,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 11
super(MXSocialSecurityNumberField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(MXSocialSecurityNumberField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': MXSocialSecurityNumberFormField}
defaults.update(kwargs)
Expand Down
28 changes: 27 additions & 1 deletion localflavor/nl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def __init__(self, *args, **kwargs):
kwargs['max_length'] = 7
super(NLZipCodeField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(NLZipCodeField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def to_python(self, value):
value = super(NLZipCodeField, self).to_python(value)
if value is not None:
Expand All @@ -42,7 +47,7 @@ def formfield(self, **kwargs):

class NLProvinceField(models.CharField):
"""
A Dutch Provice field.
A Dutch Province field.
.. versionadded:: 1.3
"""
Expand All @@ -55,6 +60,12 @@ def __init__(self, *args, **kwargs):
})
super(NLProvinceField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(NLProvinceField, self).deconstruct()
del kwargs['choices']
del kwargs['max_length']
return name, path, args, kwargs


class NLSoFiNumberField(models.CharField):
"""
Expand All @@ -72,6 +83,11 @@ def __init__(self, *args, **kwargs):
kwargs.setdefault('max_length', 12)
super(NLSoFiNumberField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(NLSoFiNumberField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': forms.NLSoFiNumberField}
defaults.update(kwargs)
Expand All @@ -94,6 +110,11 @@ def __init__(self, *args, **kwargs):
kwargs.setdefault('max_length', 12)
super(NLPhoneNumberField, self).__init__(*args, **kwargs)

def deconstruct(self):
name, path, args, kwargs = super(NLPhoneNumberField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs

def formfield(self, **kwargs):
defaults = {'form_class': forms.NLPhoneNumberField}
defaults.update(kwargs)
Expand All @@ -113,3 +134,8 @@ def __init__(self, *args, **kwargs):
super(NLBankAccountNumberField, self).__init__(*args, **kwargs)
# Ensure that only the NLBankAccountNumberFieldValidator is set.
self.validators = [NLBankAccountNumberFieldValidator()]

def deconstruct(self):
name, path, args, kwargs = super(NLBankAccountNumberField, self).deconstruct()
del kwargs['max_length']
return name, path, args, kwargs
Empty file removed localflavor/nz/models.py
Empty file.
Loading

0 comments on commit 8ffa807

Please sign in to comment.