ServiceView: error feedback, capacity check
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2129 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
dcbe6f15eb
commit
473955b503
2 changed files with 13 additions and 5 deletions
|
@ -192,6 +192,7 @@ class CheckoutView(ServiceManagerView):
|
|||
class ServiceView(BaseView):
|
||||
|
||||
showCheckoutButton = False
|
||||
state = None
|
||||
|
||||
def getRegistrations(self):
|
||||
return self.context.registrations
|
||||
|
@ -249,15 +250,16 @@ class ServiceView(BaseView):
|
|||
return True
|
||||
else:
|
||||
client = IClientFactory(manager)()
|
||||
clientName = manager.addClient(client)
|
||||
self.setClientName(clientName)
|
||||
newClient = True
|
||||
nextUrl = self.getSchemaUrl()
|
||||
regs = IClientRegistrations(client)
|
||||
regs = self.state = IClientRegistrations(client)
|
||||
try:
|
||||
number = int(form.get('number', 1))
|
||||
except ValueError:
|
||||
number = 1
|
||||
regs.validate(clientName, [self.context], [number])
|
||||
if regs.severity > 0:
|
||||
return True
|
||||
if 'submit_register' in form and number > 0:
|
||||
regs.register([self.context], numbers=[number])
|
||||
self.showCheckoutButton = True
|
||||
|
@ -266,6 +268,9 @@ class ServiceView(BaseView):
|
|||
number = 0
|
||||
elif 'submit_checkout' in form:
|
||||
nextUrl = self.getSchemaUrl()
|
||||
if newClient:
|
||||
clientName = manager.addClient(client)
|
||||
self.setClientName(clientName)
|
||||
if nextUrl:
|
||||
self.request.response.redirect(nextUrl)
|
||||
return False
|
||||
|
|
|
@ -277,8 +277,11 @@ class ClientRegistrations(object):
|
|||
if numbers is None:
|
||||
numbers = len(services) * [1]
|
||||
for svc, n in zip(services, numbers):
|
||||
oldReg = svc.registrations.get(clientName, None)
|
||||
oldN = oldReg and oldReg.number or 0
|
||||
if clientName:
|
||||
oldReg = svc.registrations.get(clientName, None)
|
||||
oldN = oldReg and oldReg.number or 0
|
||||
else:
|
||||
oldN = 0
|
||||
if svc.capacity and svc.capacity > 0 and svc.availableCapacity < n - oldN:
|
||||
error = registrationErrors['capacity_exceeded']
|
||||
entry = self.errors.setdefault(svc.token, [])
|
||||
|
|
Loading…
Add table
Reference in a new issue