Check if dates are too old only when the reply is activated.

fix #570
This commit is contained in:
Antoine Nguyen
2014-06-27 15:40:01 +02:00
parent fadc609a64
commit bf368f656a
@@ -1,5 +1,4 @@
# coding: utf-8
import datetime
from django import forms
from django.utils.translation import ugettext as _, ugettext_lazy
from django.utils import timezone
@@ -42,20 +41,25 @@ class ARmessageForm(forms.ModelForm):
"""Custom fields validaton.
We want to be sure that fromdate < untildate and that they are
both in the future.
both in the future ONLY IF the autoreply is beeing activated.
"""
super(ARmessageForm, self).clean()
if self._errors:
raise forms.ValidationError(self._errors)
if not self.cleaned_data["enabled"]:
return self.cleaned_data
if self.cleaned_data["fromdate"] is not None:
if self.cleaned_data["fromdate"] < timezone.now():
self._errors["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()
if self.cleaned_data["untildate"] is not None:
if self.cleaned_data["untildate"] < timezone.now():
self._errors["untildate"] = self.error_class([_("This date is over")])
self._errors["untildate"] = self.error_class(
[_("This date is over")])
del self.cleaned_data['untildate']
elif 'fromdate' in self.cleaned_data and \
self.cleaned_data['untildate'] < self.cleaned_data['fromdate']: