Question

I am trying to build a form package for a Plone website. I am currently working with Plone 4.3. Before I was using Dexterity with five.grok and grok libraries. But after reading the Plone 4.3 migration and five.grok dependency section of this article: http://developer.plone.org/components/grok.html it appears that Plone developers are moving away from using grok all together.

So should I move away from using Grok and how would I go about doing so when all the current documentation is currently using Grok? Additionally I am developing from a Windows based machine.

Was it helpful?

Solution

First creating form without grok is not that hard and do not depends on your Operating System.

Creating a form is always the same. Here is how I proceed:

  • Some imports
from Products.Five.browser import BrowserView
from plone.autoform.form import AutoExtensibleForm
from plone.app.z3cform import layout
from zope import interface
from zope import schema
from zope import component
from z3c.form import form

from collective.my.i18n import _
  • Create a schema
class AddFormSchema(interface.Interface):
    what = schema.Choice(
        title=_(u"What"),
        vocabulary="plone.app.vocabularies.UserFriendlyTypes"
    )
    where = schema.Choice(
        title=u"Where",
        vocabulary="collective.my.vocabulary.groups"
    )
  • create a generic adapter to fill the form from anywhere
class AddFormAdapter(object):
    interface.implements(AddFormSchema)
    component.adapts(interface.Interface)
    def __init__(self, context):
        self.what = None
        self.where = None
  • Then write the form
class AddForm(AutoExtensibleForm, form.Form):
    schema = AddFormSchema
    form_name = 'add_content'
  • Add a view
class AddButton(layout.FormWrapper):
    """Add button"""
    form = AddForm
  • Now ZCML time this is the step you don't need when using grok:
<adapter factory=".my.AddFormAdapter"/>
<browser:page
  for="*"
  name="my.addbutton"
  class=".my.AddButton"
  template="addbutton.pt"
  permission="zope2.View"
  />

Should you move from grok:

This is depending of what are you doing. For an addon I say Yes but for a project, it's up to you.

Grok is not parts of the already big Zope. So adding dependency is something that always should be done only if needed. Grok is an option so I have never used it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top