fix: the untildate field is not mandatory!

This commit is contained in:
tonio
2010-07-27 15:51:45 +02:00
parent 9888be1ba9
commit 5239bc2da9
10 changed files with 103 additions and 64 deletions
+7 -3
View File
@@ -4,9 +4,12 @@ from django.utils.translation import ugettext as _
import datetime
class ARmessageForm(forms.ModelForm):
untildate = forms.DateField(label=_('Until'), required=False,
help_text=_("Activate your auto reply until this date"))
class Meta:
model = ARmessage
fields = ('subject', 'content', 'enabled', 'untildate')
fields = ('subject', 'content', 'enabled')
def __init__(self, *args, **kwargs):
super(ARmessageForm, self).__init__(*args, **kwargs)
@@ -14,6 +17,7 @@ class ARmessageForm(forms.ModelForm):
self.fields['content'].widget.attrs['cols'] = 50
def clean_untildate(self):
if self.cleaned_data["untildate"] < datetime.date.today():
raise forms.ValidationError(_("This date is over"))
if self.cleaned_data["untildate"] is not None:
if self.cleaned_data["untildate"] < datetime.date.today():
raise forms.ValidationError(_("This date is over"))
return self.cleaned_data['untildate']
+1 -1
View File
@@ -55,7 +55,7 @@ def menu(**kwargs):
"url" : reverse(views.autoreply),
"img" : "/static/pics/auto-reply.png",
"class" : "boxed",
"rel" : "{handler:'iframe',size:{x:440,y:370}}",
"rel" : "{handler:'iframe',size:{x:440,y:400}}",
"label" : _("Auto-reply message")}
]
+1 -2
View File
@@ -18,8 +18,7 @@ class ARmessage(models.Model):
help_text=_("The content that will appear in sended emails"))
enabled = models.BooleanField(_('enabled'),
help_text=_("Activate/Deactivate your auto reply"))
untildate = models.DateField(_('until'),
help_text=_("Activate your auto reply until this date"))
untildate = models.DateField()
class ARhistoric(models.Model):
armessage = models.ForeignKey(ARmessage)
+2
View File
@@ -29,6 +29,7 @@ def autoreply(request):
from modoboa import userprefs
arm = form.save(commit=False)
arm.untildate = form.cleaned_data["untildate"]
arm.mbox = mb
arm.save()
messages.info(request, _("Auto reply message updated successfully."),
@@ -42,6 +43,7 @@ def autoreply(request):
mimetype="application/json")
form = ARmessageForm(instance=arm)
form.fields['untildate'].initial = arm.untildate
return _render(request, "postfix_autoreply/autoreply.html", {
"form" : form
})