Skip to content

Commit

Permalink
Merge pull request #3 from mooballit/master
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
davisagli committed Oct 15, 2012
2 parents f6ffad9 + 85edb98 commit 2f8dca9
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 12 deletions.
20 changes: 12 additions & 8 deletions HISTORY.txt
Expand Up @@ -4,27 +4,31 @@ 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]


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)
------------------
Expand Down
1 change: 1 addition & 0 deletions README.txt
Expand Up @@ -31,3 +31,4 @@ Contributors
* David Glick - davisagli
* Rok Garbas - garbas
* Carsten Senger - csenger
* Róman Joost - romanofski
68 changes: 68 additions & 0 deletions src/collective/z3cform/datetimewidget/issues.txt
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/collective/z3cform/datetimewidget/widget_date.py
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/collective/z3cform/datetimewidget/widget_datetime.py
Expand Up @@ -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
Expand Down

0 comments on commit 2f8dca9

Please sign in to comment.