[Checkins] SVN: z3ext.layoutform/trunk/ more managed forms related code
Nikolay Kim
fafhrd at datacom.kz
Fri Dec 12 05:38:50 EST 2008
Log message for revision 93934:
more managed forms related code
Changed:
U z3ext.layoutform/trunk/CHANGES.txt
U z3ext.layoutform/trunk/src/z3ext/layoutform/add.py
U z3ext.layoutform/trunk/src/z3ext/layoutform/browser/configure.zcml
U z3ext.layoutform/trunk/src/z3ext/layoutform/browser/form.pt
U z3ext.layoutform/trunk/src/z3ext/layoutform/browser/formbuttons.pt
U z3ext.layoutform/trunk/src/z3ext/layoutform/browser/formviewspace.pt
U z3ext.layoutform/trunk/src/z3ext/layoutform/browser/subform.pt
U z3ext.layoutform/trunk/src/z3ext/layoutform/browser/textarea.py
U z3ext.layoutform/trunk/src/z3ext/layoutform/edit.py
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/subform.py
-=-
Modified: z3ext.layoutform/trunk/CHANGES.txt
===================================================================
--- z3ext.layoutform/trunk/CHANGES.txt 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/CHANGES.txt 2008-12-12 10:38:50 UTC (rev 93934)
@@ -5,7 +5,7 @@
1.3.0 (Unreleased)
------------------
-- Added subforms
+- Added subforms concept based on new z3ext.layout pagelet manager api
- Fixed 'formError' status message
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/add.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/add.py 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/add.py 2008-12-12 10:38:50 UTC (rev 93934)
@@ -30,11 +30,11 @@
from zope.proxy import removeAllProxies
-class PageletAddForm(form.AddForm, PageletForm):
+class PageletAddForm(PageletForm, form.AddForm):
interface.implements(IPageletAddForm)
- render = PageletForm.render
- __call__ = PageletForm.__call__
+ ignoreContext = True
+ ignoreReadonly = True
_addedObject = None
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/browser/configure.zcml
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/browser/configure.zcml 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/browser/configure.zcml 2008-12-12 10:38:50 UTC (rev 93934)
@@ -55,7 +55,7 @@
<z3ext:pagelet
template="subform.pt"
- for="..interfaces.IPageletEditSubForm"
+ for="z3c.form.interfaces.ISubForm"
layer="..interfaces.ILayoutFormLayer"
provides="..interfaces.IPageletFormView"
permission="zope.Public" />
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/browser/form.pt
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/browser/form.pt 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/browser/form.pt 2008-12-12 10:38:50 UTC (rev 93934)
@@ -1,3 +1,6 @@
<div class="z-form z-form-standard"
tal:content="structure context/@@pagelet/layoutform.form">
</div>
+
+<tal:block tal:repeat="form context/forms"
+ tal:content="structure form/@@pagelet/layoutform.form" />
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/browser/formbuttons.pt
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/browser/formbuttons.pt 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/browser/formbuttons.pt 2008-12-12 10:38:50 UTC (rev 93934)
@@ -1,4 +1,4 @@
-<div class="z-form-controls" tal:condition="context/actions">
+<div class="z-form-controls" tal:condition="context/actions|nothing">
<tal:block tal:content="structure
context/@@pagelet/layoutform.buttonsInfo|nothing" />
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/browser/formviewspace.pt
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/browser/formviewspace.pt 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/browser/formviewspace.pt 2008-12-12 10:38:50 UTC (rev 93934)
@@ -1,8 +1,7 @@
-<h1 tal:condition="context/label|nothing"
- tal:content="context/label|nothing">Do something</h1>
-<div class="z-form-description"
- tal:condition="context/description|nothing"
- tal:content="context/description|nothing"></div>
+<h1 class="z-form-label"
+ tal:condition="context/label" tal:content="context/label">Do something</h1>
+<div class="z-form-description"
+ tal:condition="context/description" tal:content="context/description"></div>
<tal:block tal:content="structure
context/@@pagelet/layoutform.viewspaceInfo|nothing" />
@@ -11,3 +10,11 @@
<tal:block tal:repeat="widget context/widgets/values"
tal:content="structure widget/@@pagelet/layoutform.widget" />
</div>
+
+<tal:block tal:condition="context/groups|nothing"
+ tal:repeat="form context/groups"
+ tal:content="structure form/@@pagelet/form" />
+
+<tal:block tal:condition="context/subforms|nothing"
+ tal:repeat="form context/subforms"
+ tal:content="structure form/@@pagelet/form" />
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/browser/subform.pt
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/browser/subform.pt 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/browser/subform.pt 2008-12-12 10:38:50 UTC (rev 93934)
@@ -1,10 +1,10 @@
+==============================
<div class="z-form-fieldset">
- <h1 tal:condition="context/label|nothing"
- tal:content="context/label|nothing">Do something</h1>
- <div class="z-form-description"
- tal:content="context/description|nothing"></div>
+ <h1 class="z-form-label"
+ tal:condition="context/label" tal:content="context/label">Do something</h1>
+ <div class="z-form-description"
+ tal:condition="context/description" tal:content="context/description"></div>
<tal:block tal:repeat="widget context/widgets/values"
tal:content="structure widget/@@pagelet/layoutform.widget" />
</div>
-=========
\ No newline at end of file
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/browser/textarea.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/browser/textarea.py 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/browser/textarea.py 2008-12-12 10:38:50 UTC (rev 93934)
@@ -28,7 +28,7 @@
class TextAreaWidget(textarea.TextAreaWidget):
"""Textarea widget implementation."""
- rows = 7
+ rows = 6
@component.adapter(schema.interfaces.IField, ILayoutFormLayer)
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/edit.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/edit.py 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/edit.py 2008-12-12 10:38:50 UTC (rev 93934)
@@ -28,12 +28,9 @@
from interfaces import _, IPageletEditForm, ISaveButton
-class PageletEditForm(form.EditForm, PageletForm):
+class PageletEditForm(PageletForm, form.EditForm):
interface.implements(IPageletEditForm)
- render = PageletForm.render
- __call__ = PageletForm.__call__
-
@button.buttonAndHandler(
_(u'Save'), name='save', provides=ISaveButton)
def handleApply(self, action):
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/form.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/form.py 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/form.py 2008-12-12 10:38:50 UTC (rev 93934)
@@ -21,7 +21,7 @@
from zope.pagetemplate.interfaces import IPageTemplate
from z3c.form import form
-from z3c.form.interfaces import IGroup
+from z3c.form.interfaces import IGroup, ISubForm
from z3ext.layout.interfaces import IPagelet
from z3ext.layout.pagelet import BrowserPagelet
@@ -30,26 +30,10 @@
from interfaces import IPageletDisplayForm, IPageletFormView
-class PageletForm(form.Form, BrowserPagelet):
- interface.implements(IPageletForm)
+class PageletBaseForm(form.BaseForm, BrowserPagelet):
- forms = ()
-
__call__ = BrowserPagelet.__call__
- def extractData(self):
- data, errors = super(PageletForm, self).extractData()
- for form in self.forms:
- if IGroup.providedBy(form):
- formData, formErrors = form.extractData()
- data.update(formData)
- if formErrors:
- if errors:
- errors += formErrors
- else:
- errors = formErrors
- return data, errors
-
def render(self):
# render content template
if self.template is None:
@@ -63,13 +47,65 @@
return self.template()
+
+class PageletForm(form.Form, PageletBaseForm):
+ interface.implements(IPageletForm)
+
+ label = u''
+ description = u''
+
+ forms = ()
+ groups = ()
+ subforms = ()
+
+ render = PageletBaseForm.render
+ __call__ = PageletBaseForm.__call__
+
+ def extractData(self):
+ data, errors = super(PageletForm, self).extractData()
+ for form in self.groups:
+ formData, formErrors = form.extractData()
+ data.update(formData)
+ if formErrors:
+ if errors:
+ errors += formErrors
+ else:
+ errors = formErrors
+
+ for form in self.subforms:
+ formData, formErrors = form.extractData()
+ if formErrors:
+ if errors:
+ errors += formErrors
+ else:
+ errors = formErrors
+
+ return data, errors
+
+ def _loadSubforms(self):
+ return [form for name, form in
+ getAdapters((self.context, self.request, self), IPageletSubform)]
+
def updateForms(self):
forms = []
- for name, form in getAdapters(
- (self.context, self.request, self), IPageletSubform):
+ groups = []
+ subforms = []
+ for form in self._loadSubforms():
form.update()
- forms.append((form.weight, name, form))
+ if IGroup.providedBy(form):
+ groups.append((form.weight, form.__name__, form))
+ elif ISubForm.providedBy(form):
+ subforms.append((form.weight, form.__name__, form))
+ else:
+ forms.append((form.weight, form.__name__, form))
+
+ groups.sort()
+ self.groups = [form for weight, name, form in groups]
+
+ subforms.sort()
+ self.subforms = [form for weight, name, form in subforms]
+
forms.sort()
self.forms = [form for weight, name, form in forms]
@@ -77,6 +113,18 @@
self.updateWidgets()
self.updateActions()
self.updateForms()
+
+ if not IPageletSubform.providedBy(self):
+ self.actions.execute()
+
+ for form in self.groups:
+ form.postUpdate()
+ for form in self.subforms:
+ form.postUpdate()
+ for form in self.forms:
+ form.postUpdate()
+
+ def postUpdate(self):
self.actions.execute()
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/interfaces.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/interfaces.py 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/interfaces.py 2008-12-12 10:38:50 UTC (rev 93934)
@@ -31,16 +31,25 @@
""" pagelet form view """
-class IPageletForm(IPagelet):
+class IPageletBaseForm(IPagelet):
+ """ Base interface for pagelet forms """
+
+
+class IPageletForm(IPageletBaseForm):
"""Form mixin for pagelet implementation."""
label = interface.Attribute('Form label')
description = interface.Attribute('Form label')
- forms = interface.Attribute('Ordered list of sub forms')
+ forms = interface.Attribute('Ordered list of managed forms')
+ groups = interface.Attribute('Ordered list of managed groups')
+ subforms = interface.Attribute('Ordered list of managed subforms')
+ def updateForms():
+ """Update pagelet subforms."""
+
class IPageletAddForm(IPageletForm):
"""Add form mixin for pagelet implementation."""
@@ -56,7 +65,7 @@
"""Return whether names can be input by the user."""
-class IPageletDisplayForm(IPagelet):
+class IPageletDisplayForm(IPageletBaseForm):
""" Display form mixin """
@@ -67,11 +76,11 @@
""" as next url use newly created content url """
-class IPageletEditSubForm(IPageletForm):
+class IPageletEditSubForm(IPageletBaseForm):
""" Sub form mixin for pagelet implementation."""
-class IPageletSubform(IPageletForm):
+class IPageletSubform(interface.Interface):
""" Subform """
weight = schema.Int(
@@ -80,7 +89,10 @@
default = 9999,
required = False)
+ def postUpdate():
+ """Update form after manager form updated."""
+
class IAddButton(IButton):
""" add button """
Modified: z3ext.layoutform/trunk/src/z3ext/layoutform/subform.py
===================================================================
--- z3ext.layoutform/trunk/src/z3ext/layoutform/subform.py 2008-12-12 10:38:25 UTC (rev 93933)
+++ z3ext.layoutform/trunk/src/z3ext/layoutform/subform.py 2008-12-12 10:38:50 UTC (rev 93934)
@@ -16,24 +16,29 @@
$Id: 2007-12-12 12:27:02Z fafhrd $
"""
from zope import interface, event
+from zope.component import queryMultiAdapter
from zope.traversing.browser import absoluteURL
from zope.lifecycleevent import ObjectModifiedEvent
-from z3c.form import form, subform, button
+from z3c.form import subform, button
+from z3c.form.interfaces import IActionHandler
from z3ext.statusmessage.interfaces import IStatusMessage
-from form import PageletForm
from utils import applyChanges
-from interfaces import _, IPageletEditSubForm, ISaveButton
+from form import PageletBaseForm
+from interfaces import _, IPageletEditSubForm, IPageletSubform, ISaveButton
-class PageletEditSubForm(subform.EditSubForm, PageletForm):
+class PageletEditSubForm(subform.EditSubForm, PageletBaseForm):
interface.implements(IPageletEditSubForm)
- render = PageletForm.render
- __call__ = PageletForm.__call__
+ label = u''
+ description = u''
- @button.buttonAndHandler(_(u'Save'), name='save', provides=ISaveButton)
+ render = PageletBaseForm.render
+ __call__ = PageletBaseForm.__call__
+
+ @button.handler(ISaveButton)
def handleApply(self, action):
data, errors = self.extractData()
if errors:
@@ -47,3 +52,22 @@
IStatusMessage(self.request).add(self.successMessage)
else:
IStatusMessage(self.request).add(self.noChangesMessage)
+
+ def executeActions(self):
+ request = self.request
+ content = self.getContent()
+
+ for action in self.parentForm.actions.executedActions:
+ adapter = queryMultiAdapter(
+ (self, request, content, action), IActionHandler)
+ if adapter:
+ adapter()
+
+ def update(self):
+ self.updateWidgets()
+
+ if not IPageletSubform.providedBy(self):
+ self.executeActions()
+
+ def postUpdate(self):
+ self.executeActions()
More information about the Checkins
mailing list