Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/formmail/web/formmail2.py

Issue 29386649: Issue #5011 - Moves formmail template load to handler creation (Closed) Base URL: https://hg.adblockplus.org/sitescripts
Patch Set: Created March 17, 2017, 3:46 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sitescripts/formmail/test/test_formmail2.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/formmail/web/formmail2.py
===================================================================
--- a/sitescripts/formmail/web/formmail2.py
+++ b/sitescripts/formmail/web/formmail2.py
@@ -11,17 +11,18 @@
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
import datetime
import collections
-from sitescripts.utils import get_config, sendMail, encode_email_address
+from sitescripts.utils import (get_config, sendMail, encode_email_address,
+ get_template)
from sitescripts.web import registerUrlHandler, form_handler
def get_config_items():
config = get_config()
default_keys = set(config.defaults())
for name, value in config.items('formmail2'):
if name not in default_keys:
@@ -51,29 +52,30 @@
return spec[check_type].value
return default_message
def make_handler(name, config):
try:
url = config['url'].value
except (KeyError, AttributeError):
- raise Exception('No URL configured for form handler:' + name)
+ raise Exception('No URL configured for form handler: ' + name)
try:
template = config['template'].value
+ get_template(template, autoescape=False)
except (KeyError, AttributeError):
- raise Exception('No template configured for form handler:' + name)
+ raise Exception('No template configured for form handler: ' + name)
try:
fields = config['fields']
for field, spec in fields.items():
spec.value = {s.strip() for s in spec.value.split(',')}
except KeyError:
- raise Exception('No fields configured for form handler:' + name)
+ raise Exception('No fields configured for form handler: ' + name)
if len(fields) == 0:
- raise Exception('No fields configured for form handler:' + name)
+ raise Exception('No fields configured for form handler: ' + name)
@form_handler
def handler(environ, start_response, params):
response_headers = [('Content-Type', 'text/plain; charset=utf-8')]
errors = []
for field, spec in fields.items():
if 'mandatory' in spec.value:
if field not in params.keys():
« no previous file with comments | « sitescripts/formmail/test/test_formmail2.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld