[Checkins] SVN: z3c.formui/trunk/ - Feature: Added layout support for ``IAdding`` component based add

Stephan Richter srichter at cosmos.phy.tufts.edu
Sun Aug 31 01:08:27 EDT 2008


Log message for revision 90626:
  - Feature: Added layout support for ``IAdding`` component based add 
    forms.
  

Changed:
  U   z3c.formui/trunk/CHANGES.txt
  U   z3c.formui/trunk/buildout.cfg
  U   z3c.formui/trunk/src/z3c/formui/README.txt
  A   z3c.formui/trunk/src/z3c/formui/adding.py

-=-
Modified: z3c.formui/trunk/CHANGES.txt
===================================================================
--- z3c.formui/trunk/CHANGES.txt	2008-08-31 05:05:13 UTC (rev 90625)
+++ z3c.formui/trunk/CHANGES.txt	2008-08-31 05:08:26 UTC (rev 90626)
@@ -2,12 +2,14 @@
 CHANGES
 =======
 
-Version 1.4.3dev (unreleased)
------------------------------
+Version 1.5.0 (2008-??-??)
+--------------------------
 
-- Feature: Added CSS for multi-widget which was added in z3c.form version 1.9.1
+- Feature: Added layout support for ``IAdding`` component based add forms.
 
+- Feature: Added CSS for multi-widget which was added in `z3c.form` 2.0.0
 
+
 Version 1.4.2 (2008-08-26)
 --------------------------
 

Modified: z3c.formui/trunk/buildout.cfg
===================================================================
--- z3c.formui/trunk/buildout.cfg	2008-08-31 05:05:13 UTC (rev 90625)
+++ z3c.formui/trunk/buildout.cfg	2008-08-31 05:08:26 UTC (rev 90626)
@@ -1,7 +1,18 @@
 [buildout]
 develop = .
-parts = test
+parts = test coverage-test coverage-report
 
 [test]
 recipe = zc.recipe.testrunner
 eggs = z3c.formui [test]
+
+[coverage-test]
+recipe = zc.recipe.testrunner
+eggs = z3c.formui [test]
+defaults = ['--coverage', '../../coverage']
+
+[coverage-report]
+recipe = zc.recipe.egg
+eggs = z3c.coverage
+scripts = coverage=coverage-report
+arguments = ('coverage', 'coverage/report')

Modified: z3c.formui/trunk/src/z3c/formui/README.txt
===================================================================
--- z3c.formui/trunk/src/z3c/formui/README.txt	2008-08-31 05:05:13 UTC (rev 90625)
+++ z3c.formui/trunk/src/z3c/formui/README.txt	2008-08-31 05:08:26 UTC (rev 90626)
@@ -14,8 +14,8 @@
 -----------------------
 
 One common pattern in Zope 3 user interface development is the use of layout
-templates (see z3c.template). This package provides some mixin classes to the regular form
-classes to support layout-based templating.
+templates (see z3c.template). This package provides some mixin classes to the
+regular form classes to support layout-based templating.
 
   >>> from z3c.form import testing
   >>> testing.setupFormDefaults()
@@ -313,6 +313,162 @@
   </html>
 
 
