Skip to content

Commit

Permalink
fix date validator to work with new pattern widget output
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed May 9, 2016
1 parent b283f0c commit e920d86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
17 changes: 6 additions & 11 deletions Products/PloneFormGen/content/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ def _toLocalizedTime(self, time, long_format=None):
tool = getToolByName(self, 'translation_service')
return tool.ulocalized_time(time, long_format=long_format)


def htmlValue(self, REQUEST):
""" return from REQUEST, this field's value, rendered as XHTML.
"""
Expand All @@ -595,23 +594,19 @@ def htmlValue(self, REQUEST):

return cgi.escape(value)


def specialValidator(self, value, field, REQUEST, errors):
""" Archetypes isn't validating non-required dates --
so we need to.
"""

fname = field.getName()
month = REQUEST.form.get('%s_month'%fname, '01')
day = REQUEST.form.get('%s_month'%fname, '01')

if (month == '00') and (day == '00'):
value = ''
REQUEST.form[fname] = ''

if value and not field.required:
try:
dt = DateTime(value)
DateTime(value)
except (DateTimeSyntaxError, DateError):
return "Validation failed(isValidDate): this is not a valid date."
elif not value:
try:
DateTime(REQUEST.form.get(fname))
except (DateTimeSyntaxError, DateError):
return "Validation failed(isValidDate): this is not a valid date."
return 0
Expand Down
8 changes: 3 additions & 5 deletions Products/PloneFormGen/tests/testFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,7 @@ def testTranslationBasics(self):
def testDateValidation(self):
""" Dates should be validated """


self.ff1.invokeFactory('FormDateField', 'fdf')

# set non-date fields in request
request = self.fakeRequest(topic = 'test subject', replyto='test@test.org ', comments='test comments')

Expand All @@ -488,15 +486,15 @@ def testDateValidation(self):

# try with bad date. should not validate.
request = self.fakeRequest(topic = 'test subject', replyto='test@test.org ', comments='test comments',
fdf='2007/02/31', fdf_year='2007', fdf_month='02', fdf_day='31')
fdf='2007-02-31')
errors = self.ff1.fgvalidate(REQUEST=request)
self.assertEqual( request.form['replyto'], 'test@test.org' )
self.assertEqual( len(errors), 1 )

# try required and bad date. should not validate.
self.ff1.fdf.setRequired(True)
request = self.fakeRequest(topic = 'test subject', replyto='test@test.org ', comments='test comments',
fdf='2007/02/31', fdf_year='2007', fdf_month='02', fdf_day='31')
fdf='2007-02-31')
errors = self.ff1.fgvalidate(REQUEST=request)
self.assertEqual( request.form['replyto'], 'test@test.org' )
self.assertEqual( len(errors), 1 )
Expand All @@ -511,7 +509,7 @@ def testDateValidation(self):
# try required and good date. should validate.
self.ff1.fdf.setRequired(True)
request = self.fakeRequest(topic = 'test subject', replyto='test@test.org ', comments='test comments',
fdf='2007/02/21', fdf_year='2007', fdf_month='02', fdf_day='21')
fdf='2007-02-21')
errors = self.ff1.fgvalidate(REQUEST=request)
self.assertEqual( request.form['replyto'], 'test@test.org' )
self.assertEqual( errors, {} )
Expand Down

0 comments on commit e920d86

Please sign in to comment.