Skip to content

Commit

Permalink
Fix datetimeComponent value setter. Update README:
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
bobslee committed Jan 16, 2024
1 parent c46b8b2 commit 829e37e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions formiodata/components/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/data/test_example_builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
"useLocaleSettings": false,
"allowInput": true,
"enableDate": true,
"enableTime": true,
"enableTime": false,
"defaultDate": "",
"displayInTimezone": "viewer",
"timezone": "",
Expand Down
18 changes: 2 additions & 16 deletions tests/test_performance_nested_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = [
Expand All @@ -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 = [
Expand Down

0 comments on commit 829e37e

Please sign in to comment.