From 49b7be33e328ed92f9be1c94d409ef946e300faf Mon Sep 17 00:00:00 2001 From: Marc Aymerich Date: Wed, 12 Nov 2014 12:46:41 +0000 Subject: [PATCH] Fixed address forward email validation --- orchestra/apps/mailboxes/validators.py | 4 ++-- orchestra/apps/miscellaneous/models.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/orchestra/apps/mailboxes/validators.py b/orchestra/apps/mailboxes/validators.py index 8bee96e2..57a714e5 100644 --- a/orchestra/apps/mailboxes/validators.py +++ b/orchestra/apps/mailboxes/validators.py @@ -18,7 +18,7 @@ def validate_emailname(value): raise ValidationError(msg) value += '@localhost' try: - EmailValidator(value) + EmailValidator()(value) except ValidationError: raise ValidationError(msg) @@ -35,7 +35,7 @@ def validate_forward(value): if '@' in destination: if not destination[-1].isalpha(): raise ValidationError(msg) - EmailValidator(destination) + EmailValidator()(destination) else: if not Mailbox.objects.filter(user__username=destination).exists(): raise ValidationError(msg) diff --git a/orchestra/apps/miscellaneous/models.py b/orchestra/apps/miscellaneous/models.py index 373ea7d5..289073e4 100644 --- a/orchestra/apps/miscellaneous/models.py +++ b/orchestra/apps/miscellaneous/models.py @@ -4,6 +4,7 @@ from django.utils.translation import ugettext_lazy as _ from orchestra.core import services from orchestra.core.validators import validate_name +from orchestra.models.fields import NullableCharField class MiscService(models.Model): @@ -13,6 +14,9 @@ class MiscService(models.Model): help_text=_("Human readable name")) description = models.TextField(_("description"), blank=True, help_text=_("Optional description")) + has_identifier = models.BooleanField(_("has identifier"), default=True, + help_text=_("Designates if this service has a unique text field that " + "identifies it or not.")) has_amount = models.BooleanField(_("has amount"), default=False, help_text=_("Designates whether this service has amount " "property or not.")) @@ -35,6 +39,8 @@ class Miscellaneous(models.Model): related_name='instances') account = models.ForeignKey('accounts.Account', verbose_name=_("account"), related_name='miscellaneous') + identifier = NullableCharField(_("identifier"), max_length=256, null=True, unique=True, + blank=True, help_text=_("A unique identifier for this service.")) description = models.TextField(_("description"), blank=True) amount = models.PositiveIntegerField(_("amount"), default=1) is_active = models.BooleanField(_("active"), default=True, @@ -53,6 +59,11 @@ class Miscellaneous(models.Model): return self.is_active and self.account.is_active except type(self).account.field.rel.to.DoesNotExist: return self.is_active + + def clean(self): + if self.identifier: + self.identifier = self.identifier.strip() + self.description = self.description.strip() services.register(Miscellaneous)