extend composer.schema for better support of customized schema factories

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2390 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2008-02-12 11:40:12 +00:00
parent f9418c1df6
commit b3eaf1e58f
4 changed files with 34 additions and 19 deletions

View file

@ -62,19 +62,18 @@ class SchemaFactory(object):
fields = []
for fname in schema.getFieldNamesInOrder(interface):
field = interface[fname]
if field.__class__ in fieldMapping:
info = fieldMapping[field.__class__]
voc = (getattr(field, 'vocabulary', ()) or
getattr(field, 'vocabularyName', None))
f = Field(field.getName(),
fieldType=info[0],
required=field.required,
default=field.default,
default_method=getattr(field, 'default_method', None),
vocabulary=voc,
title=field.title,
description=field.description,
readonly=field.readonly,
nostore=getattr(field, 'nostore', False),)
fields.append(f)
info = fieldMapping.get(field.__class__) or ('textline',)
voc = (getattr(field, 'vocabulary', ()) or
getattr(field, 'vocabularyName', None))
f = Field(field.getName(),
fieldType=info[0],
required=field.required,
default=field.default,
default_method=getattr(field, 'default_method', None),
vocabulary=voc,
title=field.title,
description=field.description,
readonly=field.readonly,
nostore=getattr(field, 'nostore', False),)
fields.append(f)
return Schema(name=interface.__name__, *fields, **kw)

View file

@ -50,6 +50,12 @@ class Field(Component):
default = None
default_method = None
fieldTypeInfo = None
instance_name = None
display_renderer = None
display_format = None
def __init__(self, name, title=None, fieldType='textline', **kw):
assert name
self.__name__ = name
@ -80,6 +86,10 @@ class Field(Component):
def inputRenderer(self):
return self.getFieldTypeInfo().inputRenderer
@property
def displayRenderer(self):
return self.display_renderer or self.getFieldTypeInfo().displayRenderer
@property
def storeData(self):
return not self.nostore and self.getFieldTypeInfo().storeData
@ -100,10 +110,10 @@ class Field(Component):
return [dict(token=t.token, title=t.title or t.value) for t in voc]
def getFieldTypeInfo(self):
return fieldTypes.getTerm(self.fieldType)
return self.fieldTypeInfo or fieldTypes.getTerm(self.fieldType)
def getFieldInstance(self, clientInstance=None):
instanceName = self.getFieldTypeInfo().instanceName
instanceName = self.instance_name or self.getFieldTypeInfo().instanceName
fi = component.getAdapter(self, IFieldInstance, name=instanceName)
fi.clientInstance = clientInstance
return fi
@ -193,9 +203,10 @@ class DateFieldInstance(NumberFieldInstance):
return ''
view = self.clientInstance.view
langInfo = view and view.languageInfo or None
format = self.context.display_format or ('dateTime', 'short')
if langInfo:
locale = locales.getLocale(langInfo.language)
fmt = locale.dates.getFormatter('dateTime', 'short')
fmt = locale.dates.getFormatter(*format)
return fmt.format(value)
return str(value)

View file

@ -74,6 +74,7 @@ class FieldType(SimpleTerm):
self.name = value
self.fieldRenderer = 'field'
self.inputRenderer = 'input_' + self.name
self.displayRenderer = 'display_textline'
self.storeData = True
self.instanceName = ''
for k, v in kw.items():

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -25,6 +25,10 @@ $Id$
from zope.component import adapts
from zope.interface import implements
from cybertools.organize.interfaces import ITask
class Task(object):
implements(ITask)