[Checkins] SVN: zope3org/trunk/src/zorg/multiform/ added
namedtemplate for IParentAction
Bernd Dorn
bernd.dorn at fhv.at
Tue Apr 11 04:05:22 EDT 2006
Log message for revision 66829:
added namedtemplate for IParentAction
Changed:
U zope3org/trunk/src/zorg/multiform/configure.zcml
U zope3org/trunk/src/zorg/multiform/gridform.txt
U zope3org/trunk/src/zorg/multiform/multiform.py
-=-
Modified: zope3org/trunk/src/zorg/multiform/configure.zcml
===================================================================
--- zope3org/trunk/src/zorg/multiform/configure.zcml 2006-04-11 07:53:50 UTC (rev 66828)
+++ zope3org/trunk/src/zorg/multiform/configure.zcml 2006-04-11 08:05:21 UTC (rev 66829)
@@ -14,6 +14,9 @@
factory=".selection.FormLocationSelection"
/>
+ <!-- namedtemplate for IParentAction -->
+ <adapter factory=".multiform.render_submit_button" name="render" />
+
<include package=".container"/>
</configure>
\ No newline at end of file
Modified: zope3org/trunk/src/zorg/multiform/gridform.txt
===================================================================
--- zope3org/trunk/src/zorg/multiform/gridform.txt 2006-04-11 07:53:50 UTC (rev 66828)
+++ zope3org/trunk/src/zorg/multiform/gridform.txt 2006-04-11 08:05:21 UTC (rev 66829)
@@ -126,6 +126,8 @@
>>> print gf.subActionNames
[u'form.actions.edit']
+ >>> [a.__name__ for a in gf.availableSubActions()]
+ [u'actions.edit']
Now we are going to select some items. And the checkbox of the ``selected``
@@ -177,7 +179,7 @@
>>> res = gf()
>>> sorted([action.__name__ for action in
... gf.subForms['n1'].availableActions()])
- [u'form.actions.edit', u'form.n1.actions.singleedit']
+ [u'form.n1.actions.singleedit']
We call the singleedit to edit a single row.
Modified: zope3org/trunk/src/zorg/multiform/multiform.py
===================================================================
--- zope3org/trunk/src/zorg/multiform/multiform.py 2006-04-11 07:53:50 UTC (rev 66828)
+++ zope3org/trunk/src/zorg/multiform/multiform.py 2006-04-11 08:05:21 UTC (rev 66829)
@@ -9,7 +9,8 @@
from interfaces import IMultiForm, IParentAction, IItemAction, ISelection
from interfaces import IFormLocation,IItemForm
import copy
-
+from zope.formlib import namedtemplate
+import zope.i18n
from zope import interface
@@ -71,6 +72,20 @@
res = self.__name__ in self.form.request
return res
+ at namedtemplate.implementation(IParentAction)
+def render_submit_button(self):
+ if IBoundAction.providedBy(self) and not self.available():
+ return ''
+ label = self.label
+ if isinstance(label, (zope.i18n.Message, zope.i18n.MessageID)):
+ label = zope.i18n.translate(self.label, context=self.form.request)
+ return ('<input type="submit" id="%s" name="%s" value="%s"'
+ ' class="button" />' %
+ (self.__name__, self.__name__, label)
+ )
+
+
+
class itemAction(form.action):
def __call__(self, success):
@@ -106,16 +121,22 @@
def update(self):
super(ItemFormBase,self).update()
+
+ def availableActions(self):
+ # we need to override this, because we should not return the
+ # parentActions
+ if not hasattr(self,'actions'):
+ return []
+ actions = [action for action in self.actions
+ if not IParentAction.providedBy(action)]
+ return form.availableActions(self, actions)
def availableParentActions(self):
- actions=[]
- if hasattr(self,'actions'):
- for action in self.actions:
- if IParentAction.providedBy(action):
- actions.append(action)
-
- actions= form.availableActions(self, actions)
- return actions
+ if not hasattr(self,'actions'):
+ return []
+ actions = [action for action in self.actions
+ if IParentAction.providedBy(action)]
+ return form.availableActions(self, actions)
class MultiFormBase(form.FormBase):
@@ -236,7 +257,13 @@
return self.itemFormFactory(item,self.request,self)
-
+ def availableSubActions(self):
+ for name in self.subActionNames:
+ # remove the prefix of our form because, the actions in
+ # the class variable have no prefix in their name
+ name = name[len(self.prefix)+1:]
+ yield self.itemFormFactory.actions.byname[name]
+
class SelectionForm(form.FormBase):
def __init__(self, context, request, form_fields):
More information about the Checkins
mailing list