register and unregister directly on service view
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1988 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
e2e4f5ea8c
commit
a0756037b2
3 changed files with 55 additions and 6 deletions
|
@ -57,6 +57,13 @@ class BaseView(object):
|
|||
self.clientName = clientName
|
||||
self.setSessionInfo('clientName', clientName)
|
||||
|
||||
def formatClientInfo(self, data, default=None):
|
||||
info = ' '.join((data.get('standard.firstName', ''),
|
||||
data.get('standard.lastName', ''))).strip()
|
||||
org = data.get('standard.organization', '')
|
||||
info = ', '.join([text for text in (info, org) if text])
|
||||
return info or (default is None and data.get('__name__', '???')) or default
|
||||
|
||||
@Lazy
|
||||
def manager(self):
|
||||
return self.context.getManager()
|
||||
|
|
|
@ -35,7 +35,7 @@ from cybertools.composer.schema.interfaces import IClientFactory
|
|||
from cybertools.util.format import formatDate
|
||||
|
||||
|
||||
class BaseView(object):
|
||||
class BaseView(SchemaBaseView):
|
||||
|
||||
def __init__(self, context, request):
|
||||
self.context = context
|
||||
|
@ -133,13 +133,27 @@ class ServiceView(BaseView):
|
|||
def getRegistrations(self):
|
||||
return self.context.registrations
|
||||
|
||||
def registrationUrl(self):
|
||||
def getRegistrationTemplate(self):
|
||||
context = self.context
|
||||
man = context.getManager()
|
||||
tpl = ServiceManagerView(man, self.request).findRegistrationTemplate(context)
|
||||
return ServiceManagerView(man, self.request).findRegistrationTemplate(context)
|
||||
|
||||
def registrationUrl(self):
|
||||
tpl = self.getRegistrationTemplate()
|
||||
return self.getUrlForObject(tpl)
|
||||
|
||||
def getClientData(self, clientName):
|
||||
def getClientData(self):
|
||||
clientName = self.getClientName()
|
||||
if clientName is None:
|
||||
return {}
|
||||
data = self.getDataForClient(clientName)
|
||||
regs = self.getRegistrations()
|
||||
reg = regs.get(clientName)
|
||||
if reg:
|
||||
data['service_registration'] = reg
|
||||
return data
|
||||
|
||||
def getDataForClient(self, clientName):
|
||||
manager = self.context.getManager()
|
||||
client = manager.getClients().get(clientName)
|
||||
if client is None:
|
||||
|
@ -147,8 +161,34 @@ class ServiceView(BaseView):
|
|||
instance = IInstance(client)
|
||||
return instance.applyTemplate()
|
||||
|
||||
def update(self):
|
||||
form = self.request.form
|
||||
clientName = self.getClientName()
|
||||
if not form.get('action'):
|
||||
return True
|
||||
manager = self.context.getManager()
|
||||
if clientName:
|
||||
client = manager.getClients().get(clientName)
|
||||
if client is None:
|
||||
return True
|
||||
else:
|
||||
client = IClientFactory(manager)()
|
||||
clientName = manager.addClient(client)
|
||||
self.setClientName(clientName)
|
||||
regs = IClientRegistrations(client)
|
||||
try:
|
||||
number = int(form.get('number', 1))
|
||||
except ValueError:
|
||||
number = 1
|
||||
if 'button.register' in form:
|
||||
regs.register([self.context], numbers=[number])
|
||||
elif 'button.unregister' in form:
|
||||
regs.unregister([self.context])
|
||||
# TODO: redirect to nextUrl()
|
||||
return True
|
||||
|
||||
class RegistrationTemplateView(SchemaBaseView):
|
||||
|
||||
class RegistrationTemplateView(BaseView):
|
||||
|
||||
@Lazy
|
||||
def services(self):
|
||||
|
@ -201,7 +241,8 @@ class RegistrationTemplateView(SchemaBaseView):
|
|||
return True
|
||||
else:
|
||||
client = IClientFactory(manager)()
|
||||
clientName = self.clientName = manager.addClient(client)
|
||||
clientName = manager.addClient(client)
|
||||
self.setClientName(clientName)
|
||||
regs = IClientRegistrations(client)
|
||||
regs.template = self.context
|
||||
services = manager.getServices() # a mapping!
|
||||
|
|
|
@ -228,6 +228,7 @@ class ClientRegistrations(object):
|
|||
service.unregister(self.context)
|
||||
|
||||
def getRegistrations(self):
|
||||
# TODO: restrict to services on this template
|
||||
return getattr(self.context, self.registrationsAttributeName, [])
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue