provide navigation between forms
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1882 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
5396c068fc
commit
5247eee6f6
6 changed files with 125 additions and 35 deletions
91
composer/schema/browser/common.py
Normal file
91
composer/schema/browser/common.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
#
|
||||
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Common base class(es) for schema and other template views.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope import component
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
|
||||
from cybertools.composer.interfaces import IInstance
|
||||
from cybertools.composer.schema.interfaces import IClientFactory
|
||||
|
||||
|
||||
class BaseView(object):
|
||||
|
||||
clientName = None
|
||||
|
||||
def __init__(self, context, request):
|
||||
self.context = context
|
||||
self.request = request
|
||||
|
||||
@Lazy
|
||||
def manager(self):
|
||||
return self.context.getManager()
|
||||
|
||||
@Lazy
|
||||
def previousTemplate(self):
|
||||
return self.getPreviousTemplate()
|
||||
|
||||
def getPreviousTemplate(self):
|
||||
templates = self.context.getManager().getClientSchemas()
|
||||
context = self.context
|
||||
idx = templates.find(context)
|
||||
if idx > 0:
|
||||
#return templates[idx-1].name
|
||||
return templates.keys()[idx-1]
|
||||
else:
|
||||
return None
|
||||
|
||||
@Lazy
|
||||
def nextTemplate(self):
|
||||
return self.getNextTemplate()
|
||||
|
||||
def getNextTemplate(self):
|
||||
templates = self.context.getManager().getClientSchemas()
|
||||
context = self.context
|
||||
idx = templates.find(context)
|
||||
if 0 <= idx < len(templates) - 1:
|
||||
#return templates[idx+1].name
|
||||
return templates.keys()[idx+1]
|
||||
else:
|
||||
return None
|
||||
|
||||
@Lazy
|
||||
def url(self):
|
||||
from zope.traversing.browser import absoluteURL
|
||||
url = absoluteURL(self.context, self.request)
|
||||
|
||||
buttonActions = dict(
|
||||
submit_previous=getPreviousTemplate,
|
||||
submit_next=getNextTemplate,
|
||||
)
|
||||
|
||||
#@Lazy
|
||||
def nextUrl(self):
|
||||
#viewName = 'thankyou.html'
|
||||
viewName = ''
|
||||
form = self.request.form
|
||||
for bn in self.buttonActions:
|
||||
if bn in form:
|
||||
viewName = self.buttonActions[bn](self)
|
||||
break
|
||||
return '%s/%s?id=%s' % (self.url, viewName, self.clientName)
|
|
@ -8,7 +8,7 @@
|
|||
<page
|
||||
for="cybertools.composer.schema.interfaces.ISchema"
|
||||
name="index.html"
|
||||
class="cybertools.composer.schema.browser.base.SchemaView"
|
||||
class="cybertools.composer.schema.browser.schema.SchemaView"
|
||||
permission="zope.View"
|
||||
/>
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
|||
<page
|
||||
for="cybertools.composer.schema.interfaces.ISchema"
|
||||
name="thankyou.html"
|
||||
class="cybertools.composer.schema.browser.base.SchemaView"
|
||||
class="cybertools.composer.schema.browser.schema.SchemaView"
|
||||
permission="zope.View"
|
||||
/>
|
||||
|
||||
|
|
|
@ -25,17 +25,12 @@ $Id$
|
|||
from zope import component
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
|
||||
from cybertools.composer.schema.browser.common import BaseView
|
||||
from cybertools.composer.interfaces import IInstance
|
||||
from cybertools.composer.schema.interfaces import IClientFactory
|
||||
|
||||
|
||||
class SchemaView(object):
|
||||
|
||||
clientName = None
|
||||
|
||||
def __init__(self, context, request):
|
||||
self.context = context
|
||||
self.request = request
|
||||
class SchemaView(BaseView):
|
||||
|
||||
@Lazy
|
||||
def fields(self):
|
||||
|
@ -78,12 +73,7 @@ class SchemaView(object):
|
|||
instance = component.getAdapter(client, IInstance, name='editor')
|
||||
instance.template = self.context
|
||||
instance.applyTemplate(form)
|
||||
return True
|
||||
#self.request.response.redirect(self.nextUrl)
|
||||
#return False
|
||||
#return True
|
||||
self.request.response.redirect(self.nextUrl())
|
||||
return False
|
||||
|
||||
@Lazy
|
||||
def nextUrl(self):
|
||||
from zope.traversing.browser import absoluteURL
|
||||
url = absoluteURL(self.context, self.request)
|
||||
return '%s/thankyou.html?id=%s' % (url, self.clientName)
|
|
@ -26,16 +26,11 @@ from zope import component
|
|||
from zope.cachedescriptors.property import Lazy
|
||||
|
||||
from cybertools.organize.interfaces import IClientRegistrations
|
||||
from cybertools.composer.schema.browser.common import BaseView
|
||||
from cybertools.composer.schema.interfaces import IClientFactory
|
||||
|
||||
|
||||
class RegistrationTemplateView(object):
|
||||
|
||||
clientName = None
|
||||
|
||||
def __init__(self, context, request):
|
||||
self.context = context
|
||||
self.request = request
|
||||
class RegistrationTemplateView(BaseView):
|
||||
|
||||
@Lazy
|
||||
def services(self):
|
||||
|
@ -87,12 +82,6 @@ class RegistrationTemplateView(object):
|
|||
toDelete = [s for s in oldServices
|
||||
if s in allServices and s not in newServices]
|
||||
regs.unregister(toDelete)
|
||||
return True
|
||||
#self.request.response.redirect(self.nextUrl)
|
||||
#return False
|
||||
|
||||
@Lazy
|
||||
def nextUrl(self):
|
||||
from zope.traversing.browser import absoluteURL
|
||||
url = absoluteURL(self.context, self.request)
|
||||
return '%s/thankyou.html?id=%s' % (url, self.clientName)
|
||||
#return True
|
||||
self.request.response.redirect(self.nextUrl())
|
||||
return False
|
||||
|
|
|
@ -58,6 +58,9 @@ class ServiceManager(object):
|
|||
def getServices(self):
|
||||
return self.services
|
||||
|
||||
def getClientSchemas(self):
|
||||
return self.clientSchemas
|
||||
|
||||
@Lazy
|
||||
def clients(self):
|
||||
return self.clientsFactory()
|
||||
|
@ -138,8 +141,8 @@ class RegistrationTemplate(object):
|
|||
implements(IRegistrationTemplate)
|
||||
|
||||
def __init__(self, name=None, manager=None):
|
||||
self.name = name
|
||||
self.manager = manager
|
||||
self.name = self.__name__ = name
|
||||
self.manager = self.__parent__ = manager
|
||||
|
||||
@property
|
||||
def services(self):
|
||||
|
|
17
util/jeep.py
17
util/jeep.py
|
@ -105,3 +105,20 @@ class Jeep(object):
|
|||
delattr(self, key)
|
||||
return value
|
||||
|
||||
def find(self, obj):
|
||||
if isinstance(obj, basestring):
|
||||
key = obj
|
||||
else:
|
||||
key = getattr(obj, '__name__', getattr(obj, 'name', _notfound))
|
||||
if key is _notfound:
|
||||
raise AttributeError("No name attribute present")
|
||||
if key in self:
|
||||
return self._sequence.index(key)
|
||||
else:
|
||||
return -1
|
||||
|
||||
def index(self, obj):
|
||||
idx = self.find(obj)
|
||||
if idx < 0:
|
||||
raise ValueError('list.index(x): x not in list')
|
||||
return idx
|
||||
|
|
Loading…
Add table
Reference in a new issue