[Checkins] SVN: plone.z3cform/trunk/ Improve tests. Remove demo package that shouldn't really have been checked in.

Martin Aspeli optilude at gmx.net
Tue Feb 16 10:46:49 EST 2010


Log message for revision 109077:
  Improve tests. Remove demo package that shouldn't really have been checked in.

Changed:
  U   plone.z3cform/trunk/README.txt
  U   plone.z3cform/trunk/plone/z3cform/configure.zcml
  D   plone.z3cform/trunk/plone/z3cform/demo/
  A   plone.z3cform/trunk/plone/z3cform/inputs.txt
  U   plone.z3cform/trunk/plone/z3cform/layout.txt
  U   plone.z3cform/trunk/plone/z3cform/tests.py
  U   plone.z3cform/trunk/plone/z3cform/traversal.txt

-=-
Modified: plone.z3cform/trunk/README.txt
===================================================================
--- plone.z3cform/trunk/README.txt	2010-02-16 03:10:25 UTC (rev 109076)
+++ plone.z3cform/trunk/README.txt	2010-02-16 15:46:48 UTC (rev 109077)
@@ -3,8 +3,33 @@
 =============
 
 plone.z3cform is a library that allows use of `z3c.form`_ with Zope 2
-and the CMF_.
+and the CMF_. For Plone integration, there is also `plone.app.z3cform`_.
 
+Layout form wrapper
+-------------------
+
+
+Standalone forms
+----------------
+
+
+Default templates and macros
+----------------------------
+
+
+The widget traverser
+--------------------
+
+
+Extensible forms and fieldsets
+------------------------------
+
+
+CRUD forms
+----------
+
+
 .. _z3c.form: http://pypi.python.org/pypi/z3c.form
+.. _plone.app.z3cform: http://pypi.python.org/pypi/plone.app.z3cform
 .. _CMF: http://www.zope.org/Products/CMF
 

Modified: plone.z3cform/trunk/plone/z3cform/configure.zcml
===================================================================
--- plone.z3cform/trunk/plone/z3cform/configure.zcml	2010-02-16 03:10:25 UTC (rev 109076)
+++ plone.z3cform/trunk/plone/z3cform/configure.zcml	2010-02-16 15:46:48 UTC (rev 109077)
@@ -14,9 +14,6 @@
 
   <i18n:registerTranslations directory="locales"/>
   
-  <!-- TODO: Remove -->
-  <include package=".demo" />
-  
   <!-- Monkey patch BaseForm/GroupForm's update() to apply Zope 2 input
        parameter processing. Without this, we'll get errors because Zope is
        sending encoded str's when z3c.form wants decoded unicode's.

Added: plone.z3cform/trunk/plone/z3cform/inputs.txt
===================================================================
--- plone.z3cform/trunk/plone/z3cform/inputs.txt	                        (rev 0)
+++ plone.z3cform/trunk/plone/z3cform/inputs.txt	2010-02-16 15:46:48 UTC (rev 109077)
@@ -0,0 +1,87 @@
+Input parameter processing
+==========================
+
+z3c.form expects the inputs from the request to be decoded from byte strings
+to unicode strings. This package ensures that this happens in Zope 2.
+
+First, we'll create a request.
+
+    >>> from zope.interface import alsoProvides
+    >>> from zope.publisher.browser import TestRequest
+    >>> from zope.annotation.interfaces import IAttributeAnnotatable
+    >>> from z3c.form.interfaces import IFormLayer
+
+    >>> def make_request(form={}):
+    ...     request = TestRequest()
+    ...     request.form.update(form)
+    ...     alsoProvides(request, IFormLayer)
+    ...     alsoProvides(request, IAttributeAnnotatable)
+    ...     return request
+
+Then we create and register a simple form that expects unicode text input:
+
+    >>> from zope import interface, schema
+    >>> from z3c.form import form, field, button
+    >>> from plone.z3cform.layout import FormWrapper
+
+    >>> class MySchema(interface.Interface):
+    ...     text = schema.TextLine(title=u"Text")
+
+    >>> from z3c.form.interfaces import IFieldsForm
+    >>> from zope.interface import implements
+
+    >>> class MyForm(form.Form):
+    ...     implements(IFieldsForm)
+    ...     fields = field.Fields(MySchema)
+    ...     ignoreContext = True # don't use context to get widget data
+    ...
+    ...     @button.buttonAndHandler(u'Apply')
+    ...     def handleApply(self, action):
+    ...         data, errors = self.extractData()
+    ...         print repr(data['text'])
+
+    >>> from zope.component import provideAdapter
+    >>> from zope.publisher.interfaces.browser import IBrowserRequest
+    >>> from zope.interface import Interface
+
+    >>> provideAdapter(adapts=(Interface, IBrowserRequest),
+    ...                provides=Interface,
+    ...                factory=MyForm,
+    ...                name=u"test-form")
+
+For our context, we define a class that inherits from Acquisition.
+
+    >>> from Acquisition import Implicit
+    >>> class Bar(Implicit):
+    ...     __allow_access_to_unprotected_subobjects__ = 1
+    ...     implements(Interface)
+
+Let's now look this up with some form data that is not encoded:
+
+    >>> from zope.interface import Interface, implements
+    >>> from zope.component import getMultiAdapter
+    
+    >>> context = Bar()
+    >>> request = make_request(form={'form.widgets.text': 'foo'})
+
+    >>> testForm = getMultiAdapter((context, request), name=u"test-form")
+    >>> testForm.update()
+    >>> data, errors = testForm.extractData()
+    >>> data
+    {'text': u'foo'}
+    >>> errors
+    ()
+
+Let's now try with some encoded data. The default encoding is utf-8.
+
+    >>> context = Bar()
+    >>> request = make_request(form={'form.widgets.text': 'fo\xc3\xb8'})
+
+    >>> testForm = getMultiAdapter((context, request), name=u"test-form")
+    >>> testForm.update()
+    >>> data, errors = testForm.extractData()
+    >>> data
+    {'text': u'fo\xf8'}
+    >>> errors
+    ()
+

