added attribute 'standardFieldName' to Field class for supplying a set of standard attributes; show these on forms and listings

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1983 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-09-01 13:24:51 +00:00
parent 163e6dedd7
commit fb12b07bf3
5 changed files with 99 additions and 7 deletions

View file

@ -38,6 +38,7 @@ class Field(Component):
implements(IField)
required = False
standardFieldName = None
def __init__(self, name, title=None, fieldType='textline', **kw):
assert name

View file

@ -59,6 +59,10 @@ class ClientInstance(object):
def aspect(self):
return self.baseAspect + self.template.name
@property
def standardAspect(self):
return self.baseAspect + '__standard__'
def __init__(self, context):
self.context = context
@ -66,14 +70,14 @@ class ClientInstance(object):
""" Return a mapping of field names from self.template (a schema)
to the corresponding values from the context object.
"""
result = {}
result = dict(__name__=self.context.__name__)
mode = kw.get('mode', 'view')
attrs = getattr(self.context, self.attrsName, None)
if attrs is None:
return result
template = self.template
values = attrs.setdefault(self.aspect, {})
if template is not None:
values = attrs.get(self.aspect, {})
for f in template.fields:
fieldType = f.getFieldTypeInfo()
if not fieldType.storeData:
@ -84,7 +88,9 @@ class ClientInstance(object):
value = values.get(name, u'')
value = mode == 'view' and fi.display(value) or fi.marshall(value)
result[name] = value
result['__name__'] = self.context.__name__
# update result with standard fields:
for k, v in attrs.get(self.standardAspect, {}).items():
result['standard.' + k] = v
return result
@ -121,6 +127,12 @@ class ClientInstanceEditor(ClientInstance):
values[name] = value
fi.change = (oldValue, value)
formState.changed = True
# update standard field if appropriate:
standardFieldName = f.standardFieldName
if standardFieldName:
standardValues = attrs.setdefault(self.standardAspect, OOBTree())
if value != standardValues.get(standardFieldName):
standardValues[standardFieldName] = value
return formState
def validate(self, data):

View file

@ -82,6 +82,14 @@ fieldTypes = SimpleVocabulary((
storeData=False),
))
standardFieldNames = SimpleVocabulary((
SimpleTerm('', '', 'Not selected'),
SimpleTerm('lastName', 'lastName', 'Last name'),
SimpleTerm('firstName', 'firstName', 'First name'),
SimpleTerm('organization', 'organization', 'Organization'),
SimpleTerm('email', 'email', 'E-Mail address'),
))
class IField(IComponent):
""" May be used for data entry or display.
"""
@ -104,6 +112,13 @@ class IField(IComponent):
required=True,
default='textline',
vocabulary=fieldTypes,)
standardFieldName = schema.Choice(
title=_(u'Standard field name'),
description=_(u'Provide the values entered in this field '
'as one of the standard informations.'),
required=False,
default='',
vocabulary=standardFieldNames,)
defaultValue = schema.TextLine(
title=_(u'Default'),
description=_(u'Value with which to pre-set the field contents'),
@ -162,7 +177,7 @@ class IFormState(Interface):
""" Represents the state of all fields when editing.
"""
fieldStates = Attribute('A mapping ``{fieldName: fieldState, ...}``.')
fieldInstances = Attribute('A mapping ``{fieldName: fieldInstance, ...}``.')
changed = Attribute('True if one of the fields has been changed')
severity = Attribute("An integer giving an overall state or error "
"code, typically the maximum of the field instances' "

View file

@ -29,6 +29,7 @@ from zope.cachedescriptors.property import Lazy
from cybertools.organize.interfaces import IClientRegistrations, IRegistrationTemplate
from cybertools.organize.interfaces import serviceCategories
from cybertools.composer.interfaces import IInstance
from cybertools.composer.schema.browser.common import BaseView as SchemaBaseView
from cybertools.composer.schema.interfaces import IClientFactory
from cybertools.util.format import formatDate
@ -71,7 +72,7 @@ class BaseView(object):
class ServiceManagerView(BaseView):
def getCustomView(self):
viewName = self.context.viewName
viewName = self.context.getViewName()
if viewName:
return component.getMultiAdapter((self.context, self.request),
name=viewName)
@ -138,6 +139,14 @@ class ServiceView(BaseView):
tpl = ServiceManagerView(man, self.request).findRegistrationTemplate(context)
return self.getUrlForObject(tpl)
def getClientData(self, clientName):
manager = self.context.getManager()
client = manager.getClients().get(clientName)
if client is None:
return {}
instance = IInstance(client)
return instance.applyTemplate()
class RegistrationTemplateView(SchemaBaseView):
@ -163,6 +172,20 @@ class RegistrationTemplateView(SchemaBaseView):
def getRegistratedServicesTokens(self):
return [r.service.token for r in self.getRegistrations()]
def getData(self):
""" Retrieve standard field data (accessible without providing
a template) from the client object.
"""
clientName = self.getClientName()
if not clientName:
return {}
manager = self.context.getManager()
client = manager.getClients().get(clientName)
if client is None:
return {}
instance = IInstance(client)
return instance.applyTemplate()
def update(self):
form = self.request.form
clientName = self.getClientName()
@ -173,7 +196,6 @@ class RegistrationTemplateView(SchemaBaseView):
client = manager.getClients().get(clientName)
if client is None:
return True
#self.setClientName(clientName) # store in view and session
else:
client = IClientFactory(manager)()
clientName = self.clientName = manager.addClient(client)

View file

@ -183,12 +183,52 @@ class IService(Interface):
vocabulary=serviceCategories,
default='event',
required=False,)
externalId = schema.TextLine(
title=_(u'External ID'),
description=_(u'Identifier in external system or code number.'),
required=False,)
cost = schema.Int(
title=_(u'Cost'),
description=_(u'Cost or prizing information.'),
required=False,)
capacity = schema.Int(
title=_(u'Capacity'),
description=_(u'The capacity (maximum number of clients) '
'of this service; a negative number means: '
'no restriction, i.e. unlimited capacity.'),
required=False,)
waitingList = schema.Bool(
title=_(u'Waiting list'),
description=_(u'Check this field if participants beyond the '
'capacity of the service should be kept in a '
'waiting list.'),
required=False,)
location = schema.TextLine(
title=_(u'Location Information'),
description=_(u'Basic location information or '
'start point for transport services.'),
required=False,)
locationUrl = schema.TextLine(
title=_(u'URL for location'),
description=_(u'Web address (URL) with more information '
'about the location.'),
required=False,)
location2 = schema.TextLine(
title=_(u'Location Information (2)'),
description=_(u'Additional location information or '
'end point for transport services.'),
required=False,)
location2Url = schema.TextLine(
title=_(u'URL for location (2)'),
description=_(u'Web address (URL) with more information '
'about the location.'),
required=False,)
webAddress = schema.TextLine(
title=_(u'Web address'),
description=_(u'Web address (URL) for more information '
'about the service.'),
required=False,)
availableCapacity = Attribute('Available capacity, i.e. number of seats '
'still available; a negative number means: '
'no restriction, i.e. unlimited capacity; '
@ -224,12 +264,14 @@ class IScheduledService(IService):
title=_(u'Start date/time'),
description=_(u'The date/time when the service starts'),
required=False,)
start.default_method = 'getStartFromManager'
end = schema.Date(
title=_(u'End date/time'),
description=_(u'The date/time when the service ends'),
required=False,)
start.default_method = 'getStartFromManager'
end.default_method = 'getEndFromManager'
duration = Attribute('Time delta between start and end date/time.')