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

Adam Summers adamsummers1 at me.com
Fri Nov 13 21:10:55 EST 2009


Hi!

Thanks very much for your help!

So now for reference, my class now looks like
> mytemplate = grok.PageTemplateFile(filename='...')
>> 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):
>>                 self.mylist =  self.context.getStats(data 
>> ['f_date'],'BREAKFAST',2)
>> 		return(mytemplate.render(self))
[...]

Regards,
Adam


On 13 Nov 2009, at 6:34 AM, Souheil CHELFOUH wrote:

> you can define templates and call them:
>
> mytemplate = grok.PageTemplateFile(filename='...')
>
> and to call it :
>
> mytemplate.render(self)
> the form will then be the "view" of the template
> you can set your lists before calling the template
>
> self.mylist = self.context.getVLHData(data['f_date'], 'BREAKFAST',
> data['f_daycount'])
> mytemplate.render(self)
>
> and in your template:
> <tal:loop repeat="line view/mylist">...</tal:loop>
>
>
> 2009/11/12 Adam Summers <adamsummers1 at me.com>:
>> 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..
>>
>> Thanks and Regards,
>> Adam
>>
>> _______________________________________________
>> Grok-dev mailing list
>> Grok-dev at zope.org
>> https://mail.zope.org/mailman/listinfo/grok-dev
>>



More information about the Grok-dev mailing list