From 46df077696c6b7de28fb3dd528708510ffe51e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 1 Nov 2016 15:48:01 +0100 Subject: [PATCH 1/2] admin: require both condition and error message in post conditions (#13815) --- tests/test_admin_pages.py | 2 ++ wcs/fields.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/tests/test_admin_pages.py b/tests/test_admin_pages.py index 6c33936..d0446f3 100644 --- a/tests/test_admin_pages.py +++ b/tests/test_admin_pages.py @@ -1021,6 +1021,8 @@ def test_form_edit_page_field(pub): resp.form['post_conditions$element0$error_message'] = 'bar' resp = resp.form.submit('post_conditions$add_element') resp.form['post_conditions$element1$condition'] = 'foo2' + resp = resp.form.submit('submit') + assert 'Both condition and error message are required.' in resp.body resp.form['post_conditions$element1$error_message'] = 'bar2' resp = resp.form.submit('submit') diff --git a/wcs/fields.py b/wcs/fields.py index 37614a4..dd9a8bf 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -1424,10 +1424,19 @@ class PostConditionsRowWidget(CompositeWidget): class PostConditionsTableWidget(WidgetListAsTable): readonly = False + def __init__(self, name, **kwargs): super(PostConditionsTableWidget, self).__init__(name, element_type=PostConditionsRowWidget, **kwargs) + def parse(self, request=None): + super(PostConditionsTableWidget, self).parse(request=request) + for post_condition in self.value or []: + if not (post_condition.get('error_message') and post_condition.get('condition')): + self.set_error(_('Both condition and error message are required.')) + break + return self.value + class PageField(Field): key = 'page' -- 2.10.2