work in progress: get rid of fieldMapping, use __typeInfo__ attribute on field classes instead
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2883 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
1341b330f9
commit
a461183c40
3 changed files with 13 additions and 6 deletions
|
@ -33,7 +33,12 @@ from cybertools.composer.schema.schema import Schema
|
|||
|
||||
|
||||
class Email(schema.TextLine):
|
||||
pass
|
||||
|
||||
__typeInfo__ = ('email',)
|
||||
|
||||
|
||||
# put field type name and other info in standard field classes.
|
||||
schema.Field.__typeInfo__ = ('textline',)
|
||||
|
||||
|
||||
class SchemaFactory(object):
|
||||
|
@ -45,8 +50,8 @@ class SchemaFactory(object):
|
|||
adapts(Interface)
|
||||
|
||||
fieldMapping = {
|
||||
schema.TextLine: ('textline',),
|
||||
schema.ASCIILine: ('textline',),
|
||||
#schema.TextLine: ('textline',),
|
||||
#schema.ASCIILine: ('textline',),
|
||||
schema.Password: ('password',),
|
||||
schema.Text: ('textarea',),
|
||||
schema.ASCII: ('textarea',),
|
||||
|
@ -57,7 +62,7 @@ class SchemaFactory(object):
|
|||
schema.List: ('list',),
|
||||
schema.Choice: ('dropdown',),
|
||||
schema.Bytes: ('fileupload',),
|
||||
Email: ('email',),
|
||||
#Email: ('email',),
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
|
@ -71,7 +76,9 @@ class SchemaFactory(object):
|
|||
if fname in omit:
|
||||
continue
|
||||
field = interface[fname]
|
||||
info = fieldMapping.get(field.__class__) or ('textline',)
|
||||
info = fieldMapping.get(field.__class__)
|
||||
if info is None:
|
||||
info = getattr(field, '__typeInfo__', ('textline',))
|
||||
voc = (getattr(field, 'vocabulary', ()) or
|
||||
getattr(field, 'vocabularyName', None))
|
||||
f = Field(field.getName(),
|
||||
|
|
|
@ -54,7 +54,6 @@ class Instance(BaseInstance):
|
|||
continue
|
||||
fi = f.getFieldInstance(self)
|
||||
name = f.name
|
||||
#value = getattr(self.context, name, f.defaultValue)
|
||||
value = getattr(self.context, name) or fi.default
|
||||
value = (mode == 'view' and fi.display(value)) or fi.marshall(value)
|
||||
result[name] = value
|
||||
|
|
|
@ -82,6 +82,7 @@ class FieldType(SimpleTerm):
|
|||
setattr(self, k, v)
|
||||
|
||||
|
||||
# TODO: register this object as a utility providing IFieldTypes
|
||||
fieldTypes = SimpleVocabulary((
|
||||
FieldType('textline', 'textline', u'Textline'),
|
||||
FieldType('password', 'password', u'Password'),
|
||||
|
|
Loading…
Add table
Reference in a new issue