Projet

Général

Profil

0001-admin-require-both-condition-and-error-message-in-po.patch

Frédéric Péters, 01 novembre 2016 15:51

Télécharger (1,86 ko)

Voir les différences:

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(+)
tests/test_admin_pages.py
1021 1021
    resp.form['post_conditions$element0$error_message'] = 'bar'
1022 1022
    resp = resp.form.submit('post_conditions$add_element')
1023 1023
    resp.form['post_conditions$element1$condition'] = 'foo2'
1024
    resp = resp.form.submit('submit')
1025
    assert 'Both condition and error message are required.' in resp.body
1024 1026
    resp.form['post_conditions$element1$error_message'] = 'bar2'
1025 1027
    resp = resp.form.submit('submit')
1026 1028

  
wcs/fields.py
1424 1424

  
1425 1425
class PostConditionsTableWidget(WidgetListAsTable):
1426 1426
    readonly = False
1427

  
1427 1428
    def __init__(self, name, **kwargs):
1428 1429
        super(PostConditionsTableWidget, self).__init__(name,
1429 1430
                element_type=PostConditionsRowWidget, **kwargs)
1430 1431

  
1432
    def parse(self, request=None):
1433
        super(PostConditionsTableWidget, self).parse(request=request)
1434
        for post_condition in self.value or []:
1435
            if not (post_condition.get('error_message') and post_condition.get('condition')):
1436
                self.set_error(_('Both condition and error message are required.'))
1437
                break
1438
        return self.value
1439

  
1431 1440

  
1432 1441
class PageField(Field):
1433 1442
    key = 'page'
1434
-