[Checkins] SVN: zope3org/trunk/src/zorg/multiform/ added gridform and selection stuff

Bernd Dorn bernd.dorn at fhv.at
Mon Apr 10 08:21:02 EDT 2006


Log message for revision 66774:
  added gridform and selection stuff

Changed:
  U   zope3org/trunk/src/zorg/multiform/README.txt
  U   zope3org/trunk/src/zorg/multiform/actions.txt
  U   zope3org/trunk/src/zorg/multiform/configure.zcml
  U   zope3org/trunk/src/zorg/multiform/interfaces.py
  U   zope3org/trunk/src/zorg/multiform/multiform.py
  U   zope3org/trunk/src/zorg/multiform/tests.py

-=-
Modified: zope3org/trunk/src/zorg/multiform/README.txt
===================================================================
--- zope3org/trunk/src/zorg/multiform/README.txt	2006-04-10 12:02:04 UTC (rev 66773)
+++ zope3org/trunk/src/zorg/multiform/README.txt	2006-04-10 12:21:01 UTC (rev 66774)
@@ -7,15 +7,17 @@
 from the Form class of the formlib package.
 
     >>> from zope import interface, schema
+    >>> from zope.app.location.interfaces import ILocation
     >>> class IOrder(interface.Interface):
     ...     identifier = schema.Int(title=u"Identifier", readonly=True)
     ...     name = schema.TextLine(title=u"Name")
     >>> class Order:
-    ...     interface.implements(IOrder)
+    ...     interface.implements(IOrder,ILocation)
     ...
     ...     def __init__(self, identifier, name=''):
     ...         self.identifier = identifier
     ...         self.name = name
+    ...         self.__name__ = name
 
     >>> orderMapping = dict([(str(k),Order(k,name='n%s'%k)) for k in range(5)])
 

Modified: zope3org/trunk/src/zorg/multiform/actions.txt
===================================================================
--- zope3org/trunk/src/zorg/multiform/actions.txt	2006-04-10 12:02:04 UTC (rev 66773)
+++ zope3org/trunk/src/zorg/multiform/actions.txt	2006-04-10 12:21:01 UTC (rev 66774)
@@ -17,15 +17,17 @@
     >>> from multiform import multiform
     >>> from zope.publisher.browser import TestRequest
     >>> from zope import interface, schema
+    >>> from zope.app.location.interfaces import ILocation
     >>> class IOrder(interface.Interface):
     ...     identifier = schema.Int(title=u"Identifier", readonly=True)
     ...     name = schema.TextLine(title=u"Name")
     >>> class Order:
-    ...     interface.implements(IOrder)
+    ...     interface.implements(IOrder,ILocation)
     ...
     ...     def __init__(self, identifier, name=''):
     ...         self.identifier = identifier
     ...         self.name = name
+    ...         self.__name__= name
 
     >>> orderMapping = dict([(str(k),Order(k,name='n%s'%k)) for k in range(2)])
 
@@ -168,3 +170,19 @@
     <div>1</div><div>newer name 1</div>
     </div>
 
+Now let us call the upper action, which should uppercase the name
+attributes of the items. This action is an action on the items itself,
+so we have a unique prefix with the key of the item in the parent
+mapping.
+
+    >>> request = TestRequest()
+    >>> request.form['form.1.actions.upper']=u''
+    >>> pf =  OrdersForm(orderMapping,request)
+    >>> result = pf()
+    >>> print result
+    <div>
+    <div>0</div><div>newer name 0</div>
+    </div>
+    <div>
+    <div>1</div><div>NEWER NAME 1</div>
+    </div>

Modified: zope3org/trunk/src/zorg/multiform/configure.zcml
===================================================================
--- zope3org/trunk/src/zorg/multiform/configure.zcml	2006-04-10 12:02:04 UTC (rev 66773)
+++ zope3org/trunk/src/zorg/multiform/configure.zcml	2006-04-10 12:21:01 UTC (rev 66774)
@@ -2,5 +2,9 @@
 <configure xmlns="http://namespaces.zope.org/zope"
            xmlns:i18n="http://namespaces.zope.org/i18n"
            i18n_domain="zope">
+
+ <adapter for="zope.app.location.interfaces.ILocation"
+          provides=".interfaces.ISelection"
+          factory=".gridform.LocationSelection"/>
  
 </configure>
\ No newline at end of file

Modified: zope3org/trunk/src/zorg/multiform/interfaces.py
===================================================================
--- zope3org/trunk/src/zorg/multiform/interfaces.py	2006-04-10 12:02:04 UTC (rev 66773)
+++ zope3org/trunk/src/zorg/multiform/interfaces.py	2006-04-10 12:21:01 UTC (rev 66774)
@@ -1,12 +1,34 @@
-from zope.interface import Interface
+from zope.interface import Interface,Attribute
 from zope.formlib.interfaces import IAction
+from zope import schema
+from zope.formlib.i18n import _
 
 class IMultiForm(Interface):
 
     """multiform"""
 
+class IItemForm(Interface):
 
+    """a sub form for an item of a multiform"""
+
+class IGridItemForm(IItemForm):
+
+    """an form for an item of a grid form"""
+
+class IGridForm(IMultiForm):
+
+    """a special grid multiform"""
+
 class IParentAction(IAction):
     """a parent action"""
 
 
+class ISelection(Interface):
+
+    """Provides information about the selection state of an object"""
+
+    selected = schema.Bool(title=_(u'Selected'),default=False)
+
+class IFormLocation(Interface):
+
+    __form_name__ = Attribute('The unique name of the item in a multiform')

