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.crud

How to install megrok.z3cform.crud

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install megrok.z3cform.crud
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1 Available View build log
Windows (64-bit)
0.1 Available View build log
Mac OS X (10.5+)
0.1 Available View build log
Linux (32-bit)
0.1 Available View build log
Linux (64-bit)
0.1 Available View build log
Lastest release
version 0.1 on Jul 6th, 2011


This module gives you an abstract base class to make CRUD forms with. These forms give you by default a tabular view of the objects, where attributes of the object can be edited in-place. Please refer to the ICrudForm interface for more details.

>>> from megrok.z3cform.crud import crud

Form registration


We set up some models to serve as a form context:

>>> import grokcore.component as grok
>>> from zope import interface, schema
>>> class IPerson(interface.Interface):
...    name = schema.TextLine(title=u"Name")
...    age = schema.Int(title=u"Age")
>>> class Person(grok.Context):
...    grok.implements(IPerson)
...    name = schema.fieldproperty.FieldProperty(IPerson['name'])
...    age = schema.fieldproperty.FieldProperty(IPerson['age'])
...    def __init__(self, name, age):
...        self.name = name
...        self.age = age
>>> class IPersonContainer(interface.Interface):
...    pass
>>> class PersonContainer(dict):
...    grok.implements(IPersonContainer)

For this test, we take the the name of our persons as keys in our storage:

>>> storage = PersonContainer()
>>> storage['Peter'] = Person(u'Peter', 16)
>>> storage['Martha'] = Person(u'Martha', 32)

We declare the Form with the help of megrok.z3cform.base. It's very similar to a grok.View:

>>> import megrok.z3cform.base as z3cform
>>> class TestForm(crud.CrudForm):
...    grok.context(IPersonContainer)
...    update_schema = IPerson
...    def get_items(self):
...        return sorted(storage.items(), key=lambda x: x[1].name)
...    def add(self, data):
...        person = Person(**data)
...        storage[str(person.name)] = person
...        return person
...    def remove(self, (id, item)):
...        del storage[id]
Grokking and querying

We let Grok register the component:

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

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

Inconsistent literal block quoting.


Now, we can query it normally:

>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> from zope.component import getMultiAdapter
>>> myform = getMultiAdapter((storage, request), name="testform")
>>> myform
<TestForm object at ...>
>>> print myform()
<form action="" method="post"
enctype="multipart/form-data" class="form-testform">


  • Initial release

Subscribe to package updates

Last updated Jul 6th, 2011

Download Stats

Last month:1

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.