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 = '''
Teilnehmer | +Teilnehmer | %sAngebot | Datum/Uhrzeit | Ort | @@ -254,7 +290,7 @@ class CheckoutView(ServiceManagerView): ''' row = '''||
---|---|---|---|---|---|---|
%i | +%i | %s%s | %s | %s | @@ -262,16 +298,23 @@ class CheckoutView(ServiceManagerView): ''' def listRegistrationsHtml(self): result = [] + waitingHeader = '' + waitingRow = '%i | ' + if self.hasWaiting: + waitingHeader = 'Warteliste | ' 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