Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

pypm install megrok.z3cform.base

How to install megrok.z3cform.base

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install megrok.z3cform.base
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.5Never BuiltWhy not?
0.3 Available View build log
Windows (64-bit)
0.5Never BuiltWhy not?
0.3 Available View build log
Mac OS X (10.5+)
0.5Never BuiltWhy not?
0.3 Available View build log
Linux (32-bit)
0.5 Available View build log
0.3 Available View build log
Linux (64-bit)
0.5 Available View build log
0.3 Available View build log
ZPL 2.1
Lastest release
version 0.5 on Nov 26th, 2012

megrok.z3cform.base is a not-so-thick layer above z3c.form. It provides a Grok way 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 old megrok.layout).

The customization of the forms is also eased by the use of megrok.pagetemplate, allowing you to override a template easily.

Form registration


We 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 querying

We let Grok register the component:

>>> grok.testing.grok_component('form', TestForm)

System Message: ERROR/3 (<string>, line 48)

Inconsistent literal block quoting.


Now, 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="" method="post"
enctype="multipart/form-data" class="form-testform">
Layout integration

megrok.z3cform.base is integrated, out-of-the-box with grokcore.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):

System Message: ERROR/3 (<string>, line 87)

Inconsistent literal block quoting.

... grok.context(Mammoth)

We register the components with Grok:

>>> grok.testing.grok_component('page', PageForm)

System Message: ERROR/3 (<string>, line 92)

Inconsistent literal block quoting.

True >>> grok.testing.grok_component('layout', MyLayout) True

Now, while rendering the form, we have it embedded in the Layout:

>>> pageform = getMultiAdapter((manfred, request), name="pageform")
>>> print pageform()

System Message: ERROR/3 (<string>, line 100)

Inconsistent literal block quoting.

The layout content is: <form action="" method="post" enctype="multipart/form-data" class="form-pageform"> ...

This is only a tiny presentation of the package features. Please, read the tests for a global overview.


0.5 (2012-07-21)
  • Added support for the new grokcore.layout. No longer depends on

System Message: WARNING/2 (<string>, line 118)

Bullet list ends without a blank line; unexpected unindent.

megrok.layout directly. [danilobotelho]

0.4 (2012-06-22)
  • Added decorators for validator, invariant and default_value.

System Message: WARNING/2 (<string>, line 125)

Bullet list ends without a blank line; unexpected unindent.

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

System Message: WARNING/2 (<string>, line 144)

Bullet list ends without a blank line; unexpected unindent.

once during edition. [trollfot]

  • Upgrading to be compatible with grok 1.1. [trollfot]
0.1 (2009-10-20)
  • Initial release

Subscribe to package updates

Last updated Nov 26th, 2012

Download Stats

Last month:2

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.