[Checkins] SVN: z3ext.layoutform/trunk/ Use SelectionManager for form subforms, groups, view
Nikolay Kim
fafhrd91 at gmail.com
Fri May 22 07:47:25 EDT 2009
Log message for revision 100226:
Use SelectionManager for form subforms,groups,view
Changed:
U z3ext.layoutform/trunk/CHANGES.txt
U z3ext.layoutform/trunk/src/z3ext/layoutform/form.py
U z3ext.layoutform/trunk/src/z3ext/layoutform/interfaces.py
U z3ext.layoutform/trunk/src/z3ext/layoutform/tests/form.txt
-=-
Modified: z3ext.layoutform/trunk/CHANGES.txt
===================================================================
--- z3ext.layoutform/trunk/CHANGES.txt 2009-05-22 09:59:23 UTC (rev 100225)
+++ z3ext.layoutform/trunk/CHANGES.txt 2009-05-22 11:47:25 UTC (rev 100226)
@@ -3,9 +3,12 @@
=======
-- Convert 'forms','groups','subforms','views' to tuple
+1.4.0 (2009-05-22)
+------------------
+- Use SelectionManager for form subforms,groups,view
+
1.3.5 (2009-04-15)
------------------
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/form.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/form.py 2009-05-22 09:59:23 UTC (rev 100225)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/form.py 2009-05-22 11:47:25 UTC (rev 100226)
@@ -20,18 +20,33 @@
from zope.component import getMultiAdapter, queryMultiAdapter
from zope.pagetemplate.interfaces import IPageTemplate
-from z3c.form import form
+from z3c.form import form, util
from z3c.form.interfaces import IForm, IGroup, ISubForm
from z3ext.layout.interfaces import IPagelet
from z3ext.layout.pagelet import BrowserPagelet
from interfaces import _
-from interfaces import IFormWrapper
+from interfaces import IFormWrapper, IForms
from interfaces import IPageletForm, IPageletSubform
from interfaces import IPageletDisplayForm, IPageletFormView
+class Views(util.SelectionManager):
+ """Forms manager."""
+ interface.implements(IForms)
+ managerInterface = IForms
+
+ def __init__(self, *args, **kw):
+ super(Views, self).__init__()
+ for view in args:
+ self._data_values.append(view)
+ self._data_keys.append(view.__name__)
+ self._data[view.__name__] = view
+
+ def __iter__(self):
+ return iter(self._data_values)
+
class PageletBaseForm(form.BaseForm, BrowserPagelet):
__call__ = BrowserPagelet.__call__
@@ -80,7 +95,7 @@
return data, errors
def _loadSubforms(self):
- return [form for name, form in
+ return [(name, form) for name, form in
getAdapters((self.context, self, self.request), IPageletSubform)]
def updateForms(self):
@@ -90,7 +105,8 @@
groups = []
subforms = []
views = []
- for form in self._loadSubforms():
+ for name, form in self._loadSubforms():
+ form.__name__ = name
form.update()
if not form.isAvailable():
continue
@@ -107,16 +123,16 @@
views.append((form.weight, form.__name__, form))
groups.sort()
- self.groups = tuple([form for weight, name, form in groups])
+ self.groups = Views(*[form for weight, name, form in groups])
subforms.sort()
- self.subforms = tuple([form for weight, name, form in subforms])
+ self.subforms = Views(*[form for weight, name, form in subforms])
forms.sort()
- self.forms = tuple([form for weight, name, form in forms])
+ self.forms = Views(*[form for weight, name, form in forms])
views.sort()
- self.views = tuple([view for weight, name, view in views])
+ self.views = Views(*[view for weight, name, view in views])
def update(self):
self.updateWidgets()
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/interfaces.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/interfaces.py 2009-05-22 09:59:23 UTC (rev 100225)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/interfaces.py 2009-05-22 11:47:25 UTC (rev 100226)
@@ -17,7 +17,7 @@
"""
from zope import interface, schema
from zope.i18nmessageid import MessageFactory
-from z3c.form.interfaces import IFormLayer
+from z3c.form.interfaces import IFormLayer, ISelectionManager
from z3ext.layout.interfaces import IPagelet
_ = MessageFactory('z3ext.layoutform')
@@ -127,3 +127,6 @@
class IFormWrapper(interface.Interface):
""" """
+
+class IForms(ISelectionManager):
+ """ Forms manager """
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/tests/form.txt
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/tests/form.txt 2009-05-22 09:59:23 UTC (rev 100225)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/tests/form.txt 2009-05-22 11:47:25 UTC (rev 100226)
@@ -29,7 +29,7 @@
...
... ignoreContext = True
... fields = Fields(IPerson)
- ...
+ ...
... @button.buttonAndHandler(u'Save', name='save',
... provides=interfaces.ISaveAction)
... def handleSave(self, action):
@@ -99,21 +99,21 @@
>>> class PersonEducation(group.Group):
... interface.implements(interfaces.IPageletSubform)
- ...
+ ...
... weight = 10
... fields = Fields(IPersonEducation)
... ignoreContext = True
- ...
+ ...
... def __init__(self, context, form, request):
... super(PersonEducation, self).__init__(context, request, form)
- ...
+ ...
... def isAvailable(self):
... return True
- ...
+ ...
... def postUpdate(self):
... pass
- >>> form.groups
+ >>> tuple(form.groups)
()
>>> component.getSiteManager().registerAdapter(
@@ -122,7 +122,7 @@
>>> form.update()
- >>> print form.groups
+ >>> print tuple(form.groups)
(<PersonEducation ...>,)
>>> print form.render()
@@ -181,15 +181,15 @@
>>> class PersonInfo(subform.PageletEditSubForm):
... interface.implements(interfaces.IPageletSubform)
- ...
+ ...
... weight = 10
... fields = Fields(IPersonInfo)
... ignoreContext = True
- ...
+ ...
... def getContent(self):
... return {}
- >>> form.subforms
+ >>> tuple(form.subforms)
()
>>> component.getSiteManager().registerAdapter(
@@ -198,7 +198,7 @@
>>> form.update()
- >>> print form.subforms
+ >>> print tuple(form.subforms)
(<PersonInfo ...>,)
>>> print form.render()
@@ -266,7 +266,7 @@
>>> class IItem(interface.Interface):
- ...
+ ...
... title = schema.TextLine(
... title = u'Title',
... required = True)
@@ -293,6 +293,10 @@
>>> form = PersonForm(root, request)
>>> form.update()
- >>> form.forms
+ >>> tuple(form.forms)
(<ItemForm object ...>,)
+We can get forms, subforms, groups by name
+
+ >>> form.forms['item']
+ <ItemForm object ...>
More information about the Checkins
mailing list