correctly handle the checkout situation when the capacity of a service is exceeded
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3625 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									dcdd97f23d
								
							
						
					
					
						commit
						0341411d22
					
				
					 2 changed files with 22 additions and 5 deletions
				
			
		|  | @ -210,17 +210,23 @@ class CheckoutView(ServiceManagerView): | ||||||
|         client = self.getClient() |         client = self.getClient() | ||||||
|         if client is None: |         if client is None: | ||||||
|             return {} |             return {} | ||||||
|         regs = IClientRegistrations(client) |         #clientRegs = IClientRegistrations(client) | ||||||
|  |         #regs = sorted(clientRegs.getRegistrations(), key=self.sortKey) | ||||||
|  |         regs = self.registrationsInfo | ||||||
|         instance = IInstance(client) |         instance = IInstance(client) | ||||||
|         data = instance.applyTemplate() |         data = instance.applyTemplate() | ||||||
|         data['service_registrations'] = sorted(regs.getRegistrations(), |         data['service_registrations'] = regs | ||||||
|                                                key=self.sortKey) |         data['info_messages'] = [item['info'] for item in regs if item['info']] | ||||||
|  |         data['errors'] = [item['error'] for item in regs if item['error']] | ||||||
|         return data |         return data | ||||||
| 
 | 
 | ||||||
|     def sortKey(self, reg): |     def sortKey(self, reg): | ||||||
|         return reg.service.start |         return reg.service.start | ||||||
| 
 | 
 | ||||||
|     def update(self): |     def update(self): | ||||||
|  |         data = self.getClientData() | ||||||
|  |         if data['errors']: | ||||||
|  |             return True | ||||||
|         form = self.request.form |         form = self.request.form | ||||||
|         clientName = self.getClientName() |         clientName = self.getClientName() | ||||||
|         if not form.get('action'): |         if not form.get('action'): | ||||||
|  | @ -246,10 +252,17 @@ class CheckoutView(ServiceManagerView): | ||||||
|         if client is None: |         if client is None: | ||||||
|             return [] |             return [] | ||||||
|         result = [] |         result = [] | ||||||
|         regs = IClientRegistrations(client) |         clientRegs = IClientRegistrations(client) | ||||||
|         regs = sorted(regs.getRegistrations(), key=self.sortKey) |         regs = sorted(clientRegs.getRegistrations(), key=self.sortKey) | ||||||
|         for reg in regs: |         for reg in regs: | ||||||
|  |             info = error = u'' | ||||||
|             service = reg.service |             service = reg.service | ||||||
|  |             if (service.capacity >= 0 and | ||||||
|  |                     IStateful(reg).state == 'temporary' and | ||||||
|  |                     service.getNumberRegistered() + reg.number > service.capacity): | ||||||
|  |                 service.unregister(client) | ||||||
|  |                 clientRegs.unregister([service]) | ||||||
|  |                 info = error = u'capacity_exceeded' | ||||||
|             result.append(dict(service=service.title or '???', |             result.append(dict(service=service.title or '???', | ||||||
|                                waitingList=service.waitingList, |                                waitingList=service.waitingList, | ||||||
|                                fromTo=self.getFromTo(service), |                                fromTo=self.getFromTo(service), | ||||||
|  | @ -262,6 +275,8 @@ class CheckoutView(ServiceManagerView): | ||||||
|                                numberWaiting=reg.numberWaiting, |                                numberWaiting=reg.numberWaiting, | ||||||
|                                externalId=service.externalId or '', |                                externalId=service.externalId or '', | ||||||
|                                cost=self.getCost(service), |                                cost=self.getCost(service), | ||||||
|  |                                info=info, | ||||||
|  |                                error=error, | ||||||
|                                serviceObject=service)) |                                serviceObject=service)) | ||||||
|         return result |         return result | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -203,6 +203,8 @@ class Service(object): | ||||||
|     def unregister(self, client): |     def unregister(self, client): | ||||||
|         clientName = client.__name__ |         clientName = client.__name__ | ||||||
|         if clientName in self.registrations: |         if clientName in self.registrations: | ||||||
|  |             reg = self.registrations[clientName] | ||||||
|  |             reg.number = reg.numberWaiting = 0 | ||||||
|             del self.registrations[clientName] |             del self.registrations[clientName] | ||||||
| 
 | 
 | ||||||
|     def getNumberRegistered(self, ignoreTemporary=True): |     def getNumberRegistered(self, ignoreTemporary=True): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm