Commit 5f734c0f authored by Sebastien Robin's avatar Sebastien Robin

some patch were missing


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@536 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 516976dc
......@@ -22,6 +22,7 @@
from Products.Formulator.Field import Field
from AccessControl import ClassSecurityInfo
from zLOG import LOG
class PatchedField:
......@@ -65,7 +66,6 @@ from Products.Formulator.Validator import SelectionValidator
from Products.Formulator.Validator import StringBaseValidator
def SelectionValidator_validate(self, field, key, REQUEST):
LOG('SelectionValidate_validate',0,'field; %s, key: %s')
value = StringBaseValidator.validate(self, field, key, REQUEST)
if value == "" and not field.get_value('required'):
......@@ -231,6 +231,7 @@ def SingleItemsWidget_render_items(self, field, key, value, REQUEST):
return rendered_items
SingleItemsWidget.render_items = SingleItemsWidget_render_items
import string
def StringBaseValidator_validate(self, field, key, REQUEST):
# We had to add this patch for hidden fields of type "list"
......@@ -242,3 +243,90 @@ def StringBaseValidator_validate(self, field, key, REQUEST):
return value
StringBaseValidator.validate = StringBaseValidator_validate
from Products.Formulator.Widget import Widget
def render_hidden(self, field, key, value, REQUEST):
"""Renders this widget as a hidden field.
"""
#LOG('render_hidden',0,str(value))
try:
extra = field.get_value('extra')
except KeyError:
# In case extra is not defined as in DateTimeWidget
extra = ''
result = ''
# We must adapt the rendering to the type of the value
# in order to get the correct type back
if type(value) is type([]) or type(value) is type(()):
for v in value:
result += render_element("input",
type="hidden",
name="%s:list" % key,
value=v,
extra=extra)
else:
result = render_element("input",
type="hidden",
name=key,
value=value,
extra=extra)
return result
Widget.render_hidden = render_hidden
from Products.Formulator.Validator import LinesValidator
def LinesValidator_validate(self, field, key, REQUEST):
value = StringBaseValidator.validate(self, field, key, REQUEST)
# Added as a patch for hidden values
if type(value) is type([]) or type(value) is type(()):
value = string.join(value, "\n")
# we need to add this check again
if value == "" and not field.get_value('required'):
return []
if field.get_value('unicode'):
value = unicode(value, field.get_form_encoding())
# check whether the entire input is too long
max_length = field.get_value('max_length') or 0
if max_length and len(value) > max_length:
self.raise_error('too_long', field)
# split input into separate lines
lines = string.split(value, "\n")
# check whether we have too many lines
max_lines = field.get_value('max_lines') or 0
if max_lines and len(lines) > max_lines:
self.raise_error('too_many_lines', field)
# strip extraneous data from lines and check whether each line is
# short enough
max_linelength = field.get_value('max_linelength') or 0
result = []
whitespace_preserve = field.get_value('whitespace_preserve')
for line in lines:
if not whitespace_preserve:
line = string.strip(line)
if max_linelength and len(line) > max_linelength:
self.raise_error('line_too_long', field)
result.append(line)
return result
LinesValidator.validate = LinesValidator_validate
from Products.Formulator.Validator import FloatValidator
def FloatValidator_validate(self, field, key, REQUEST):
value = StringBaseValidator.validate(self, field, key, REQUEST)
if value == "" and not field.get_value('required'):
return value
try:
if value.find(',') >= 0:
value = value.replace(',','.')
value = float(value)
except ValueError:
self.raise_error('not_float', field)
return value
FloatValidator.validate = FloatValidator_validate
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment