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(): |