[Grok-dev] Re: Heads up: Renamed AddForm to Form

Martijn Faassen faassen at startifact.com
Fri Mar 16 08:18:39 EDT 2007

Philipp von Weitershausen wrote:
>  From the commit log message:
> - Renamed grok.AddForm to grok.Form because there was no additional
>   functionality in that base class that was specific to adding. Yes, it
>   used formlib's AddForm, but none of the features that has to make
>   adding objects easy for you were used (adding objects in Zope 3 is
>   overly complicated anyway, thanks to IAdding). Everybody writing add
>   forms was writing his/her own actions anyway, which is exactly what
>   the point of a general grok.Form base class is.
> - Got rid of the "form in form" weirdness. It turns out that a very,
>   very simple mix-in with a custom render() method makes it possible to
>   mix formlib's base classes with grok.View. This makes the ViewGrokker
>   simpler and exposes more of formlib directly in Grok forms.
> Apart from having to use grok.Form instead of grok.AddForm, existing 
> applications shouldn't have to change.

And here's a failing functional test. place it under ftests.form.formupdate:

A grok.EditForm is a special grok.View that renders an edit form. It
allows update() to be overridden as well.

   >>> import grok
   >>> from grok.ftests.form.formupdate import Mammoth
   >>> grok.grok('grok.ftests.form.formupdate')
   >>> getRootFolder()["manfred"] = Mammoth()

   >>> from zope.testbrowser.testing import Browser
   >>> browser = Browser()
   >>> browser.handleErrors = False
   >>> browser.open("http://localhost/manfred/@@edit")
   >>> browser.getControl(name="form.name").value = "Manfred the Mammoth"
   >>> browser.getControl(name="form.size").value = "Really big"
   >>> browser.getControl("Apply").click()
   >>> print browser.contents
   ...Manfred the Mammoth...
   ...Really big...

grok.DisplayForm renders a display form:

   >>> browser.open("http://localhost/manfred/@@display")
   >>> print browser.contents
   ...Manfred the Mammoth...
   ...Really big...

import grok
from zope import schema

class Mammoth(grok.Model):
     class fields:
         name = schema.TextLine(title=u"Name")
         size = schema.TextLine(title=u"Size")

class Edit(grok.EditForm):
     def update(self):
         self.foo = 'bar'

class Display(grok.DisplayForm):

I propose we revert your changes, as I think you cannot make update() 
and render() work as they should on grok views in the current design. 
And then we should check in this test to make sure nobody gets the same 
idea. Not doing this to start with is my mistake.



More information about the Grok-dev mailing list