[Grok-dev] Using templates on forms with multiple actions?

Jan-Wijbrand Kolman janwijbrand at gmail.com
Fri Nov 13 04:31:04 EST 2009

Adam Summers wrote:
> Hi all,
> This is a simple question, I know, but I'm stumped.
> lets say I have a grok.Form as follows:
> class showData(grok.Form):
> 	grok.context(Restaurant)
> 	grok.name('vlh')
> 	form_fields = grok.Fields( f_date = schema.Date(title=u'Date'),
> 		 f_daycount = schema.Int(title=u'Number of Days'))
> 	@grok.action('Calculate!')
> 	 def calc(self, **data):
> 		 return str(self.context.getStats(data['f_date'],'BREAKFAST',2))
> 	 @grok.action('VLH!')
> 	 def calc2(self, **data):
> 		 return str(self.context.getVLHData(data['f_date'], 'BREAKFAST', data 
> ['f_daycount']))
> As a result of the actions, I'm currently returning strings. But how  
> can I use this calculated data in a template? Basically the results  
> are lists of lists that I want to render in tables.
> Any help would be much appreciated..

Another idea would be:

* define a grok.template() for you form.

* have this template render the for (you can look in the "default" 
templates of form for ideas how to do that).

* in this template you render results of the form submit when available.

Something like this (sketchy pseudo code):


class ShowData(grok.Form):

     form_fields = ....

     result = None

     def handle_do(self, **data):
         self.result = ....


<tal:block condition="python: view.result is not None">
    ....render result table...
<tal:block condition="python: view.result is None">
     ....render form....

Something like that.


More information about the Grok-dev mailing list