[Grok-dev] Re: Multiple addforms with different default values

Sebastian Ware sebastian at urbantalk.se
Tue Jun 3 04:02:52 EDT 2008


2 jun 2008 kl. 18.33 skrev Jan Ulrich Hasecke:

>
> Is it possible to have a Addform called AddElephant which hands over  
> some
> default values?
>
> Something like this?
>
>        form_fields = grok.AutoFields(IAnimal)
>        form_fields['specie'] = 'Elephant'
>

This replaces the field 'specie' with the string 'Elephant'. You would  
want to put your code in the update method of your addform class. I  
suggest that you add a breakpoint in the update method and then  
introspect form_fields, I am sure you will find a "default" attribute  
of the form_fields['specie'] field object that you can manipulate.

>
> This does not work. It should render a form where the field 'specie'  
> is filled
> with the value 'Elephant'. Perfect would be if fields with default  
> values
> cannot be edited.

To make the fields read only (in this case login and role), try  
something like:

     form_fields = grok.Fields(interfaces.IVisitUser,  
for_display=True).select('login', 'role')
     form_fields +=  
grok.AutoFields(interfaces.IVisitUser).omit('object_type', 'login',  
'role')
>
>
> Any hints?


mvh Sebastian


More information about the Grok-dev mailing list