diff --git a/HISTORY.txt b/HISTORY.txt index 3c37851..4874192 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -4,13 +4,17 @@ Changelog 1.2.2 (unreleased) ------------------ -- Nothing changed yet. + * Fixes potential round trip traceback when converting the date(time) + values to a date(time) object. Happens if integrated with + collective.z3cform.wizard. + https://github.com/collective/collective.z3cform.datetimewidget/issues/2 + [romanofski] 1.2.1 (2012-10-10) ------------------ -* Make sure DOM is ready before activating the dateinput jQuery plugin. + * Make sure DOM is ready before activating the dateinput jQuery plugin. This was causing Internet Explorer 7 to fail. [rafaelbco] @@ -18,13 +22,13 @@ Changelog 1.2.0 (2012-06-15) ------------------ -* Fix day names. Also respect the first day of the week from the current - locale. This fixes http://code.google.com/p/dexterity/issues/detail?id=272 - [davisagli] + * Fix day names. Also respect the first day of the week from the current + locale. This fixes http://code.google.com/p/dexterity/issues/detail?id=272 + [davisagli] -* Use viewpagetemplatefile from zope.browserpage. This breaks compatibility - with Zope < 2.13 and Plone < 4.1 in order to minimize dependencies. - [hannosch] + * Use viewpagetemplatefile from zope.browserpage. This breaks compatibility + with Zope < 2.13 and Plone < 4.1 in order to minimize dependencies. + [hannosch] 1.1.1 (2011-09-24) ------------------ diff --git a/README.txt b/README.txt index c30bbc4..0b7e1ec 100644 --- a/README.txt +++ b/README.txt @@ -31,3 +31,4 @@ Contributors * David Glick - davisagli * Rok Garbas - garbas * Carsten Senger - csenger + * Róman Joost - romanofski diff --git a/src/collective/z3cform/datetimewidget/issues.txt b/src/collective/z3cform/datetimewidget/issues.txt index a8d321f..ca53bbb 100644 --- a/src/collective/z3cform/datetimewidget/issues.txt +++ b/src/collective/z3cform/datetimewidget/issues.txt @@ -144,3 +144,71 @@ ISSUE 2 >>> 'value: new Date("2011/12/31")' in widget.show_jquerytools_dateinput_js() True +ISSUE 2 (github) +---------------- + + * status: SOLVED + * reported by: Róman Joost | romanofski + * assigned to: Róman Joost | romanofski + + The datetime widgets default month is January. The widgets default + value is influenced by this default value and may cause a traceback. + + >>> field = zope.schema.Datetime() + >>> widget = self.setupWidget(field) + >>> widget.ampm = True + >>> widget.update() + >>> widget.request = self.testrequest( + ... form={'bar-day': '', + ... 'bar-month': '1', + ... 'bar-year': '', + ... 'bar-hour': '00', + ... 'bar-min': '00', + ... 'bar-ampm': 'PM', + ... 'bar-empty-marker': '1', + ... } + ... ) + >>> widget.update() + >>> widget.formatted_value + '' + + The required field will not validate the widget value: + + >>> from z3c.form import validator + >>> from z3c.form import interfaces + >>> field.required + True + >>> simple = validator.SimpleFieldValidator( + ... None, None, None, field, widget) + >>> value = interfaces.IDataConverter(widget).toFieldValue(widget.extract()) + >>> simple.validate(value) + Traceback (most recent call last): + RequiredMissing + + The date widget will have the same issue: + + >>> field = zope.schema.Date() + >>> widget = self.setupWidget(field) + >>> widget.ampm = True + >>> widget.update() + >>> widget.request = self.testrequest( + ... form={'bar-day': '', + ... 'bar-month': '1', + ... 'bar-year': '', + ... 'bar-empty-marker': '1', + ... } + ... ) + >>> widget.update() + >>> widget.formatted_value + '' + + The required field will not validate the widget value: + + >>> field.required + True + >>> simple = validator.SimpleFieldValidator( + ... None, None, None, field, widget) + >>> value = interfaces.IDataConverter(widget).toFieldValue(widget.extract()) + >>> simple.validate(value) + Traceback (most recent call last): + RequiredMissing diff --git a/src/collective/z3cform/datetimewidget/widget_date.py b/src/collective/z3cform/datetimewidget/widget_date.py index 9b8850b..cd631a3 100644 --- a/src/collective/z3cform/datetimewidget/widget_date.py +++ b/src/collective/z3cform/datetimewidget/widget_date.py @@ -82,10 +82,11 @@ def months(self): @property def formatted_value(self): - if self.value == ('', '', ''): + try: + date_value = date(*map(int, self.value)) + except ValueError: return '' formatter = self.request.locale.dates.getFormatter("date", "short") - date_value = date(*map(int, self.value)) if date_value.year > 1900: return formatter.format(date_value) # due to fantastic datetime.strftime we need this hack diff --git a/src/collective/z3cform/datetimewidget/widget_datetime.py b/src/collective/z3cform/datetimewidget/widget_datetime.py index 566787c..def9ed3 100644 --- a/src/collective/z3cform/datetimewidget/widget_datetime.py +++ b/src/collective/z3cform/datetimewidget/widget_datetime.py @@ -39,10 +39,11 @@ class DatetimeWidget(DateWidget): @property def formatted_value(self): - if self.value == ('', '', '', '00', '00'): + try: + datetime_value = datetime(*map(int, self.value)) + except ValueError: return '' formatter = self.request.locale.dates.getFormatter("dateTime", "short") - datetime_value = datetime(*map(int, self.value)) if datetime_value.year > 1900: return formatter.format(datetime_value) # due to fantastic datetime.strftime we need this hack