[silva.infrae.contact][Emiliano D'Alterio] Added forced refresh ...
[email protected] Mon, 21 Oct 2013 16:53:10 +0200
| Newsgroups | gmane.comp.web.zope.silva.cvs |
|---|---|
| Message-ID | <[email protected]> |
author: Emiliano D'Alterio
date: Mon Oct 21 16:53:04 2013 +0200
revision: 10:60125a67b7c9 in silva.infrae.contact
branch:
details: https://hg.infrae.com/silva.infrae.contact?cmd=changeset;node=60125a67b7c9
modified: src/silva/infrae/contact/contactform.py
added:
removed:
log: Added forced refresh in case of form "tinkering". Made subject field
not required in order to have an html5 valid page.
diffstat:
src/silva/infrae/contact/contactform.py | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diffs (36 lines):
diff -r f7770115b8b6 -r 60125a67b7c9 src/silva/infrae/contact/contactform.py
--- a/src/silva/infrae/contact/contactform.py Thu Oct 17 13:53:44 2013 +0200
+++ b/src/silva/infrae/contact/contactform.py Mon Oct 21 16:53:04 2013 +0200
@@ -70,7 +70,7 @@
subject = schema.Choice(
title=u'Message subject',
source=subjects,
- required=True)
+ required=False)
message = schema.Text(
title=u'Message',
required=True)
@@ -140,7 +140,13 @@
if self.sstore is None:
self.sstore = store.SessionStore(self.request)
- return super(ContactForm, self).update()
+ ## if people "tinker" with the form deleting fields
+ ## we issue a redirect to force page reload,
+ ## avoiding displaying a stacktrace.
+ try:
+ return super(ContactForm, self).update()
+ except KeyError:
+ self.response.redirect(absoluteURL(self.context, self.request))
def updateWidgets(self):
sid = uuid.uuid4()
@@ -172,7 +178,7 @@
return silvaforms.FAILURE
msg = EMAIL_TEMPLATE.format(**data_dict)
- sub = u'%s from %s' % (data['st'], data['ne'])
+ sub = u'%s from %s' % (data_dict.get('st'), data_dict.get('ne'))
sendmail(self.context, msg, mto='[email protected]',
mfrom='[email protected]', subject=sub)