Skip to content

Commit

Permalink
Fixed registration views, so that the site management interface becomes
Browse files Browse the repository at this point in the history
useful again.

Reimplemented tools with a compacter UI (which still needs some work).

Fixed bug that prevented us to create absolute urls for views. This was 
due to the fact that getView has been deprecated. The name and parent of 
a view are now the responsibility of the factory.
  • Loading branch information
strichter committed Jan 12, 2005
1 parent 8329b8d commit ac42a94
Show file tree
Hide file tree
Showing 5 changed files with 392 additions and 5 deletions.
5 changes: 2 additions & 3 deletions browser/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ def AddViewFactory(name, schema, label, permission, layer,
keyword_arguments, set_before_add, set_after_add,
menu=u''):

# XXX: Needs to be tested
class_ = SimpleViewClass(
template,
used_for = schema, bases = bases
)
template, used_for=schema, bases=bases, name=name)

class_.schema = schema
class_.label = label
Expand Down
143 changes: 143 additions & 0 deletions browser/addwizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Add Wizard View Classes
$Id$
"""
__docformat__ = 'restructuredtext'

import sys

from zope.app import zapi
from zope.event import notify
from zope.app.event.objectevent import ObjectCreatedEvent
from zope.app.form.utility import setUpWidgets
from zope.app.form.interfaces import WidgetsError, IInputWidget
from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.schema.interfaces import ValidationError
from zope.security.checker import defineChecker, NamesChecker
from editwizard import EditWizardView, WizardStorage

class AddWizardView(EditWizardView):
"""Multi-page add-view base class.
Subclasses should provide a `schema` attribute defining the schema
to be edited.
"""

def _setUpWidgets(self):
if self.use_session:
# Need session for File upload fields
raise NotImplementedError, 'Need a working ISessionDataManager'
else:
self.storage = WizardStorage(self.fieldNames, None)

setUpWidgets(self, self.schema, IInputWidget, names=self.fieldNames)

def create(self, *args, **kw):
"""Do the actual instantiation."""
return self._factory(*args, **kw)

def apply_update(self, data):
"""Add the desired object using the data in the data argument.
The data argument is a dictionary with the data entered in the form.
Issues a redirect to `context.nextURL()`
Returns ``False``, as per `editview.apply_update`
"""

# This code originally from add.py's createAndAdd method

args = []
for name in self._arguments:
args.append(data[name])

kw = {}
for name in self._keyword_arguments:
if name in data:
kw[str(name)] = data[name]

content = self.create(*args, **kw)
adapted = self.schema(content)

errors = []

for name in self._set_before_add:
if name in data:
field = self.schema[name]
try:
field.set(adapted, data[name])
except ValidationError:
errors.append(sys.exc_info()[1])

if errors:
raise WidgetsError(*errors)

notify(ObjectCreatedEvent(content))

content = self.context.add(content)

adapted = self.schema(content)

for name in self._set_after_add:
if name in data:
field = self.schema[name]
try:
field.set(adapted, data[name])
except ValidationError:
errors.append(sys.exc_info()[1])

if errors:
raise WidgetsError(*errors)

self.request.response.redirect(self.context.nextURL())
return False

# XXX: Needs unittest
def AddWizardViewFactory(
name, schema, permission, layer, panes, fields,
template, default_template, bases, for_, content_factory, arguments,
keyword_arguments, set_before_add, set_after_add, use_session=True):

# XXX: name=name Needs to be tested
class_ = SimpleViewClass(template, used_for=schema, bases=bases,
name=name)

class_.schema = schema
class_.panes = panes
class_.fieldNames = fields
class_._factory = content_factory
class_._arguments = arguments or []
class_._keyword_arguments = keyword_arguments or []
class_._set_before_add = set_before_add or []
class_._set_after_add = set_after_add or []
class_.use_session = use_session

class_.generated_form = ViewPageTemplateFile(default_template)

defineChecker(class_,
NamesChecker(
("__call__", "__getitem__", "browserDefault"),
permission,
)
)
if layer is None:
layer = IDefaultBrowserLayer

sm = zapi.getGlobalSiteManager()
sm.provideAdapter((for_, layer), Interface, name, class_)
3 changes: 2 additions & 1 deletion browser/editview.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def update(self):
def EditViewFactory(name, schema, label, permission, layer,
template, default_template, bases, for_, fields,
fulledit_path=None, fulledit_label=None, menu=u''):
class_ = SimpleViewClass(template, used_for=schema, bases=bases)
# XXX: Need to test name=name
class_ = SimpleViewClass(template, used_for=schema, bases=bases, name=name)
class_.schema = schema
class_.label = label
class_.fieldNames = fields
Expand Down
Loading

0 comments on commit ac42a94

Please sign in to comment.