This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!
Project Description

This package provides support for writing forms using the Zope Formlib library and registering them directly in Python (without ZCML).

Setting up grokcore.formlib

This package is essentially set up like the grokcore.component package, please refer to its documentation for details. The additional ZCML lines you will need are:

<include package="grokcore.formlib" file="meta.zcml" />
<include package="grokcore.formlib" />

Put the first line somewhere near the top of your root ZCML file.

Examples

We need an example interface:

from zope import interface, schema

class IMammoth(interface.Interface):

   name = schema.TextLine(title=u"Name")
   age = schema.Int(title=u"Age", min=0)

Edit forms

You can provide an edit form for IMammoth like this:

from grokcore import formlib

class Edit(formlib.EditForm):

   formlib.context(IMammoth)

If your content object is defined in the same Python file and implements grokcore.formlib.IContext, then it will be the default context for your form.

Display forms

Display forms are as easy as edit forms:

class Index(formlib.DisplayForm):

   formlib.context(IMammoth)

Generic forms

You can build more generic forms, providing your own actions for a form:

class ISearch(interface.Interface):

    search = schema.TextLine(title=u"Text")

After this, you define your form. It’s applied to a mammoth, but uses the ISearch interface to generate fields:

class Search(formlib.Form):

    formlib.context(IMammoth)

    form_fields = formlib.Fields(ISearch)

    def update(self):
        # Default search results are None
        self.search_result = None

    @formlib.action(u"Search")
    def search(self, text):
        self.search_result = 'something found with text'

Create a custom template search.pt to render your form (in a directory modulename_templates).

Add forms

Add forms work like generic forms, you have to provide your action Add.

Customization

Since a Grok form is a Grok view, all configuration directives and attributes available on a Grok view are available as well on a Grok form.

This means that you can customize your form by associating a template with it. The template is responsible for displaying widgets and actions. The API to access them is the same as on a Zope Formlib form.

You can’t customize a form by providing a render() method on it, but you can still use the update() method if you want.

Please refer to the documentation of grokcore.view for more details.

API Overview

Base classes

EditForm
Extends Form to create an edit form for your content.
DisplayForm
Creates simple display forms.
Form
Is a base class to create generic forms.
AddForm
Extends Form to create add forms. You have to provide the add action which is going to create the new object.

Decorators

action
Is a decorator to create an action on the form. Your action only has to accept values from the form as parameters.

Helpers

AutoFields
Create form fields from the given context. If the context is an interface, Zope fields defined in that interface are going to be used to build form fields. If the context is a regular object, Zope fields of all implemented interfaces of that object are going to used to build form fields.
Fields
Create and reorder fields on the form.

Additionally, the grokcore.formlib package exposes the grokcore.component, grokcore.security and grokcore.view APIs.

Changes

1.11 (2016-06-20)

  • grok.action will now trigger validation errors RequiredMissing for required fields that not present at all in the request.

1.10.1 (2016-02-15)

  • Update tests.

1.10 (2015-04-01)

  • Forms now notify the ObjectEditedEvent instead of the ObjectModifiedEvent.

1.10a1 (2013-11-22)

  • Add compatibility for CSRF protection feature in zope.formlib.

1.9 (2012-05-01)

  • Nothing changed yet.

1.8 (2010-11-03)

  • The context directive now has its own default computation.

1.7 (2010-11-01)

  • Update version requirements for martian, grokcore.component, grokcore.security grokcore.view.

1.6 (2010-10-18)

  • Made package comply to zope.org repository policy.
  • Update functional tests to zope.app.wsgi Browser instead of zope.app.testing one.
  • Don’t depend anymore on zope.app.zcmlfiles for tests.

1.5 (2009-12-13)

  • Use zope.container instead of zope.app.container (in tests and in the configure.zcml).
  • Fixed up missing dependencies and splitted regular and test dependencies.

1.4 (2009-09-17)

  • Reflect the changes in grokcore.view 1.12 where View and CodeView become a single View again. This reverts to the View situation of grokcore.formlib 1.1.

1.3 (2009-09-16)

  • Remove the reference to the grok.View permission that is no longer in grokcore.security 1.2
  • Use 1.0b1 versions.cfg in Grok’s release info instead of a local copy; a local copy for all grokcore packages is just too hard to maintain.

1.2 (2009-07-20)

  • Adapted tests to the grokcore.view split of View and CodeView.
  • Fixed forms to use self.template.render() directly instead of using a removed private method from grokcore.view.
  • Add grok.View permissions for functional tests.

1.1 (2009-01-07)

  • Have GrokForm define an empty actions attribute by default, in order for “action-less” forms to work easily.

1.0 (2008-09-25)

  • Created grokcore.formlib in July 2008 by factoring zope.formlib-based components, grokkers and directives out of Grok.
Release History

Release History

1.11

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.10.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.10

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.10a1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.9

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.8

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.7

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.6

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
grokcore.formlib-1.11.tar.gz (26.3 kB) Copy SHA256 Checksum SHA256 Source Jun 20, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting