From 24b7bcaf5655483a2dd66f1143bb2d7a78ea9019 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 31 Dec 2013 17:50:18 +0100 Subject: [PATCH] Fixing validation issues. see #414 --- modoboa/extensions/postfix_autoreply/__init__.py | 2 ++ modoboa/extensions/postfix_autoreply/forms.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modoboa/extensions/postfix_autoreply/__init__.py b/modoboa/extensions/postfix_autoreply/__init__.py index c28dd67e0..fce457e71 100644 --- a/modoboa/extensions/postfix_autoreply/__init__.py +++ b/modoboa/extensions/postfix_autoreply/__init__.py @@ -27,6 +27,8 @@ class PostfixAutoreply(ModoExtension): def init(self): from modoboa.extensions.admin.models import Domain + from modoboa.extensions.postfix_autoreply.general_callbacks \ + import onDomainCreated, onMailboxCreated for dom in Domain.objects.all(): try: diff --git a/modoboa/extensions/postfix_autoreply/forms.py b/modoboa/extensions/postfix_autoreply/forms.py index 211186eb1..cf9cd5ad4 100644 --- a/modoboa/extensions/postfix_autoreply/forms.py +++ b/modoboa/extensions/postfix_autoreply/forms.py @@ -30,9 +30,12 @@ class ARmessageForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ARmessageForm, self).__init__(*args, **kwargs) - self.fields.keyOrder = ['subject', 'content', 'fromdate', 'untildate', 'enabled'] + self.fields.keyOrder = [ + 'subject', 'content', 'fromdate', 'untildate', 'enabled' + ] if 'instance' in kwargs and kwargs['instance'] is not None: - self.fields['fromdate'].initial = kwargs['instance'].fromdate + self.fields['fromdate'].initial = \ + kwargs['instance'].fromdate.replace(second=0, microsecond=0) self.fields['untildate'].initial = kwargs['instance'].untildate def clean(self): @@ -46,7 +49,7 @@ class ARmessageForm(forms.ModelForm): raise forms.ValidationError(self._errors) if self.cleaned_data["fromdate"] is not None: if self.cleaned_data["fromdate"] < timezone.now(): - self._errrors["fromdate"] = self.error_class([_("This date is over")]) + self._errors["fromdate"] = self.error_class([_("This date is over")]) del self.cleaned_data['fromdate'] else: self.cleaned_data['fromdate'] = timezone.now() @@ -54,7 +57,8 @@ class ARmessageForm(forms.ModelForm): if self.cleaned_data["untildate"] < timezone.now(): self._errors["untildate"] = self.error_class([_("This date is over")]) del self.cleaned_data['untildate'] - elif self.cleaned_data['untildate'] < self.cleaned_data['fromdate']: + elif 'fromdate' in self.cleaned_data and \ + self.cleaned_data['untildate'] < self.cleaned_data['fromdate']: self._errors["untildate"] = \ self.error_class([_("Must be greater than start date")]) del self.cleaned_data['untildate']