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:
		
							parent
							
								
									32c52c7b31
								
							
						
					
					
						commit
						4affa83236
					
				
					 3 changed files with 68 additions and 14 deletions
				
			
		|  | @ -82,19 +82,25 @@ class ServiceManagerView(BaseView): | ||||||
|     def manager(self): |     def manager(self): | ||||||
|         return self.context |         return self.context | ||||||
| 
 | 
 | ||||||
|     def findRegistrationTemplate(self, service): |     def getRegistrationTemplate(self, service=None, preferRegistrationTemplate=False): | ||||||
|         """ Find a registration template that provides the registration |         """ Find a suitable data or registration template. | ||||||
|             for the service given. |  | ||||||
|         """ |         """ | ||||||
|         first = None |         first = None | ||||||
|         for tpl in self.context.getClientSchemas(): |         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: |             if first is None: | ||||||
|                 first = tpl |                 first = tpl | ||||||
|             if IRegistrationTemplate.providedBy(tpl): |  | ||||||
|                 # TODO: check that service is really provided by this template |  | ||||||
|                 return tpl |  | ||||||
|         return first |         return first | ||||||
| 
 | 
 | ||||||
|  |     def registrationUrl(self): | ||||||
|  |         tpl = self.getRegistrationTemplate() | ||||||
|  |         return self.getUrlForObject(tpl) | ||||||
|  | 
 | ||||||
|     def overview(self, includeCategories=None): |     def overview(self, includeCategories=None): | ||||||
|         result = [] |         result = [] | ||||||
|         classific = [] |         classific = [] | ||||||
|  | @ -178,7 +184,7 @@ class ServiceView(BaseView): | ||||||
|     def getRegistrationTemplate(self): |     def getRegistrationTemplate(self): | ||||||
|         context = self.context |         context = self.context | ||||||
|         man = context.getManager() |         man = context.getManager() | ||||||
|         return ServiceManagerView(man, self.request).findRegistrationTemplate(context) |         return ServiceManagerView(man, self.request).getRegistrationTemplate() | ||||||
| 
 | 
 | ||||||
|     def registrationUrl(self): |     def registrationUrl(self): | ||||||
|         tpl = self.getRegistrationTemplate() |         tpl = self.getRegistrationTemplate() | ||||||
|  |  | ||||||
|  | @ -149,6 +149,19 @@ class IServiceManager(Interface): | ||||||
|                 vocabulary=serviceManagerViews, |                 vocabulary=serviceManagerViews, | ||||||
|                 default='', |                 default='', | ||||||
|                 required=False,) |                 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.') |     services = Attribute('A collection of services managed by this object.') | ||||||
| 
 | 
 | ||||||
|  | @ -189,6 +202,13 @@ class IService(Interface): | ||||||
|                         'object (participant) may be assigned with one ' |                         'object (participant) may be assigned with one ' | ||||||
|                         'registration by entering a corresponding number.'), |                         'registration by entering a corresponding number.'), | ||||||
|                 required=False,) |                 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( |     externalId = schema.TextLine( | ||||||
|                 title=_(u'External ID'), |                 title=_(u'External ID'), | ||||||
|                 description=_(u'Identifier in external system or code number.'), |                 description=_(u'Identifier in external system or code number.'), | ||||||
|  | @ -240,6 +260,9 @@ class IService(Interface): | ||||||
|                 'no restriction, i.e. unlimited capacity; ' |                 'no restriction, i.e. unlimited capacity; ' | ||||||
|                 'read-only') |                 'read-only') | ||||||
| 
 | 
 | ||||||
|  |     allowRegWithNumber.default_method = 'getAllowRegWithNumberFromManager' | ||||||
|  |     allowDirectRegistration.default_method = 'getAllowDirectRegistrationFromManager' | ||||||
|  | 
 | ||||||
|     token = Attribute('A name unique within the manager of this service ' |     token = Attribute('A name unique within the manager of this service ' | ||||||
|                 'used for identifying the service e.g. in forms.') |                 'used for identifying the service e.g. in forms.') | ||||||
|     serviceGroup = Attribute('The service group this object is an instance of.') |     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. |         The client should be accessed via an IClientRegistrations adapter. | ||||||
|     """ |     """ | ||||||
| 
 | 
 | ||||||
