let field instance retrieve context attribute (fi.getRawValue())

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2723 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-06-27 11:45:33 +00:00
parent e76f640529
commit a9058f441e
3 changed files with 18 additions and 6 deletions

View file

@ -144,6 +144,9 @@ class FieldInstance(object):
return method()
return self.context.defaultValue
def getRawValue(self, data, key, default=None):
return data.get(key, default)
def marshall(self, value):
return value or u''
#return toStr(value)

View file

@ -85,7 +85,9 @@ class Editor(BaseInstance):
name = f.name
ftype = f.fieldType
fi = formState.fieldInstances[name]
value = fi.unmarshall(data.get(name, u''))
#rawValue = data.get(name, u'')
rawValue = fi.getRawValue(data, name, u'')
value = fi.unmarshall(rawValue)
if ftype in fieldHandlers: # caller wants special treatment of field
fieldHandlers[ftype](context, value, fi, formState)
else:
@ -104,7 +106,8 @@ class Editor(BaseInstance):
if f.readonly:
continue
fi = f.getFieldInstance(self)
value = data.get(f.name)
#value = data.get(f.name)
value = fi.getRawValue(data, f.name)
fi.validate(value, data)
formState.fieldInstances.append(fi)
formState.severity = max(formState.severity, fi.severity)

View file

@ -204,19 +204,25 @@ class IFieldInstance(Interface):
severity = Attribute("An integer giving a state or error "
"code, 0 meaning 'OK'.")
def getRawValue(data, key, default=None):
""" Extract a raw value for the field from the data given
using the key; if no corresponding value is found return
the default.
"""
def marshall(value):
""" Return a string (possibly unicode) representation of the
value given that may be used for editing.
"""
def display(value):
""" Return a string (possibly unicode) representation of the
""" Return a string- (possibly unicode-) based representation of the
value given that may be used for presentation.
"""
def unmarshall(strValue):
""" Return the internal (real) value corresponding to the string
value given.
def unmarshall(rawValue):
""" Return the internal (real) value corresponding to the
raw value given.
"""
def validate(value, data=None):