[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - add.py:1.9.8.2 edit.pt:1.6.2.1 editview.py:1.14.2.1 meta.zcml:1.5.8.1

Jim Fulton jim@zope.com
Tue, 18 Mar 2003 11:56:14 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv21811/zope/app/browser/form

Modified Files:
      Tag: local-utility-branch
	add.py edit.pt editview.py meta.zcml 
Log Message:
checkpoint into branch

=== Zope3/src/zope/app/browser/form/add.py 1.9.8.1 => 1.9.8.2 ===
--- Zope3/src/zope/app/browser/form/add.py:1.9.8.1	Tue Mar 18 07:35:48 2003
+++ Zope3/src/zope/app/browser/form/add.py	Tue Mar 18 11:55:43 2003
@@ -31,7 +31,6 @@
 from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
 from zope.app.browser.form.submit import Update
 from zope.app.browser.form.editview import EditView, _normalize
-from zope.app.interfaces.container import IAdding
 
 class AddView(EditView):
     """Simple edit-view base class
@@ -43,7 +42,7 @@
     def _setUpWidgets(self):
         setUpWidgets(self, self.schema, names=self.fieldNames)
 
-    def apply_update(self, data):
+    def createAndAdd(self, data):
         """Add the desirted object using the data in the data arument
 
         The data argument is a dictionary with the data entered in the form.
@@ -89,20 +88,30 @@
         return content
 
     def update(self):
+
+        if self.update_status is not None:
+            # We've been called before. Just return the previous result.
+            return self.update_status
+
+        self.beforeUpdateHook()
+
         if Update in self.request:
             try:
                 data = getWidgetsData(self, self.schema,
                                       strict=False,
                                       names=self.fieldNames,
                                       set_missing=False)
-                content = self.apply_update(data)
+                content = self.createAndAdd(data)
             except WidgetsError, errors:
                 self.errors = errors
-                return u"An error occured."
+                self.update_status = u"An error occured."
+                return self.update_status
 
             self.request.response.redirect(self.nextURL())
 
-    # Overide these to work with something other than IAdding
+    def beforeUpdateHook(self):
+        pass
+
     def nextURL(self):
         return self.context.nextURL()
 
@@ -140,9 +149,10 @@
 
     provideView(for_, name, IBrowserPresentation, class_, layer)
 
-def add(_context, name, schema, label, content_factory,
+
+def add(_context, name, schema, content_factory, label='',
         permission = 'zope.Public', layer = "default",
-        class_ = None, for_ = None,
+        class_ = None, for_ = 'zope.app.interfaces.container.IAdding',
         template = None, omit=None, fields=None,
         arguments='', keyword_arguments='',
         set_before_add='', set_after_add=''):
@@ -199,11 +209,10 @@
 
     return [
         Action(
-        discriminator = ('view', IAdding, name, IBrowserPresentation, layer),
+        discriminator = ('view', for_, name, IBrowserPresentation, layer),
         callable = AddViewFactory,
         args = (name, schema, label, permission, layer, template, 'add.pt',
-                bases,
-                IAdding, fields, content_factory, arguments,
+                bases, for_, fields, content_factory, arguments,
                 keyword_arguments, set_before_add, set_after_add),
         )
         ]


=== Zope3/src/zope/app/browser/form/edit.pt 1.6 => 1.6.2.1 ===
--- Zope3/src/zope/app/browser/form/edit.pt:1.6	Fri Mar  7 11:39:41 2003
+++ Zope3/src/zope/app/browser/form/edit.pt	Tue Mar 18 11:55:43 2003
@@ -1,4 +1,5 @@
-<html metal:use-macro="views/standard_macros/page">
+<tal:tag condition="view/update"
+><html metal:use-macro="views/standard_macros/page">
   <body>
   <div metal:fill-slot="body">
 


=== Zope3/src/zope/app/browser/form/editview.py 1.14 => 1.14.2.1 ===
--- Zope3/src/zope/app/browser/form/editview.py:1.14	Fri Mar  7 16:28:51 2003
+++ Zope3/src/zope/app/browser/form/editview.py	Tue Mar 18 11:55:43 2003
@@ -47,6 +47,7 @@
     """
 
     errors = ()
+    update_status = None
     label = ''
 
     # Fall-back field names computes from schema
@@ -127,6 +128,13 @@
         return unchanged
 
     def update(self):
+        if self.update_status is not None:
+            # We've been called before. Just return the status we previously
+            # computed.
+            return self.update_status
+
+        status = ''
+        
         if Update in self.request:
             unchanged = True
             try:
@@ -138,14 +146,15 @@
                 unchanged = self.apply_update(data)
             except WidgetsError, errors:
                 self.errors = errors
-                return u"An error occured."
+                status = u"An error occured."
             else:
                 setUpEditWidgets(self, self.schema, force=1,
                                  names=self.fieldNames)
                 if not unchanged:
-                    return "Updated %s" % datetime.utcnow()
+                    status = "Updated %s" % datetime.utcnow()
 
-        return ''
+        self.update_status = status
+        return status
 
 
 def EditViewFactory(name, schema, label, permission, layer,


=== Zope3/src/zope/app/browser/form/meta.zcml 1.5 => 1.5.8.1 ===
--- Zope3/src/zope/app/browser/form/meta.zcml:1.5	Fri Feb 21 04:45:21 2003
+++ Zope3/src/zope/app/browser/form/meta.zcml	Tue Mar 18 11:55:43 2003
@@ -5,6 +5,10 @@
     <directive name="editform" handler=".editview.edit">
 
       <description>
+        Define an automatically generated edit form
+
+        The editForm directive creates and register's a view for
+        editing an object based on a schema.
       </description>
 
       <attribute name="name" required="yes">
@@ -21,7 +25,7 @@
         </description>
         </attribute>
 
-      <attribute name="label" required="yes">
+      <attribute name="label" required="no">
         <description>
         A label to be used as the heading for the form.
         </description>
@@ -34,8 +38,9 @@
         The view will be for all objects that implement this interface.
 
         The schema is used if the for attribute is not specified.
-        If the for attribute is specified, the given
-        interface must extend the schema.
+
+        If the for attribute is specified, then the objects views must
+        implement or be adaptable to the schema.
         </description>
         </attribute>
 
@@ -68,6 +73,9 @@
         <description>
         A class to provide custom widget definitions or methods to be
         used by a custom template.
+
+        This class is used as a mix-in class. As a result, it needn't
+        subclass any special classes, such as BrowserView.
         </description>
         </attribute>
 
@@ -101,11 +109,150 @@
 
     <directive
        name="addform" 
-       attributes="name schema label for layer permission class
-                   template content_factory argument keyword_arguments
-                   set_before_add set_after_add"
        handler="zope.app.browser.form.add.add"
-       />
+       >       
+      <description>
+        Define an automatically generated add form
+
+        The addForm directive creates and register's a view for
+        adding an object based on a schema.
+
+        Adding an object is a bit trickier than editing an object,
+        because the object the schema applies to isn't available when
+        forms are being rendered.  The addForm directive provides an
+        extensive customization interface to overcome this difficulty.
+      </description>
+
+      <attribute name="name" required="yes">
+        <description>
+        The name of the generated add view.
+        </description>
+        </attribute>
+
+      <attribute name="schema" required="yes">
+        <description>
+        The schema from which the add form is generated.
+
+        A schema is an interface that includes fields.
+        </description>
+        </attribute>
+
+      <attribute name="label" required="no">
+        <description>
+        A label to be used as the heading for the form.
+        </description>
+        </attribute>
+
+      <attribute name="for" required="no">
+        <description>
+        The interface this page (view) applies to. 
+
+        The view will be for all objects that implement this interface.
+
+        IAdding is used if this attribute isn't specified.  If this
+        attribute is specified, then either the named interface must
+        extend IAdding or a class attribute must be used to supply a
+        class implements certain methods described in 
+
+        The schema is used if the for attribute is not specified.
+
+        If the for attribute is specified, then the objects views must
+        implement or be adaptable to the schema.
+        </description>
+        </attribute>
+
+      <attribute name="layer" required="no">
+        <description>
+              The layer the view is in. 
+
+              A skin is composed of layers. It is common to put skin specific
+              views in a layer named after the skin. If the 'layer' attribute
+              is not supplied, it defaults to 'default'. 
+          </description>
+        </attribute>
+
+
+       <attribute name="permission" required="yes">
+        <description>
+              The permission needed to use the view. 
+          </description>
+        </attribute>
+
+      <attribute name="template" required="no">
+        <description>
+        An alternate template to use for the edit form.
+
+        XXX Need to document how to extend the default.
+        </description>
+        </attribute>
+
+      <attribute name="class" required="no">
+        <description>
+        A class to provide custom widget definitions or methods to be
+        used by a custom template.
+
+        This class is used as a mix-in class. As a result, it needn't
+        subclass any special classes, such as BrowserView.
+        </description>
+        </attribute>
+
+
+      <attribute name="content_factory" required="no">
+        <description>
+          The dotted name of an object to call to create new content objects.
+
+          This attribute isn't used if a class is specified that
+          implements createAndAdd.
+          </description>
+        </attribute>
+
+      <attribute name="arguments" required="no">
+        <description>
+          A list of field names to supply as positional arguments to
+          the factory.
+        </description>
+      </attribute>
+
+      <attribute name="keyword_arguments" required="no">
+        <description>
+          A list of field names to supply as keyword arguments to
+          the factory.
+        </description>
+      </attribute>
+
+      <attribute name="set_before_add" required="no">
+        <description>
+          A list of fields to be assigned to the newly created object
+          before it is added.
+        </description>
+      </attribute>
+
+      <attribute name="set_after_add" required="no">
+        <description>
+          A list of fields to be assigned to the newly created object
+          after it is added.
+        </description>
+      </attribute>
+
+      <attribute name="menu" required="no">
+        <description>
+          The browser menu to include the edit form in.
+
+          Many views are included in menus. It's convenient to name
+          the menu in the page directive, rather than having to give a
+          separate menuItem directive.
+          </description>
+        </attribute>
+
+      <attribute name="title" required="no">
+        <description>
+          The browser menu label for the edit form
+
+          This attribute defaults to "Edit".
+          </description>
+        </attribute>
+
+      </directive>
 
   </directives>