provide list field instance for schema.List, use for Person.phoneNumbers
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2659 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
a9b8de7b21
commit
9dcb371b9e
7 changed files with 39 additions and 11 deletions
|
@ -52,7 +52,7 @@ Field types
|
||||||
>>> from cybertools.composer.schema.interfaces import fieldTypes
|
>>> from cybertools.composer.schema.interfaces import fieldTypes
|
||||||
>>> sorted(t.token for t in fieldTypes)
|
>>> sorted(t.token for t in fieldTypes)
|
||||||
['checkbox', 'date', 'display', 'dropdown', 'email', 'fileupload', 'html',
|
['checkbox', 'date', 'display', 'dropdown', 'email', 'fileupload', 'html',
|
||||||
'number', 'password', 'spacer', 'textarea', 'textline']
|
'list', 'number', 'password', 'spacer', 'textarea', 'textline']
|
||||||
|
|
||||||
>>> from zope.schema.vocabulary import SimpleVocabulary
|
>>> from zope.schema.vocabulary import SimpleVocabulary
|
||||||
>>> textFieldTypes = SimpleVocabulary([t for t in fieldTypes if t.token in
|
>>> textFieldTypes = SimpleVocabulary([t for t in fieldTypes if t.token in
|
||||||
|
@ -183,4 +183,4 @@ Macros / renderers
|
||||||
>>> sorted(fieldRenderers.keys())
|
>>> sorted(fieldRenderers.keys())
|
||||||
[u'field', u'field_spacer', u'fields', u'form', u'input_checkbox',
|
[u'field', u'field_spacer', u'fields', u'form', u'input_checkbox',
|
||||||
u'input_date', u'input_dropdown', u'input_fileupload', u'input_html',
|
u'input_date', u'input_dropdown', u'input_fileupload', u'input_html',
|
||||||
u'input_password', u'input_textarea', u'input_textline']
|
u'input_list', u'input_password', u'input_textarea', u'input_textline']
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Form(object):
|
||||||
@Lazy
|
@Lazy
|
||||||
def fieldRenderers(self):
|
def fieldRenderers(self):
|
||||||
""" proof-of-concept - get a dictionary of renderers (macros) via
|
""" proof-of-concept - get a dictionary of renderers (macros) via
|
||||||
adaptatation.
|
adaptation.
|
||||||
"""
|
"""
|
||||||
return IRenderers(self)
|
return IRenderers(self)
|
||||||
|
|
||||||
|
|
|
@ -161,6 +161,18 @@
|
||||||
</metal:dropdown>
|
</metal:dropdown>
|
||||||
|
|
||||||
|
|
||||||
|
<metal:list define-macro="input_list">
|
||||||
|
<textarea name="field" rows="3" style="width: 450px"
|
||||||
|
tal:define="width field/width|nothing;
|
||||||
|
height field/height|python:3"
|
||||||
|
tal:attributes="name name;
|
||||||
|
rows python: height or 3;
|
||||||
|
style python:
|
||||||
|
'width: %s' % (width and str(width)+'px' or '450px');"
|
||||||
|
tal:content="data/?name|string:" />
|
||||||
|
</metal:list>
|
||||||
|
|
||||||
|
|
||||||
<metal:spacer define-macro="field_spacer">
|
<metal:spacer define-macro="field_spacer">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="2" style="border-top:none; font-size: 50%"> </td>
|
<td colspan="2" style="border-top:none; font-size: 50%"> </td>
|
||||||
|
|
|
@ -54,6 +54,7 @@ class SchemaFactory(object):
|
||||||
schema.Datetime: ('date',),
|
schema.Datetime: ('date',),
|
||||||
schema.Int: ('number',),
|
schema.Int: ('number',),
|
||||||
schema.Bool: ('checkbox',),
|
schema.Bool: ('checkbox',),
|
||||||
|
schema.List: ('list',),
|
||||||
schema.Choice: ('dropdown',),
|
schema.Choice: ('dropdown',),
|
||||||
schema.Bytes: ('fileupload',),
|
schema.Bytes: ('fileupload',),
|
||||||
Email: ('email',),
|
Email: ('email',),
|
||||||
|
|
|
@ -216,10 +216,12 @@ class DateFieldInstance(NumberFieldInstance):
|
||||||
if not value:
|
if not value:
|
||||||
return None
|
return None
|
||||||
value = ''.join(value)
|
value = ''.join(value)
|
||||||
|
if value:
|
||||||
return datetime(*(strptime(value, '%Y-%m-%dT%H:%M:%S')[:6]))
|
return datetime(*(strptime(value, '%Y-%m-%dT%H:%M:%S')[:6]))
|
||||||
|
return None
|
||||||
|
|
||||||
def validate(self, value, data=None):
|
def validate(self, value, data=None):
|
||||||
if value in ('', None):
|
if value in ('', ['', ''], None):
|
||||||
if self.context.required:
|
if self.context.required:
|
||||||
self.setError('required_missing')
|
self.setError('required_missing')
|
||||||
else:
|
else:
|
||||||
|
@ -273,16 +275,27 @@ class ListFieldInstance(FieldInstance):
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def valueFieldInstance(self):
|
def valueFieldInstance(self):
|
||||||
|
if self.valueType is None:
|
||||||
|
return FieldInstance(self.context)
|
||||||
|
else:
|
||||||
instanceName = (self.valueType.instance_name or
|
instanceName = (self.valueType.instance_name or
|
||||||
self.valueType.getFieldTypeInfo().instanceName)
|
self.valueType.getFieldTypeInfo().instanceName)
|
||||||
return component.getAdapter(self.valueType, IFieldInstance, name=instanceName)
|
return component.getAdapter(self.valueType, IFieldInstance, name=instanceName)
|
||||||
|
|
||||||
def marshall(self, value):
|
def marshall(self, value):
|
||||||
return [self.valueFieldInstance.marshall(v) for v in value]
|
if isinstance(value, basestring):
|
||||||
|
return value
|
||||||
|
return u'\n'.join(self.valueFieldInstance.marshall(v) for v in value)
|
||||||
|
#return [self.valueFieldInstance.marshall(v) for v in value]
|
||||||
|
|
||||||
def display(self, value):
|
def display(self, value):
|
||||||
|
if isinstance(value, basestring):
|
||||||
|
return value
|
||||||
return u' | '.join(self.valueFieldInstance.display(v) for v in value)
|
return u' | '.join(self.valueFieldInstance.display(v) for v in value)
|
||||||
|
|
||||||
def unmarshall(self, value):
|
def unmarshall(self, value):
|
||||||
return [self.valueFieldInstance.unmarshall(v) for v in value]
|
if isinstance(value, basestring):
|
||||||
|
value = value.split('\n')
|
||||||
|
return [self.valueFieldInstance.unmarshall(v)
|
||||||
|
for v in value if v.strip()]
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,7 @@ fieldTypes = SimpleVocabulary((
|
||||||
FieldType('checkbox', 'checkbox', u'Checkbox', instanceName='boolean'),
|
FieldType('checkbox', 'checkbox', u'Checkbox', instanceName='boolean'),
|
||||||
FieldType('dropdown', 'dropdown', u'Drop-down selection'),
|
FieldType('dropdown', 'dropdown', u'Drop-down selection'),
|
||||||
#FieldType('listbox', 'listbox', u'List box (multiple selection)'),
|
#FieldType('listbox', 'listbox', u'List box (multiple selection)'),
|
||||||
|
FieldType('list', 'list', u'List', instanceName='list'),
|
||||||
FieldType('calculated', 'display', u'Calculated Value',
|
FieldType('calculated', 'display', u'Calculated Value',
|
||||||
instanceName='calculated'),
|
instanceName='calculated'),
|
||||||
FieldType('spacer', 'spacer', u'Spacer',
|
FieldType('spacer', 'spacer', u'Spacer',
|
||||||
|
|
|
@ -56,7 +56,8 @@ class IPerson(Interface):
|
||||||
description=_(u'The last name or surname'),)
|
description=_(u'The last name or surname'),)
|
||||||
email = Email(title=_(u'E-Mail address'),
|
email = Email(title=_(u'E-Mail address'),
|
||||||
description=_(u'The standard email address of the person'),)
|
description=_(u'The standard email address of the person'),)
|
||||||
phoneNumbers = SimpleList(
|
#phoneNumbers = SimpleList(
|
||||||
|
phoneNumbers = schema.List(
|
||||||
value_type=schema.TextLine(),
|
value_type=schema.TextLine(),
|
||||||
default=[],
|
default=[],
|
||||||
title=_(u'Phone numbers'),
|
title=_(u'Phone numbers'),
|
||||||
|
@ -97,7 +98,7 @@ class IAddress(Interface):
|
||||||
title=_(u'Country code'),
|
title=_(u'Country code'),
|
||||||
description=_(u'International two-letter country code'),
|
description=_(u'International two-letter country code'),
|
||||||
required=False,)
|
required=False,)
|
||||||
lines = LinesList(
|
lines = schema.List(
|
||||||
value_type=schema.TextLine(),
|
value_type=schema.TextLine(),
|
||||||
default=[],
|
default=[],
|
||||||
title=_(u'Additional lines'),
|
title=_(u'Additional lines'),
|
||||||
|
|
Loading…
Add table
Reference in a new issue