|     # TODO: provide fields for criteria for selecting the services |     categories = schema.List( | ||||||
|     #       that should be handled by this object, e.g. service |                 title=_(u'Categories'), | ||||||
|     #       category/ies or classification(s). |                 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.') |     manager = Attribute('The service manager this object belongs to.') | ||||||
|     services = Attribute('A collection of services to which this ' |     services = Attribute('A collection of services to which this ' | ||||||
|  |  | ||||||
|  | @ -54,13 +54,16 @@ class ServiceManager(object): | ||||||
|     services = None |     services = None | ||||||
|     clients = None |     clients = None | ||||||
| 
 | 
 | ||||||
|  |     allowRegWithNumber = False | ||||||
|  |     allowDirectRegistration = True | ||||||
|  | 
 | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         if self.servicesFactory is not None: |         if self.servicesFactory is not None: | ||||||
|             self.services = self.servicesFactory() |             self.services = self.servicesFactory() | ||||||
|         if self.clientSchemasFactory is not None: |         if self.clientSchemasFactory is not None: | ||||||
|             self.clientSchemas = self.clientSchemasFactory() |             self.clientSchemas = self.clientSchemasFactory() | ||||||
| 
 | 
 | ||||||
|     def getServices(self): |     def getServices(self, categories=[]): | ||||||
|         return self.services |         return self.services | ||||||
| 
 | 
 | ||||||
|     def getClientSchemas(self): |     def getClientSchemas(self): | ||||||
|  | @ -95,6 +98,7 @@ class Service(object): | ||||||
|     manager = None |     manager = None | ||||||
|     category = None |     category = None | ||||||
|     allowRegWithNumber = False |     allowRegWithNumber = False | ||||||
|  |     allowDirectRegistration = True | ||||||
| 
 | 
 | ||||||
|     def __init__(self, name=None, title=u'', capacity=-1, **kw): |     def __init__(self, name=None, title=u'', capacity=-1, **kw): | ||||||
|         self.name = self.__name__ = name |         self.name = self.__name__ = name | ||||||
|  | @ -151,6 +155,12 @@ class Service(object): | ||||||
|         if clientName in self.registrations: |         if clientName in self.registrations: | ||||||
|             del self.registrations[clientName] |             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): | class ScheduledService(Service): | ||||||
| 
 | 
 | ||||||
|  | @ -158,6 +168,7 @@ class ScheduledService(Service): | ||||||
| 
 | 
 | ||||||
|     start = end = None |     start = end = None | ||||||
| 
 | 
 | ||||||
|  |     # default methods | ||||||
|     def getStartFromManager(self): |     def getStartFromManager(self): | ||||||
|         return getattr(self.getManager(), 'start', None) |         return getattr(self.getManager(), 'start', None) | ||||||
|     def getEndFromManager(self): |     def getEndFromManager(self): | ||||||
|  | @ -186,14 +197,19 @@ class RegistrationTemplate(object): | ||||||
|     def __init__(self, name=None, manager=None): |     def __init__(self, name=None, manager=None): | ||||||
|         self.name = self.__name__ = name |         self.name = self.__name__ = name | ||||||
|         self.manager = self.__parent__ = manager |         self.manager = self.__parent__ = manager | ||||||
|  |         self.categories = [] | ||||||
| 
 | 
 | ||||||
|     @property |     @property | ||||||
|     def services(self): |     def services(self): | ||||||
|         return self.getServices() |         return self.getServices() | ||||||
| 
 | 
 | ||||||
|     def getServices(self): |     def getServices(self): | ||||||
|         # TODO: Restrict according to the objects selection criteria |         svcs = self.getManager().getServices() | ||||||
|         return 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): |     def getManager(self): | ||||||
|         return self.manager |         return self.manager | ||||||
|  | @ -229,7 +245,11 @@ class ClientRegistrations(object): | ||||||
| 
 | 
 | ||||||
|     def getRegistrations(self): |     def getRegistrations(self): | ||||||
|         # TODO: restrict to services on this template |         # 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 | # registration states definition | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm