Allow an empty value as a recipient in order to deactivate a forward.

fixes #266
This commit is contained in:
Antoine Nguyen
2012-06-20 11:09:10 +02:00
parent 3f99bcd872
commit 4a72436e67
3 changed files with 24 additions and 4 deletions
+15 -3
View File
@@ -52,12 +52,24 @@ class ProfileForm(forms.ModelForm):
return user
class ForwardForm(forms.Form):
dest = forms.CharField(label=ugettext_lazy("Destination(s)"), widget=forms.Textarea)
keepcopies = forms.BooleanField(label=ugettext_lazy("Keep local copies"), required=False)
dest = forms.CharField(
label=ugettext_lazy("Recipient(s)"),
widget=forms.Textarea,
required=False,
help_text=ugettext_lazy("Indicate one or more recipients separated by a ','")
)
keepcopies = forms.BooleanField(
label=ugettext_lazy("Keep local copies"),
required=False,
help_text=ugettext_lazy("Forward messages and store copies into your local mailbox")
)
def parse_dest(self):
self.dests = []
for d in self.cleaned_data["dest"].strip().split(","):
rawdata = self.cleaned_data["dest"].strip()
if rawdata == "":
return
for d in rawdata.split(","):
local_part, domname = split_mailbox(d)
if not local_part or not domname or not len(domname):
raise BadDestination("Invalid mailbox syntax for %s" % d)
@@ -11,6 +11,9 @@ $(document).ready(function() {
$("body").notify("success", data.respmsg, 2000);
} else {
$("#form").html(data.content);
if (data.respmsg) {
$("body").notify("error", data.respmsg);
}
}
});
});
+6 -1
View File
@@ -52,8 +52,13 @@ def forward(request):
return ajax_response(request, respmsg=_("Forward updated"))
except BadDestination, e:
error = str(e)
ctx.update(form=form, error=error)
return ajax_response(request, status="ko", template="userprefs/form.html", **ctx)
return ajax_simple_response(dict(
status="ko",
content=render_to_string("userprefs/form.html", dict(form=form)),
respmsg=error
))
form = ForwardForm()
if al is not None: