diff --git a/portail_citoyen/app_settings.py b/portail_citoyen/app_settings.py index 34036c4..12677d7 100644 --- a/portail_citoyen/app_settings.py +++ b/portail_citoyen/app_settings.py @@ -1,3 +1,4 @@ +from django.utils.translation import ugettext_lazy as _ import sys class AppSettings(object): @@ -13,6 +14,13 @@ class AppSettings(object): 'allow_redirects': False, }, 'PROFILE_FORM_PLUGIN_FORM_CLASS': 'portail_citoyen.forms.ProfileFormPluginForm', + 'POSTAL_CODE_REGEXP': r'^[0-9]*$', + 'POSTAL_CODE_MESSAGE': _('Postal code must be five numbers'), + 'HOME_PHONE_REGEXP': r'^0[1234589][0-9]{8}$', + 'HOME_PHONE_MESSAGE': _('Phone number must start with 01, 02, 03, 04, 05, 08 or 07 and be ten digits long without spaces'), + 'MOBILE_PHONE_REGEXP': r'^0[67][0-9]{8}$', + 'MOBILE_PHONE_MESSAGE': _('Mobile phone number must start with 06 or 07 and be ten digits long without spaces'), + } __prefix = 'PORTAIL_CITOYEN_' diff --git a/portail_citoyen/models.py b/portail_citoyen/models.py index 56ca9a9..8e65e3f 100644 --- a/portail_citoyen/models.py +++ b/portail_citoyen/models.py @@ -7,6 +7,8 @@ from django.contrib.auth.models import Group from authentic2.models import AbstractUser +from . import app_settings + class Citoyen(AbstractUser): title = models.CharField(pgettext_lazy('person title', 'title'), max_length=16, blank=True, @@ -20,25 +22,23 @@ class Citoyen(AbstractUser): address = models.CharField(_('address'), max_length=128, blank=True) postal_code = models.CharField(_('postal code'), max_length=5, blank=True, validators=[ - RegexValidator(r'^[0-9]*$', - _('Postal code must be five numbers'), - _('Invalid postal code')), - MinLengthValidator(5), - MaxLengthValidator(5)]) + RegexValidator(app_settings.POSTAL_CODE_REGEXP, + app_settings.POSTAL_CODE_MESSAGE, + 'invalid postal code')]) phone = models.CharField(verbose_name=_("phone"), max_length=16, blank=True, help_text=_('Phone number must start with 01, 02, 03, 04, 05, 08 or 07 and be ten digits long without spaces'), validators=[ - RegexValidator(r'^0[1234589][0-9]{8}$', - _('Phone number must start with 01, 02, 03, 04, 05, 08 or 07 and be ten digits long without spaces'), - _('Invalid mobile phone number')),]) + RegexValidator(app_settings.HOME_PHONE_REGEXP, + app_settings.HOME_PHONE_MESSAGE, + 'invalid phone'),]) mobile = models.CharField(verbose_name=_("mobile"), max_length=16, blank=True, help_text=_('Mobile phone number must start with 06 or 07 and be ten digits long without spaces'), validators=[ - RegexValidator(r'^0[67][0-9]{8}$', - _('Mobile phone number must start with 06 or 07 and be ten digits long without spaces'), - _('Invalid mobile phone number')),]) + RegexValidator(app_settings.MOBILE_PHONE_REGEXP, + app_settings.MOBILE_PHONE_MESSAGE, + 'invalid phone'),]) REQUIRED_FIELDS = ['first_name', 'last_name', 'email'] USERNAME = 'username' diff --git a/portail_citoyen/settings.py b/portail_citoyen/settings.py index b41c296..79c1321 100644 --- a/portail_citoyen/settings.py +++ b/portail_citoyen/settings.py @@ -431,6 +431,11 @@ if 'USE_MEMCACHED' in os.environ: } SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db' +for key in ('POSTAL_CODE_REGEXP', 'POSTAL_CODE_MESSAGE', 'HOME_PHONE_REGEXP', 'HOME_PHONE_MESSAGE', 'MOBILE_PHONE_REGEXP', 'MOBILE_PHONE_MESSAGE'): + key = 'PORTAIL_CITOYEN_' + key + if key in os.environ: + globals()[key] = unicode(os.environ[key], 'utf8') + # try to import local_settings.py (useless, in theory) try: from portail_citoyen.local_settings import *