Modified: zope3org/trunk/src/zorg/multiform/multiform.py
===================================================================
--- zope3org/trunk/src/zorg/multiform/multiform.py	2006-04-10 12:02:04 UTC (rev 66773)
+++ zope3org/trunk/src/zorg/multiform/multiform.py	2006-04-10 12:21:01 UTC (rev 66774)
@@ -2,11 +2,11 @@
 from zope.interface import implements
 from zope.app import zapi
 from zope.app.form.browser.interfaces import IWidgetInputErrorView
-
+from zope.component import getMultiAdapter
 from zope.formlib import form
 from zope.formlib.interfaces import IBoundAction
 from zope.formlib.i18n import _
-from interfaces import IMultiForm, IParentAction
+from interfaces import IMultiForm, IParentAction, IFormLocation,IItemForm
 from zope import interface
         
 
@@ -16,11 +16,12 @@
 def isFormInputMode(f,action):
     return f.inputMode
 
+def isParentFormDisplayMode(f,action):
+    return not f.parentForm.inputMode
+
 def isParentFormInputMode(f,action):
     return f.parentForm.inputMode
 
-
-
 class ParentAction(form.Action):
 
     """an action that is rendered in the parent multiform object and
@@ -61,11 +62,15 @@
 
 class ItemFormBase(form.FormBase):
 
+
+    implements(IItemForm)
+    forceInput = []
     parentForm = None
     inputMode = None
 
     def __init__(self,context,request,parentForm):
-        super(ItemFormBase,self).__init__(context,request)
+        self.request=request
+        self.context = getMultiAdapter([context,self],IFormLocation)
         self.parentForm=parentForm
 
     def update(self):
@@ -81,12 +86,9 @@
         actions= form.availableActions(self, actions)
         return actions
 
-
-
-
 class MultiFormBase(form.FormBase):
 
-
+    implements(IMultiForm)
     itemFormFactory = ItemFormBase
     subForms={}
     form_fields = []
@@ -121,9 +123,9 @@
             prefix = (self.prefix and self.prefix+'.' or '') + name
             subForm = self.itemFormFactory(item,self.request,self)
             if self.inputMode is not None and not self.inputMode:
-                forceInputs = getattr(self.itemFormFactory,'forceInputs',[])
+                forceInput = self.itemFormFactory.forceInput
                 for field in subForm.form_fields:
-                    if field.__name__ not in forceInputs:
+                    if field.__name__ not in forceInput:
                         field.for_display=True
             subForm.setPrefix(prefix)
             subForm.setUpWidgets(*args, **kw)
@@ -162,8 +164,8 @@
     def checkInputMode(self):
         for action in self.itemFormFactory.actions:
             name = '%s.%s' % (self.prefix,action.__name__)
-            if name in self.request.form and action.inputMode \
-               is not None:
+            if name in self.request.form and getattr(action,
+                                'inputMode', None) is not None:
                 self.setInputMode(action.inputMode)
             
                 

Modified: zope3org/trunk/src/zorg/multiform/tests.py
===================================================================
--- zope3org/trunk/src/zorg/multiform/tests.py	2006-04-10 12:02:04 UTC (rev 66773)
+++ zope3org/trunk/src/zorg/multiform/tests.py	2006-04-10 12:21:01 UTC (rev 66774)
@@ -7,6 +7,10 @@
 import zope.app.form.browser
 import zope.publisher.interfaces.browser
 import zope.app.form.interfaces
+import interfaces
+import gridform
+
+
 def setUp(test):
     setup.placefulSetUp()
 
@@ -25,6 +29,20 @@
         zope.app.form.interfaces.IDisplayWidget,
         )
     component.provideAdapter(
+        zope.app.form.browser.boolwidgets.BooleanDisplayWidget,
+        [zope.schema.interfaces.IBool,
+         zope.publisher.interfaces.browser.IBrowserRequest,
+         ],
+        zope.app.form.interfaces.IDisplayWidget,
+        )
+    component.provideAdapter(
+        zope.app.form.browser.CheckBoxWidget,
+        [zope.schema.interfaces.IBool,
+         zope.publisher.interfaces.browser.IBrowserRequest,
+         ],
+        zope.app.form.interfaces.IInputWidget,
+        )
+    component.provideAdapter(
         zope.app.form.browser.UnicodeDisplayWidget,
         [zope.schema.interfaces.IInt,
          zope.publisher.interfaces.browser.IBrowserRequest,
@@ -38,8 +56,23 @@
          ],
         zope.app.form.interfaces.IInputWidget,
         )
-
+    component.provideAdapter(
+        gridform.FormLocationProxy,
+        [zope.app.location.interfaces.ILocation,
+         zope.formlib.interfaces.IForm
+         ],
+        interfaces.IFormLocation
+        )
+    component.provideAdapter(
+        gridform.FormLocationSelection,
+        [interfaces.IFormLocation],
+        interfaces.ISelection
+        )
     
+    component.provideAdapter(gridform.default_grid_template,
+                             name="default")
+    component.provideAdapter(gridform.default_griditem_template,
+                             name="default")
 
 def tearDown(test):
     setup.placefulTearDown()
@@ -49,6 +82,9 @@
     
     return unittest.TestSuite(
         (
+        DocTestSuite('multiform.gridform',
+                     optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+                     ),
         DocFileSuite('README.txt',
                      setUp=setUp, tearDown=tearDown,
                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
@@ -57,6 +93,10 @@
                      setUp=setUp, tearDown=tearDown,
                      optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
                      ),
+        DocFileSuite('gridform.txt',
+                     setUp=setUp, tearDown=tearDown,
+                     optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+                     ),
         ))
 
 



More information about the Checkins mailing list