[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Forms/Browser - subedit.pt:1.1.2.1 EditView.py:1.3.12.1 meta.zcml:1.1.18.1

Jim Fulton jim@zope.com
Wed, 11 Dec 2002 06:41:38 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Forms/Browser
In directory cvs.zope.org:/tmp/cvs-serv23318/lib/python/Zope/App/Forms/Browser

Modified Files:
      Tag: AdapterAndView-branch
	EditView.py meta.zcml 
Added Files:
      Tag: AdapterAndView-branch
	subedit.pt 
Log Message:
Got AdapterService views working.

=== Added File Zope3/lib/python/Zope/App/Forms/Browser/subedit.pt ===
<div metal:define-macro="formbody">

  <span tal:condition="view/label"
      tal:content="view/label"
      metal:define-slot="heading"
      >Edit something</span>

  <p tal:define="status view/update"
     tal:condition="status"
     tal:content="status" />

  <div tal:condition="view/errors">
     <ul>
        <li tal:repeat="error view/errors">
           <strong tal:content="error/__class__">
              Error Type</strong>:
           <span tal:content="error">Error text</span>
        </li>
     </ul>
  </div>

  <div metal:define-slot="extra_info" tal:replace="nothing">
  </div>

  <table width="100%" border="0">
  <tr metal:define-slot="extra_top" tal:replace="nothing">
      <td>Extra top</td>
      <td><input type="text" style="width:100%" /></td>
  </tr>
  <tr metal:define-macro="widget_rows" tal:repeat="widget view/widgets"
      tal:content="structure widget/row">
      <td>Name</td>
      <td><input type="text" style="width:100%" /></td>
  </tr>
  <tr metal:define-slot="extra_bottom" tal:replace="nothing">
      <td>Extra bottom</td>
      <td><input type="text" style="width:100%" /></td>
  </tr>
  </table>

</div>


=== Zope3/lib/python/Zope/App/Forms/Browser/EditView.py 1.3 => 1.3.12.1 ===
--- Zope3/lib/python/Zope/App/Forms/Browser/EditView.py:1.3	Sun Dec  1 05:22:33 2002
+++ Zope3/lib/python/Zope/App/Forms/Browser/EditView.py	Wed Dec 11 06:41:06 2002
@@ -42,22 +42,17 @@
     errors = ()
     label = ''
 
-    generated_form = index = ViewPageTemplateFile('edit.pt')
-
     def __init__(self, context, request):
         super(EditView, self).__init__(context, request)
-        setUpEditWidgets(self, self.schema)
+        setUpEditWidgets(self, self.schema, names=self.fieldNames)
 
     def setPrefix(self, prefix):
         for widget in self.widgets():
             widget.setPrefix(prefix)
 
-    def __call__(self, *args, **kw):
-        return self.index(*args, **kw)
-
     def widgets(self):
         return [getattr(self, name)
-                for name in fieldNames(self.schema)
+                for name in self.fieldNames
                 ]
 
     def apply_update(self, data):
@@ -110,7 +105,8 @@
         if Update in self.request:
             unchanged = True
             try:
-                data = getWidgetsData(self, self.schema, required=0)
+                data = getWidgetsData(self, self.schema,
+                                      required=0, names=self.fieldNames)
                 unchanged = self.apply_update(data)
             except WidgetsError, errors:
                 self.errors = errors
@@ -119,22 +115,17 @@
                 self.errors = (v, )
                 return u"An error occured."
             else:
-                setUpEditWidgets(self, self.schema, force=1)
+                setUpEditWidgets(self, self.schema, force=1,
+                                 names=self.fieldNames)
                 if not unchanged:
                     return "Updated %s" % datetime.utcnow()
 
         return ''
 
-    
 
 def EditViewFactory(name, schema, label, permission, layer,
-                    template, class_, for_):
+                    template, default_template, bases, for_, fields):
 
