diff --git a/composer/schema/field.py b/composer/schema/field.py index 6bdc9ee..379e51c 100644 --- a/composer/schema/field.py +++ b/composer/schema/field.py @@ -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) diff --git a/composer/schema/instance.py b/composer/schema/instance.py index 1aec4b7..8caf2cd 100644 --- a/composer/schema/instance.py +++ b/composer/schema/instance.py @@ -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) diff --git a/composer/schema/interfaces.py b/composer/schema/interfaces.py index 9d7106e..9fd64c5 100644 --- a/composer/schema/interfaces.py +++ b/composer/schema/interfaces.py @@ -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):