grok.Form subclasses expect an actions attribute when rendering

Bug #236897 reported by Dan Fairs
2
Affects Status Importance Assigned to Milestone
grok
Fix Released
Medium
Jan Wijbrand Kolman
1.0
Fix Released
Medium
Jan Wijbrand Kolman

Bug Description

This is grok 0.12.1.

Forms created by subclassing grok.Form fail to render if no actions are specified. For example:

(app.py)
from zope.interface import Interface
from zope.schema import TextLine
import grok

class IDummyForm(Interface):
    name = TextLine(title=u'name')

class Content(grok.Application, grok.Container):
    grok.implements(IDummyForm)

class DummyForm(grok.Form):
    grok.context(Content)
    form_fields = [] # or grok.AutoFields(Content)

Visiting the /dummyform URL in the browser gives a traceback as follows:

2008-06-02T21:10:08 ERROR SiteError http://localhost:8080/foo/dummyform
Traceback (most recent call last):
  File "/Users/dan/.buildout/eggs/tmpHn7YIK/zope.publisher-3.5.0a1.dev_r78838-py2.5.egg/zope/publisher/publish.py", line 133, in publish
  File "/Users/dan/.buildout/eggs/tmp2mfFo8/grok-0.12.1-py2.5.egg/grok/publication.py", line 45, in callObject
  File "/Users/dan/.buildout/eggs/tmpjOPdnD/zope.app.publication-3.4.2-py2.5.egg/zope/app/publication/zopepublication.py", line 167, in callObject
  File "/Users/dan/.buildout/eggs/tmpHn7YIK/zope.publisher-3.5.0a1.dev_r78838-py2.5.egg/zope/publisher/publish.py", line 108, in mapply
   - __traceback_info__: <madhatter.app.DummyForm object at 0x1e8fb50>
  File "/Users/dan/.buildout/eggs/tmpHn7YIK/zope.publisher-3.5.0a1.dev_r78838-py2.5.egg/zope/publisher/publish.py", line 114, in debug_call
  File "/Users/dan/.buildout/eggs/tmp2mfFo8/grok-0.12.1-py2.5.egg/grok/components.py", line 500, in __call__
  File "/Users/dan/.buildout/eggs/tmp2mfFo8/grok-0.12.1-py2.5.egg/grok/components.py", line 472, in update_form
  File "/Users/dan/.buildout/eggs/tmpU7ZlvQ/zope.formlib-3.4.0-py2.5.egg/zope/formlib/form.py", line 740, in update
AttributeError: 'DummyForm' object has no attribute 'actions'

While forms with buttons are the common case, it's not hard to imagine a situation where a form might not have any buttons (perhaps the form is processed by some client-side javascript).

It should be possible to have forms without buttons (actions).

Revision history for this message
Philipp von Weitershausen (philikon) wrote : Re: [Bug 236897] [NEW] grok.Form subclasses expect an actions attribute when rendering

On 2 Jun 2008, at 22:14 , Dan Fairs wrote:
> (app.py)
> from zope.interface import Interface
> from zope.schema import TextLine
> import grok
>
> class IDummyForm(Interface):
> name = TextLine(title=u'name')
>
> class Content(grok.Application, grok.Container):
> grok.implements(IDummyForm)
>
>
> class DummyForm(grok.Form):
> grok.context(Content)
> form_fields = [] # or grok.AutoFields(Content)
>
> Visiting the /dummyform URL in the browser gives a traceback as
> follows:
>
> 2008-06-02T21:10:08 ERROR SiteError http://localhost:8080/foo/
> dummyform
> Traceback (most recent call last):
> ...
> AttributeError: 'DummyForm' object has no attribute 'actions'
>
> While forms with buttons are the common case, it's not hard to
> imagine a
> situation where a form might not have any buttons (perhaps the form is
> processed by some client-side javascript).
>
> It should be possible to have forms without buttons (actions).

You can simply add the 'actions' attribute to the form class to avoid
the exception:

class DummyForm(grok.Form):
    ...
    actions = []

Revision history for this message
Martijn Faassen (faassen) wrote :

> You can simply add the 'actions' attribute to the form class to avoid
> the exception:
>
> class DummyForm(grok.Form):
> ...
> actions = []

This is a workaround though, not a solution. I think we should make
sure that if you don't use any @grok.action decorators, you still get
to see a form.

todd (todd-infrae)
Changed in grok:
assignee: nobody → janwijbrand
milestone: none → 1.0
Revision history for this message
Jan Wijbrand Kolman (janwijbrand) wrote :

What about merely adding

  actions = form.Actions()

on the grokcore.formlib EditForm and AddForm baseclasses?

Changed in grok:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Jan Wijbrand Kolman (janwijbrand) wrote :

Fixed in grokcore.formlib trunk. We should remember to release a 1.0.1 of grokcore.formlib when releasing grok 1.0.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.