From b0e5854833b28927a5530a7a48c117d10fbe19d2 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 28 Apr 2013 10:19:05 +0200 Subject: [PATCH] Fixed #629 --- openslides/utils/forms.py | 15 ++++++++++----- tests/motion/test_views.py | 4 ++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/openslides/utils/forms.py b/openslides/utils/forms.py index 145df2045..6a43ed630 100644 --- a/openslides/utils/forms.py +++ b/openslides/utils/forms.py @@ -85,9 +85,14 @@ class CleanHtmlFormMixin(object): def clean(self): cleaned_data = super(CleanHtmlFormMixin, self).clean() for field in self.get_clean_html_fields(): - cleaned_data[field] = bleach.clean(cleaned_data[field], - tags=HTML_TAG_WHITELIST, - attributes=HTML_ATTRIBUTES_WHITELIST, - styles=HTML_STYLES_WHITELIST, - strip=True) + try: + cleaned_data[field] = bleach.clean( + cleaned_data[field], + tags=HTML_TAG_WHITELIST, + attributes=HTML_ATTRIBUTES_WHITELIST, + styles=HTML_STYLES_WHITELIST, + strip=True) + except KeyError: + # The field 'field' is not pressent. Do not change cleaned_data + pass return cleaned_data diff --git a/tests/motion/test_views.py b/tests/motion/test_views.py index 94138065d..96833eeb4 100644 --- a/tests/motion/test_views.py +++ b/tests/motion/test_views.py @@ -127,6 +127,10 @@ class TestMotionCreateView(MotionViewTestCase): 'identifier': 'foo'}) self.assertFormError(response, 'form', 'identifier', 'The Identifier is not unique.') + def test_empty_text_field(self): + response = self.admin_client.post(self.url, {'title': 'foo', + 'submitter': self.admin}) + self.assertFormError(response, 'form', 'text', 'This field is required.') class TestMotionUpdateView(MotionViewTestCase):