Modified: plone.z3cform/trunk/plone/z3cform/layout.txt
===================================================================
--- plone.z3cform/trunk/plone/z3cform/layout.txt	2010-02-16 03:10:25 UTC (rev 109076)
+++ plone.z3cform/trunk/plone/z3cform/layout.txt	2010-02-16 15:46:48 UTC (rev 109077)
@@ -1,15 +1,24 @@
-Layout
-======
+Layout form wrapper
+===================
 
-plone.z3cform tries to avoid mixing Acqusition into your forms.  Also,
-it tries to separate form templates from layout templates (aka main
-template), so that your forms are usable in different contexts,
-e.g. in viewlets.
+Layout wrapper views are used for two purposes:
 
-Use the ``wrap_form`` function defined in the ``layout`` module to
-create a view that's suitable for registration with a ``browser:page``
-directive.
+* To avoid having to mix Zope2-isms into form classes in Zope 2.11 and
+  earlier. (In Zope 2.12, the changes to the acquisition mechanism means that
+  standard z3c.form forms can be used directly without having to mix in
+  acquisition anyway)
+* To avoid separate form templates from layout templates (aka the main
+  template), to allow a single form to be usable in different contexts,
+  e.g. as a standalone form or a viwelet.
 
+If you are using Zope 2.12 or later, you don't need to use the wrapper view
+if you don't want to, so long as you have loaded the plone.z3cform
+configuration.
+
+To use the wrapper, you can call the ``wrap_form`` function defined in the
+``layout`` module to create a view that's suitable for registration with a
+``browser:page`` directive.
+
     >>> from zope.interface import alsoProvides
     >>> from zope.publisher.browser import TestRequest
     >>> from zope.annotation.interfaces import IAttributeAnnotatable
@@ -22,7 +31,7 @@
     ...     alsoProvides(request, IAttributeAnnotatable)
     ...     return request
 
-Then we create a simple z3c form:
+Then we create a simple form:
 
     >>> from zope import interface, schema
     >>> from z3c.form import form, field, button
@@ -122,8 +131,8 @@
     >>> view = view_class(context, request).__of__(context)
     >>> print view() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
     <html>Hello, this is your layout speaking:...Another label...Age...</html>
-    
 
+
 Send bad data to the form:
 
     >>> request = make_request(form={'form.widgets.age': '12.1'})
@@ -173,4 +182,4 @@
 
 Clean up:
 
-    >>> os.unlink(path)
\ No newline at end of file
+    >>> os.unlink(path)

Modified: plone.z3cform/trunk/plone/z3cform/tests.py
===================================================================
--- plone.z3cform/trunk/plone/z3cform/tests.py	2010-02-16 03:10:25 UTC (rev 109076)
+++ plone.z3cform/trunk/plone/z3cform/tests.py	2010-02-16 15:46:48 UTC (rev 109077)
@@ -26,6 +26,7 @@
 def setup_defaults():
     # Set up z3c.form defaults
     z3c.form.testing.setupFormDefaults()
+    
     # Make traversal work; register both the default traversable
     # adapter and the ++view++ namespace adapter
     component.provideAdapter(
@@ -33,8 +34,7 @@
     component.provideAdapter(
         zope.traversing.namespace.view, (None, None), name='view')
 
-    # Setup ploneform macros
-    
+    # Setup ploneform macros, simlulating the ZCML directive
     plone.z3cform.templates.Macros.index = ViewPageTemplateFile(plone.z3cform.templates.path('macros.pt'))
     
     component.provideAdapter(
@@ -42,7 +42,8 @@
         (None, None),
         zope.publisher.interfaces.browser.IBrowserView,
         name='ploneform-macros')
-    # setup plone.z3cform template
+    
+    # setup plone.z3cform templates
     from zope.pagetemplate.interfaces import IPageTemplate
 
     component.provideAdapter(
@@ -63,6 +64,9 @@
     layout_txt = doctest.DocFileSuite('layout.txt')
     layout_txt.layer = testing_zcml_layer
     
+    inputs_txt = doctest.DocFileSuite('inputs.txt')
+    inputs_txt.layer = testing_zcml_layer
+    
     fieldsets_txt = doctest.DocFileSuite('fieldsets/README.txt')
     fieldsets_txt.layer = testing_zcml_layer
     
@@ -70,7 +74,7 @@
     traversal_txt.layer = testing_zcml_layer
     
     return unittest.TestSuite([
-        layout_txt, fieldsets_txt, traversal_txt,
+        layout_txt, inputs_txt, fieldsets_txt, traversal_txt,
 
         doctest.DocFileSuite(
            'README.txt',

Modified: plone.z3cform/trunk/plone/z3cform/traversal.txt
===================================================================
--- plone.z3cform/trunk/plone/z3cform/traversal.txt	2010-02-16 03:10:25 UTC (rev 109076)
+++ plone.z3cform/trunk/plone/z3cform/traversal.txt	2010-02-16 15:46:48 UTC (rev 109077)
@@ -2,7 +2,7 @@
 =========
 
 plone.z3cform allows you to traverse to a widget using the ++widget++
-namespace adapter on a form view.
+namespace adapter on a form wrapper view or standalone form view.
 
 Note that widgets may need to mix in Acquisition.Explicit to be truly
 traversable in Zope 2.10. In Zope 2.12, that is not required. However, you



More information about the checkins mailing list