Skip to content

Commit

Permalink
Merge pull request #59 from seanupton/master
Browse files Browse the repository at this point in the history
DateWidget, DatetimeWidget (pick-a-date) now able to clear previous
  • Loading branch information
vangheem authored Aug 11, 2016
2 parents 989f2ce + d07b5e4 commit fd14d46
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ New features:

Bug fixes:

- DateWidget, DatetimeWidget now able to clear previous values.
[seanupton]

- Use zope.interface decorator.
[gforcada]

Expand Down
9 changes: 8 additions & 1 deletion Products/Archetypes/Widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,10 @@ def process_form(self, instance, field, form, empty_marker=None):

value = value.split('-')

if value[0] == '':
# empty value, clear any previous value
return None, {}

try:
value = DateTime(datetime(*map(int, value)))
except:
Expand Down Expand Up @@ -1102,8 +1106,11 @@ def process_form(self, instance, field, form, empty_marker=None):
return empty_marker

tmp = value.split(' ')

if not tmp[0]:
return empty_marker
# empty: clear, not preserve, any previous value
return None, {}

value = tmp[0].split('-')
if len(tmp) == 2 and ':' in tmp[1]:
value += tmp[1].split(':')
Expand Down
20 changes: 20 additions & 0 deletions Products/Archetypes/tests/test_pawidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ def test_process_form(self):
(datetime(2011, 11, 22))
)

def test_process_form_empty_existing(self):
form = {
'fieldname': ''
}
self.assertEqual(
self.widget.process_form(
self.context, self.field, form)[0],
None
)


class DatetimeWidgetTests(unittest.TestCase):

Expand Down Expand Up @@ -188,6 +198,16 @@ def test_process_form(self):
(datetime(2011, 11, 22, 13, 30))
)

def test_process_form_empty_existing(self):
form = {
'fieldname': ''
}
self.assertEqual(
self.widget.process_form(
self.context, self.field, form)[0],
None
)


class SelectWidgetTests(unittest.TestCase):

Expand Down

0 comments on commit fd14d46

Please sign in to comment.