[web] Don't raise ProcessFormError if there is no value specified
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 07 Mar 2017 12:08:39 +0100
changeset 12006 c2230b7f6358
parent 12005 dcf80f5b7b63
child 12007 b82cda5ba3bf
[web] Don't raise ProcessFormError if there is no value specified a03376213747 introduced a slight modification in None / empty string values and with it a regression where an exception is raised on empty values, while we should simply consider no value is specified and return None.
cubicweb/web/formwidgets.py
cubicweb/web/test/unittest_form.py
--- a/cubicweb/web/formwidgets.py	Tue Mar 07 11:59:07 2017 +0100
+++ b/cubicweb/web/formwidgets.py	Tue Mar 07 12:08:39 2017 +0100
@@ -795,17 +795,17 @@
         req = form._cw
         datestr = req.form.get(field.input_name(form, 'date'))
         if datestr:
-            datestr = datestr.strip() or None
-        timestr = req.form.get(field.input_name(form, 'time'))
-        if timestr:
-            timestr = timestr.strip() or None
-        if datestr is None:
+            datestr = datestr.strip()
+        if not datestr:
             return None
         try:
             date = todatetime(req.parse_datetime(datestr, 'Date'))
         except ValueError as exc:
             raise ProcessFormError(text_type(exc))
-        if timestr is None:
+        timestr = req.form.get(field.input_name(form, 'time'))
+        if timestr:
+            timestr = timestr.strip()
+        if not timestr:
             return date
         try:
             time = req.parse_datetime(timestr, 'Time')
--- a/cubicweb/web/test/unittest_form.py	Tue Mar 07 11:59:07 2017 +0100
+++ b/cubicweb/web/test/unittest_form.py	Tue Mar 07 12:08:39 2017 +0100
@@ -32,7 +32,7 @@
                                      PasswordField, DateTimeField,
                                      FileField, EditableFileField,
                                      TZDatetimeField)
-from cubicweb.web.formwidgets import DateTimePicker
+from cubicweb.web.formwidgets import DateTimePicker, JQueryDateTimePicker
 from cubicweb.web.views.forms import EntityFieldsForm, FieldsForm
 from cubicweb.web.views.workflow import ChangeStateForm
 from cubicweb.web.views.formrenderers import FormRenderer
@@ -62,6 +62,15 @@
             form = AForm(req)
             self.assertRaises(ValidationError, form.process_posted)
 
+    def test_jqdt_process_data(self):
+        widget = JQueryDateTimePicker()
+        field = DateTimeField('jqdt')
+        with self.admin_access.web_request(**{'jqdt-date': '', 'jqdt-time': '00:00'}) as req:
+            self._cw = req
+            self.formvalues = {}
+            date = widget.process_field_data(self, field)
+            self.assertIsNone(date)
+
 
 class EntityFieldsFormTC(CubicWebTC):