Replacing %(name)s macro in default autoreply content.

see #432
This commit is contained in:
Antoine Nguyen
2013-11-22 15:13:17 +01:00
parent 4effce65c7
commit 5b302babd0
3 changed files with 16 additions and 2 deletions
+1 -1
View File
@@ -202,7 +202,7 @@ class GeneralParametersForm(parameters.AdminParametersForm):
tpl = self.cleaned_data["ldap_user_dn_template"]
try:
test = tpl % {"user": "toto"}
except ValueError:
except (KeyError, ValueError):
raise forms.ValidationError(_("Invalid syntax"))
return tpl
@@ -39,3 +39,16 @@ Best regards,
),
widget=forms.widgets.Textarea
)
def clean_default_content(self):
"""Check if the provided value is valid.
Must be a valid format string which will be used with the %
operator.
"""
tpl = self.cleaned_data["default_content"]
try:
test = tpl % {"name": "Antoine Nguyen"}
except (KeyError, ValueError):
raise forms.ValidationError(ugettext_lazy("Invalid syntax"))
return tpl
@@ -138,7 +138,8 @@ def save_extra_mailform_fields(form_name, mailbox, values):
else:
arm = ARmessage(mbox=mailbox)
arm.subject = parameters.get_admin("DEFAULT_SUBJECT")
arm.content = parameters.get_admin("DEFAULT_CONTENT")
arm.content = parameters.get_admin("DEFAULT_CONTENT") \
% {'name': mailbox.user.fullname}
arm.fromdate = timezone.now()
arm.enabled = True if values['autoreply'] == 'yes' else False
arm.save()