The grok module provides a number of convenience functions to aid in common tasks.
This function is used to create a sequence of form fields from an interface (schema) or from the interfaces (schemas) the context object provides.
Example: Generate fields from an interface
The grok.AutoFields() is used on the IMammoth interface, and all attributes that inherit from IField (such as the ones supplied in the zope.schema package) are concatenated into a list.
import grok
from zope import interface, schema
class IMammoth(interface.Interface):
name = schema.TextLine(title=u"Name")
size = schema.TextLine(title=u"Size", default=u"Quite normal")
class Mammoth(grok.Model):
interface.implements(IMammoth)
class Edit(grok.EditForm):
grok.context(Mammoth)
form_fields = grok.AutoFields(Mammoth).omit('size')
In this example the size attribute will not show up in the resulting edit view.
See also
Example: Generate form fields from schema objects
When the Edit form is rendered, the Textlines b and a will appear as input fields in that order.
import grok
from zope import schema
class Edit(grok.EditForm):
fields = grok.Fields(
b = schema.TextLine(title=u"Beta"),
a = schema.TextLine(title=u"Alpha"),
)
See also
See also
Site objects are instances of grok.Site. Typically this will also be your main grok.Application root object, which inherits from grok.Site. Normally you will want to use grok.getApplication to get the application object, as grok.getSite can return enclosed sub-sites in applications with more complex configuration.
See also
Web Component Development With Zope 3, second edition By Philipp von Weitershausen; Chapter 18 describes the use of Site objects.
Example:
import grok
class Mammoth(object):
def __init__(self, name):
self.name = name
manfred = Mammoth('manfred')
grok.notify(grok.ObjectCreatedEvent(manfred))
See also
Grok events provide a selection of common event types.
See also
Web Component Development With Zope 3, second edition By Philipp von Weitershausen; Chapter 16 describes the Zope 3 event system.
Construct a URL for the given request and object.
name may be a string that gets appended to the object URL. Commonly used to construct an URL to a particular view on the object.
This function returns the constructed URL as a string.
See also
View classes derived from grok.View have a similar url() method for constructing URLs.