more control on registration process; registration template allows selection of services by category

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2082 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-10-01 18:04:21 +00:00
parent 32c52c7b31
commit 4affa83236
3 changed files with 68 additions and 14 deletions

View file

@ -82,19 +82,25 @@ class ServiceManagerView(BaseView):
def manager(self):
return self.context
def findRegistrationTemplate(self, service):
""" Find a registration template that provides the registration
for the service given.
def getRegistrationTemplate(self, service=None, preferRegistrationTemplate=False):
""" Find a suitable data or registration template.
"""
first = None
for tpl in self.context.getClientSchemas():
if not preferRegistrationTemplate:
return tpl
if IRegistrationTemplate.providedBy(tpl):
# TODO (optional): make sure template provides registration
# for service given.
return tpl
if first is None:
first = tpl
if IRegistrationTemplate.providedBy(tpl):
# TODO: check that service is really provided by this template
return tpl
return first
def registrationUrl(self):
tpl = self.getRegistrationTemplate()
return self.getUrlForObject(tpl)
def overview(self, includeCategories=None):
result = []
classific = []
@ -178,7 +184,7 @@ class ServiceView(BaseView):
def getRegistrationTemplate(self):
context = self.context
man = context.getManager()
return ServiceManagerView(man, self.request).findRegistrationTemplate(context)
return ServiceManagerView(man, self.request).getRegistrationTemplate()
def registrationUrl(self):
tpl = self.getRegistrationTemplate()

View file

@ -149,6 +149,19 @@ class IServiceManager(Interface):
vocabulary=serviceManagerViews,
default='',
required=False,)
allowRegWithNumber = schema.Bool(
title=_(u'Allow registration with number'),
description=_(u'When this field is checked more than one '
'object (participant) may be assigned with one '
'registration by entering a corresponding number.'),
required=False,)
allowDirectRegistration = schema.Bool(
title=_(u'Allow direct registration'),
description=_(u'When this field is checked participants '
'may register themselves directly on the page '
'with the service description; otherwise registration '
'is only possible on a registration template.'),
required=False,)
services = Attribute('A collection of services managed by this object.')
@ -189,6 +202,13 @@ class IService(Interface):
'object (participant) may be assigned with one '
'registration by entering a corresponding number.'),
required=False,)
allowDirectRegistration = schema.Bool(
title=_(u'Allow direct registration'),
description=_(u'When this field is checked participants '
'may register themselves directly on the page '
'with the service description; otherwise registration '
'is only possible on a registration template.'),
required=False,)
externalId = schema.TextLine(
title=_(u'External ID'),
description=_(u'Identifier in external system or code number.'),
@ -240,6 +260,9 @@ class IService(Interface):
'no restriction, i.e. unlimited capacity; '
'read-only')
allowRegWithNumber.default_method = 'getAllowRegWithNumberFromManager'
allowDirectRegistration.default_method = 'getAllowDirectRegistrationFromManager'
token = Attribute('A name unique within the manager of this service '
'used for identifying the service e.g. in forms.')
serviceGroup = Attribute('The service group this object is an instance of.')
@ -317,9 +340,14 @@ class IRegistrationTemplate(Interface):
The client should be accessed via an IClientRegistrations adapter.
"""
# TODO: provide fields for criteria for selecting the services
# that should be handled by this object, e.g. service
# category/ies or classification(s).
categories = schema.List(
title=_(u'Categories'),
description=_(u'A list of categories that of services '
'that should be shown on this template.'),
default=[],
required=False,)
categories.vocabulary = serviceCategories
manager = Attribute('The service manager this object belongs to.')
services = Attribute('A collection of services to which this '

View file

@ -54,13 +54,16 @@ class ServiceManager(object):
services = None
clients = None
allowRegWithNumber = False
allowDirectRegistration = True
def __init__(self):
if self.servicesFactory is not None:
self.services = self.servicesFactory()
if self.clientSchemasFactory is not None:
self.clientSchemas = self.clientSchemasFactory()
def getServices(self):
def getServices(self, categories=[]):
return self.services
def getClientSchemas(self):
@ -95,6 +98,7 @@ class Service(object):
manager = None
category = None
allowRegWithNumber = False
allowDirectRegistration = True
def __init__(self, name=None, title=u'', capacity=-1, **kw):
self.name = self.__name__ = name
@ -151,6 +155,12 @@ class Service(object):
if clientName in self.registrations:
del self.registrations[clientName]
# default methods
def getAllowRegWithNumberFromManager(self):
return getattr(self.getManager(), 'allowRegWithNumber', None)
def getAllowDirectRegistrationFromManager(self):
return getattr(self.getManager(), 'allowDirectRegistration', None)
class ScheduledService(Service):
@ -158,6 +168,7 @@ class ScheduledService(Service):
start = end = None
# default methods
def getStartFromManager(self):
return getattr(self.getManager(), 'start', None)
def getEndFromManager(self):
@ -186,14 +197,19 @@ class RegistrationTemplate(object):
def __init__(self, name=None, manager=None):
self.name = self.__name__ = name
self.manager = self.__parent__ = manager
self.categories = []
@property
def services(self):
return self.getServices()
def getServices(self):
# TODO: Restrict according to the objects selection criteria
return self.getManager().getServices()
svcs = self.getManager().getServices()
categories = [c.strip() for c in self.categories if c.strip()]
if categories:
svcs = Jeep((key, s) for key, s in svcs.items()
if s.category in categories)
return svcs
def getManager(self):
return self.manager
@ -229,7 +245,11 @@ class ClientRegistrations(object):
def getRegistrations(self):
# TODO: restrict to services on this template
return getattr(self.context, self.registrationsAttributeName, [])
regs = getattr(self.context, self.registrationsAttributeName, [])
if self.template is None:
return regs
svcs = self.template.getServices().values()
return [r for r in regs if r.service in svcs]
# registration states definition