Package: megrok.z3cform.base
megrok.z3cform.baseis a not-so-thick layer abovez3c.form. It
provides aGrokway to register your forms and your widgets. In
addition, the package has a collection of base forms, useable
out-of-the box with grokcore.layout (or the oldmegrok.layout).The customization of the forms is also eased by the use ofmegrok.pagetemplate, allowing you to override a template easily.Form registrationModelsWe set up some models to serve as a form context:>>> import grokcore.component as grok
>>> from zope import interface, schema

>>> class IMammoth(interface.Interface):
...    name = schema.TextLine(title=u"Name")
...    age = schema.Int(title=u"Age")

>>> class Mammoth(grok.Context):
...    grok.implements(IMammoth)
...    name = schema.fieldproperty.FieldProperty(IMammoth['name'])
...    age = schema.fieldproperty.FieldProperty(IMammoth['age'])We declare the Form. It’s very similar to a grok.View:>>> import megrok.z3cform.base as z3cform

>>> class TestForm(z3cform.Form):
...    grok.context(Mammoth)Grokking and queryingWe let Grok register the component:>>> grok.testing.grok_component('form', TestForm)
TrueNow, we can query it normally:>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> manfred = Mammoth()

>>> from zope.component import getMultiAdapter
>>> myform = getMultiAdapter((manfred, request), name="testform")

>>> myform
<TestForm object at ...>
>>> print myform()
<form action="http://127.0.0.1" method="post"
        enctype="multipart/form-data" class="form-testform">
...Layout integrationmegrok.z3cform.baseis integrated, out-of-the-box withgrokcore.layout, providing base classes to ease the layout integration
in your project.Let’s have a quick overview. We create a layout:>>> import grokcore.layout

>>> class MyLayout(grokcore.layout.Layout):
...     grok.context(IMammoth)
...     def render(self):
...        return 'The layout content is: %s' % self.view.content()We declare a Page Form. A Page Form is a form that will show up inside
a layout:>>> class PageForm(z3cform.PageForm):
...    grok.context(Mammoth)We register the components with Grok:>>> grok.testing.grok_component('page', PageForm)
True
>>> grok.testing.grok_component('layout', MyLayout)
TrueNow, while rendering the form, we have it embedded in the Layout:>>> pageform = getMultiAdapter((manfred, request), name="pageform")
>>> print pageform()
The layout content is: <form action="http://127.0.0.1" method="post"
      enctype="multipart/form-data" class="form-pageform">
...Changelog0.5 (2012-07-21)Added support for the new grokcore.layout. No longer depends on
megrok.layout directly. [danilobotelho]0.4 (2012-06-22)Added decorators for validator, invariant and default_value.
The idea of these decorators is from plone.directives.form.Added support for Groups (z3c.form.group) [danilobotelho]Fixed WidgetTemplateGrokker [danilobotelho]Added HIDDEN_MODE to __init__.py [danilobotelho]0.3 (2010-02-11)Fixed OS-dependent path handling in the widget template grokker.0.2 (2009-11-18)Corrected a bug where the ObjectModifiedEvent was trigged more than
once during edition. [trollfot]Upgrading to be compatible with grok 1.1. [trollfot]0.1 (2009-10-20)Initial release