diff --git a/CHANGELOG.md b/CHANGELOG.md index e475048..b7f987f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## 1.2.6 + +- Fix `datetimeComponent` value setter, to properyly parse when the + `enableTime` property is `False`.\ + This fixes a bug/regression in version 1.2.3. +- Update README concerning the datetime component value. + ## 1.2.5 Improve the load methods for components and `gridRow`, by passing @@ -22,13 +29,16 @@ validation errors. ## 1.2.3 -Improve the `datetimeComponent` to properly parse a date with a custom format, when the `enableTime` (new property) is False. +Improve the `datetimeComponent` value setter, to properly parse a date +with a custom format, when the `enableTime` (new property) is `False`. Provide the `component_class_mapping` (interface) in the keyword arguments of the Form (class) instantiation. ## 1.2.2 -Refactored the `Component` class `conditionally_visible` method, to call the following 2 methods which can be extended in component subclasses: +Refactored the `Component` class `conditionally_visible` method, to +call the following 2 methods which can be extended in component +subclasses: - `conditional_visible_json_when` - `conditional_visible_json_logic` diff --git a/README.md b/README.md index 24e7c8c..0d597be 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,9 @@ For more examples of usage, see the unit-tests. # datetime value >> print(form.input_components['birthday'].value) +'2009-10-16' + +>> print(form.input_components['birthday'].to_date()) datetime.date(2009 10 16) # datagrid (rows property) @@ -135,7 +138,7 @@ datetime.date(2009 10 16) >> for row in form.input_components['datagridMeasurements'].rows: >> dtime = row['measurementDatetime'] >> fahrenheit = row['measurementFahrenheit'] ->> print(%s: %s, %s: %s' % (dt.label, dt.value, fahrenheit.label, fahrenheit.value)) +>> print(%s: %s, %s: %s' % (dt.label, dt.to_datetime(), fahrenheit.label, fahrenheit.value)) Datetime: datetime.datetime(2021, 5, 8, 11, 39, 0, 296487), Fahrenheit: 122 Datetime: datetime.datetime(2021, 5, 8, 11, 41, 5, 919943), Fahrenheit: 131 diff --git a/formiodata/components/datetime.py b/formiodata/components/datetime.py index bb1e3a0..881a651 100644 --- a/formiodata/components/datetime.py +++ b/formiodata/components/datetime.py @@ -74,8 +74,21 @@ def value(self, value): if not self.enableTime: # OMG some parsing to deal with the ISO format (storage). try: - datetime.fromisoformat(value) - super(self.__class__, self.__class__).value.fset(self, value) + dt = datetime.fromisoformat(value) + dt_format = self.raw.get('format') + py_format = copy(dt_format) + for date_part, mapping in self._format_mappings().items(): + done_date_part = False + for fm_formio, fm_py in mapping.items(): + # fm_formio are (JS) uibDateParser codes, see comment + # in _format_mappings + if not done_date_part and fm_formio in dt_format: + py_format = py_format.replace(fm_formio, fm_py) + done_date_part = True + super(self.__class__, self.__class__).value.fset( + self, + dt.strftime(py_format) + ) except ValueError: dt_format = self.raw.get('format') py_format = copy(dt_format) diff --git a/pyproject.toml b/pyproject.toml index 803fb2e..7899966 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "formio-data" -version = "1.2.5" +version = "1.2.6" homepage = "https://github.com/novacode-nl/python-formio-data" description = "formio.js JSON-data API" readme = "README.md" diff --git a/tests/data/test_example_builder.json b/tests/data/test_example_builder.json index 4bef874..82e6295 100644 --- a/tests/data/test_example_builder.json +++ b/tests/data/test_example_builder.json @@ -343,7 +343,7 @@ "useLocaleSettings": false, "allowInput": true, "enableDate": true, - "enableTime": true, + "enableTime": false, "defaultDate": "", "displayInTimezone": "viewer", "timezone": "", diff --git a/tests/test_performance_nested_components.py b/tests/test_performance_nested_components.py index dad4931..9958331 100644 --- a/tests/test_performance_nested_components.py +++ b/tests/test_performance_nested_components.py @@ -5,22 +5,8 @@ import time import unittest -from datetime import datetime, date, timezone, timedelta - from tests.utils import readfile from formiodata.builder import Builder -from formiodata.form import Form - -from formiodata.components.columns import columnsComponent -from formiodata.components.datetime import datetimeComponent -from formiodata.components.email import emailComponent -from formiodata.components.number import numberComponent -from formiodata.components.select import selectComponent -from formiodata.components.textfield import textfieldComponent -from formiodata.components.checkbox import checkboxComponent -from formiodata.components.panel import panelComponent -from formiodata.components.datagrid import datagridComponent -from formiodata.components.editgrid import editgridComponent class PerformanceNestedTestCase(unittest.TestCase): @@ -47,7 +33,7 @@ def load_builders_range(self, range_num, load_path_objects): self.logger.info('\n'.join(msg_lines)) # self.logger.info(end - start) - def XX_test_Builder_component_with_path_objects(self): + def test_Builder_component_with_path_objects(self): """ Builder: component path objects """ msg_lines = [ @@ -60,7 +46,7 @@ def XX_test_Builder_component_with_path_objects(self): self.load_builders_range(100, load_path_objects=True) self.load_builders_range(1000, load_path_objects=True) - def XX_test_Builder_component_no_path_objects(self): + def test_Builder_component_no_path_objects(self): """ Builder: component NO path objects """ msg_lines = [