From cbbb46d02f79f38c36a9dc7890254dd38c9baef4 Mon Sep 17 00:00:00 2001 From: helmutm Date: Sun, 28 Jun 2009 15:01:45 +0000 Subject: [PATCH] waiting list: base functionality OK git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3429 fd906abe-77d9-0310-91a1-e0d9ade77398 --- organize/browser/service.py | 69 ++++++++++++++++++++++++++++++------- organize/service.py | 14 +++++--- 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/organize/browser/service.py b/organize/browser/service.py index 38b35b2..04228d6 100644 --- a/organize/browser/service.py +++ b/organize/browser/service.py @@ -211,16 +211,37 @@ class CheckoutView(ServiceManagerView): for reg in regs: service = reg.service result.append(dict(service=service.title or '???', + waitingList=service.waitingList, fromTo=self.getFromTo(service), location=service.location or '', locationUrl=service.locationUrl or '', number=reg.number, + numberWaiting=reg.numberWaiting, serviceObject=service)) return result + @Lazy + def registrationsInfo(self): + return self.getRegistrationsInfo() + + @Lazy + def hasWaiting(self): + for reg in self.registrationsInfo: + if reg['numberWaiting'] > 0: + return True + return False + + def getLocationInfo(self, info): + location, locationUrl = info['location'], info['locationUrl'] + if locationUrl and locationUrl.startswith('/'): + locationUrl = self.request.get('SERVER_URL') + locationUrl + locationInfo = (locationUrl and '%s (%s)' % (location, locationUrl) + or location) + return locationInfo + def listRegistrationsTextTable(self): result = [] - for info in self.getRegistrationsInfo(): + for info in self.registrationsInfo: line = '%-30s %27s' % (info['service'], info['fromTo']) if info['serviceObject'].allowRegWithNumber: line += ' %4i' % info['number'] @@ -229,22 +250,37 @@ class CheckoutView(ServiceManagerView): def listRegistrationsText(self): result = [] - for info in self.getRegistrationsInfo(): - location, locationUrl = info['location'], info['locationUrl'] - if locationUrl and locationUrl.startswith('/'): - locationUrl = self.request.get('SERVER_URL') + locationUrl - locationInfo = (locationUrl and '%s (%s)' % (location, locationUrl) - or location) + for info in self.registrationsInfo: + if not info['number'] and not info['numberWaiting']: + continue + locationInfo = self.getLocationInfo(info) + line = '\n'.join((info['service'], info['fromTo'], locationInfo)) + if info['serviceObject'].allowRegWithNumber and info['number']: + line += '\nTeilnehmer: %s\n' % info['number'] + if info['numberWaiting']: + line += 'Teilnehmer auf Warteliste' + if info['serviceObject'].allowRegWithNumber: + line += ': %s' % info['numberWaiting'] + line += '\n' + result.append(line) + return '\n'.join(result) + + def listRegistrationsWaitingText(self): + result = [] + for info in self.registrationsInfo: + if not info['numberWaiting']: + continue + locationInfo = self.getLocationInfo(info) line = '\n'.join((info['service'], info['fromTo'], locationInfo)) if info['serviceObject'].allowRegWithNumber: - line += '\nTeilnehmer: %s\n' % info['number'] + line += '\nTeilnehmer: %s\n' % info['numberWaiting'] result.append(line) return '\n'.join(result) html = ''' - + %s @@ -254,7 +290,7 @@ class CheckoutView(ServiceManagerView): ''' row = ''' - + %s @@ -262,16 +298,23 @@ class CheckoutView(ServiceManagerView): ''' def listRegistrationsHtml(self): result = [] + waitingHeader = '' + waitingRow = '' + if self.hasWaiting: + waitingHeader = '' for info in self.getRegistrationsInfo(): location, locationUrl = info['location'], info['locationUrl'] locationInfo = (locationUrl and ('%s' % (locationUrl, location)) or location) - line = self.row % (info['number'], info['service'], + line = self.row % (info['number'], + self.hasWaiting and + waitingRow % info['numberWaiting'] or '', + info['service'], info['fromTo'].replace(' ', '  '), locationInfo) result.append(line) - return self.html % '\n'.join(result) + return self.html % (waitingHeader, '\n'.join(result)) class ServiceView(BaseView): @@ -356,6 +399,8 @@ class ServiceView(BaseView): if state.name != 'temporary': total += reg.number totalWaiting += reg.numberWaiting + if not self.context.waitingList: + totalWaiting = '' return dict(number=total, numberWaiting=totalWaiting) def update(self): diff --git a/organize/service.py b/organize/service.py index 4db075d..9b8d619 100644 --- a/organize/service.py +++ b/organize/service.py @@ -169,13 +169,17 @@ class Service(object): def register(self, client, number=1): clientName = client.__name__ - numberWaiting = 0 - if (self.waitingList and self.availableCapacity >= 0 - and number > self.availableCapacity): - numberWaiting = number - self.availableCapacity - number = self.availableCapacity + numberWaiting = current = 0 + reg = None if clientName in self.registrations: reg = self.registrations[clientName] + current = reg.number + if (self.waitingList and self.availableCapacity >= 0 + and number > (self.availableCapacity + current)): + numberWaiting = number - current - self.availableCapacity + #number = self.availableCapacity + current + number = number - numberWaiting + if reg is not None: if number != reg.number: reg.number = number # TODO: set timeStamp
TeilnehmerTeilnehmerAngebot Datum/Uhrzeit Ort
%i%i%s %s %s%iWarteliste