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
Models
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)
True
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="http://127.0.0.1" 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): ... grok.context(Mammoth)
We register the components with Grok:
>>> grok.testing.grok_component('page', PageForm)
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()
The layout content is: <form action="http://127.0.0.1" method="post"
enctype="multipart/form-data" class="form-pageform">
...
Changelog
0.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
Metadata
Release files for megrok.z3cform.base 0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| megrok.z3cform.base-0.5.tar.gz | 19.5 kB | Without provenance | Details for megrok.z3cform.base-0.5.tar.gz |
Release files / megrok.z3cform.base-0.5.tar.gz
| Download URL | megrok.z3cform.base-0.5.tar.gz |
|---|---|
| Size | 19.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07ce4ae77465fa2175a0023b990b1cfe66e48095958893ac5577e468b86e64d5
|
|
BLAKE2b-256 checksum How to use checksums |
36a464e7dc118933ceecbf32fa30b511ef1422759519530427e117f8a5b07995
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for megrok.z3cform.base 0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.