+`AddForm` rendering for `IAdding`
+---------------------------------
+
+The `z3c.formui` package also provides a layout-aware version of
+`z3c.form.adding.AddForm` which can be used for creating forms for the
+`zope.app.container.interfaces.IAdding` mechanism.
+
+Let's check its template support. First, create the form for an `Adding`
+instance. We just need to define the ``create()`` method, because the default
+``add()`` and ``nextURL()`` methods are already defined using the `Adding`
+object.
+
+  >>> from z3c.formui import adding
+  >>> class AddingPersonAddForm(adding.AddForm):
+  ...
+  ...     fields = field.Fields(IPerson)
+  ...
+  ...     def create(self, data):
+  ...         return Person(**data)
+
+
+Let's now instantiate the adding component and isntantiate the add form:
+
+  >>> from zope.app.container.browser.adding import Adding
+  >>> rootAdding = Adding(root, divRequest)
+
+  >>> addForm = AddingPersonAddForm(rootAdding, divRequest)
+
+First, let's ensure that we can lookup a layout template for the form:
+
+  >>> layout = zope.component.getMultiAdapter(
+  ...     (addForm, divRequest), ILayoutTemplate)
+
+  >>> layout
+  <zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile ...>
+
+Okay, that worked. Let's now render the div-based addform:
+
+  >>> print addForm()
+  <html>
+    <body>
+      <form action="http://127.0.0.1" method="post"
+        enctype="multipart/form-data" class="edit-form"
+        name="form" id="form">
+        <div class="viewspace">
+          <div class="required-info">
+            <span class="required">*</span>
+            &ndash; required
+          </div>
+          <div>
+            <div id="form-widgets-name-row" class="row">
+              <div class="label">
+                <label for="form-widgets-name">
+                  <span>Name</span>
+                  <span class="required">*</span>
+                </label>
+              </div>
+              <div class="widget"><input type="text" id="form-widgets-name"
+                   name="form.widgets.name"
+                   class="text-widget required textline-field" value="" />
+              </div>
+            </div>
+            <div id="form-widgets-age-row" class="row">
+              <div class="label">
+                <label for="form-widgets-age">
+                  <span>Age</span>
+                </label>
+              </div>
+              <div class="widget"><input type="text" id="form-widgets-age"
+                   name="form.widgets.age" class="text-widget int-field"
+                   value="20" />
+              </div>
+            </div>
+          </div>
+        </div>
+        <div>
+          <div class="buttons">
+            <input type="submit" id="form-buttons-add"
+             name="form.buttons.add"
+             class="submit-widget button-field" value="Add" />
+          </div>
+        </div>
+      </form>
+    </body>
+  </html>
+
+Okay, now we are going to check table layout support.
+
+  >>> rootAdding = Adding(root, tableRequest)
+  >>> addForm = AddingPersonAddForm(rootAdding, tableRequest)
+
+Again, the layout should be available:
+
+  >>> layout = zope.component.getMultiAdapter((addForm, tableRequest),
+  ...     ILayoutTemplate)
+
+  >>> layout
+  <zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile ...>
+
+Let's now render the form:
+
+  >>> print addForm()
+  <html>
+    <body>
+      <form action="http://127.0.0.1" method="post"
+        enctype="multipart/form-data" class="edit-form"
+        name="form" id="form">
+        <div class="viewspace">
+          <div class="required-info">
+            <span class="required">*</span>
+            &ndash; required
+          </div>
+          <div>
+          <table class="form-fields">
+                <tr class="row">
+                  <td class="label">
+                    <label for="form-widgets-name">
+                      <span>Name</span>
+                      <span class="required"> * </span>
+                    </label>
+                  </td>
+                  <td class="field">
+                    <div class="widget"><input type="text" id="form-widgets-name"
+                         name="form.widgets.name"
+                         class="text-widget required textline-field" value="" />
+                    </div>
+                  </td>
+                </tr>
+                <tr class="row">
+                  <td class="label">
+                    <label for="form-widgets-age">
+                      <span>Age</span>
+                    </label>
+                  </td>
+                  <td class="field">
+                    <div class="widget"><input type="text" id="form-widgets-age"
+                         name="form.widgets.age" class="text-widget int-field"
+                         value="20" />
+                    </div>
+                  </td>
+                </tr>
+          </table>
+        </div>
+      </div>
+      <div>
+        <div class="buttons">
+          <input type="submit" id="form-buttons-add"
+         name="form.buttons.add"
+         class="submit-widget button-field" value="Add" />
+        </div>
+      </div>
+      </form>
+    </body>
+  </html>
+
+
 Form Macros
 -----------
 
@@ -393,7 +549,8 @@
   [...div-form.pt'), ...define-macro': u'label'...
 
 
-  >>> zope.component.getMultiAdapter(objects, IMacroTemplate, 'form-required-info')
+  >>> zope.component.getMultiAdapter(
+  ...     objects, IMacroTemplate, 'form-required-info')
   [...div-form.pt'), ...define-macro', u'required-info'...
 
 

Added: z3c.formui/trunk/src/z3c/formui/adding.py
===================================================================
--- z3c.formui/trunk/src/z3c/formui/adding.py	                        (rev 0)
+++ z3c.formui/trunk/src/z3c/formui/adding.py	2008-08-31 05:08:26 UTC (rev 90626)
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2008 Zope Foundation 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.
+#
+##############################################################################
+"""Implementation of layout-aware addform for IAdding
+
+$Id:$
+"""
+__docformat__ = "reStructuredText"
+
+from z3c.form import adding
+from z3c.formui import form, layout
+
+class AddForm(form.ContentTemplateMixin, layout.AddFormLayoutSupport,
+              adding.AddForm):
+    """Layout aware add form for zope.app.container.interfaces.IAdding."""


Property changes on: z3c.formui/trunk/src/z3c/formui/adding.py
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the Checkins mailing list