-    if class_ is None:
-        bases = EditView,
-    else:
-        bases = class_, EditView
-    
     class_  = SimpleViewClass(
         template,
         used_for = schema, bases = bases
@@ -142,6 +133,9 @@
 
     class_.schema = schema
     class_.label = label
+    class_.fieldNames = fields
+
+    class_.generated_form = ViewPageTemplateFile(default_template)
 
     defineChecker(class_,
                   NamesChecker(
@@ -152,34 +146,87 @@
 
     provideView(for_, name, IBrowserPresentation, class_, layer)
                   
-        
 
-def directive(_context, name, schema, label,
-              permission = 'Zope.Public', layer = "default",
-              class_ = None, for_ = None,
-              template = None):
+def _normalize(_context, schema_, for_, class_, template, default_template,
+               fields, omit):
+    schema = _context.resolve(schema_)
 
-    schema = _context.resolve(schema)
     if for_ is None:
         for_ = schema
     else:
         for_ = _context.resolve(for_)
-    if class_ is not None:
-        class_ = _context.resolve(class_)
+
+    if class_ is None:
+        bases = (EditView, )
+    else:
+        bases = (_context.resolve(class_), EditView)
+        
+
     if template is not None:
         template = _context.path(template)
     else:
-        template = 'edit.pt'
+        template = default_template
 
     template = str(template)
 
+    names = fieldNames(schema)
+    
+    if fields:
+        fields = fields.split()
+        for name in fields:
+            if name not in names:
+                raise ValueError("Field name %s is not in schema %s",
+                                 name, schema_)
+    else:
+        fields = names
+
+    if omit:
+        omit = omit.split()
+        for name in omit:
+            if name not in names:
+                raise ValueError("Field name %s is not in schema %s",
+                                 name, schema_)
+        fields = [name for name in fields if name not in omit]
+
+    return schema, for_, bases, template, fields
+
+def edit(_context, name, schema, label,
+              permission = 'Zope.Public', layer = "default",
+              class_ = None, for_ = None,
+              template = None, omit=None, fields=None):
+
+    (schema, for_, bases, template, fields,
+     ) = _normalize(
+        _context, schema, for_, class_, template, 'edit.pt', fields, omit)
+
     return [
         Action(
         discriminator = ('http://namespaces.zope.org/form/edit',
                          name, for_, layer),
         callable = EditViewFactory,
-        args = (name, schema, label, permission, layer, template, class_,
-                for_),
+        args = (name, schema, label, permission, layer, template, 'edit.pt',
+                bases,
+                for_, fields),
+        )
+        ]
+
+def subedit(_context, name, schema, label,
+              permission = 'Zope.Public', layer = "default",
+              class_ = None, for_ = None,
+              template = None, omit=None, fields=None):
+
+    (schema, for_, bases, template, fields,
+     ) = _normalize(
+        _context, schema, for_, class_, template, 'subedit.pt', fields, omit)
+
+    return [
+        Action(
+        discriminator = ('http://namespaces.zope.org/form/subedit',
+                         name, for_, layer),
+        callable = EditViewFactory,
+        args = (name, schema, label, permission, layer, template, 'subedit.pt',
+                bases,
+                for_, fields),
         )
         ]
 


=== Zope3/lib/python/Zope/App/Forms/Browser/meta.zcml 1.1 => 1.1.18.1 ===
--- Zope3/lib/python/Zope/App/Forms/Browser/meta.zcml:1.1	Mon Nov 11 15:29:58 2002
+++ Zope3/lib/python/Zope/App/Forms/Browser/meta.zcml	Wed Dec 11 06:41:06 2002
@@ -5,7 +5,13 @@
     <directive
        name="edit" 
        attributes="name schema label for layer permission class template"
-       handler=".EditView.directive"
+       handler=".EditView.edit"
+       />
+
+    <directive
+       name="subedit" 
+       attributes="name schema label for layer permission class template"
+       handler=".EditView.subedit"
        />
 
   </directives>