[Zope] Making pythonscript changes to formulator fields persistent

Gaute Amundsen gaute at div.org
Tue Apr 3 12:01:07 EDT 2007


On Monday 02 April 2007 18:58, Maciej Wisniowski wrote:
> > I was thinking of that...
> > How would you do that? Do you know formulator enough to say?
>
> I don't know your use case good enough. Is this just changing
> attributes of formulator fields?

Just asking :)


> > Put the whole thing in the EM, or something simpler?
> > An EM I could just hand off the field object to, to get "persisted"?
>
> I don't understand what you mean. Field objects already are persistent.
> EM gives you no security restrictions in comparision to Script Python.
>
In hindsight, what I ment, was instead of doing the whole traversal thing in 
the EM, I could just hand the EM the field, and a dict with the changes to be 
made, and it would only do the little magic:
vals = field.values
vals.update(mydict)
field.values = vals

> In general to simply change field.values['required'] to false I'd write
> function to traverse through ZODB to find all FormulatorForm objects
> and it's fields.

Had that allready. 
Ended up more or less just pasting that into the EM, then calling the EM from 
a script and just passing it the context.
It just worked, plain and simple. :)

> > (I find it a bit cumbersome to develop in EMs, reloading and all, so I
> > tend to avoid it.)
>
> With ExternalMethod you only have to hit save button again to refresh
> it.

I know, I know but that extra step actually adds 1/3 to the usual cycle of 
editt->reload. And then it ads another layer of indirection when you come 
back later and have to figure out how it works.

> Simple external method code that you may use to traverse through ZODB:
>
> def checkFolder(self, fld):
>     for obj_name, obj in fld.objectItems( 'FormulatorForm' ):
>         # get form fields here etc
>
>     for fld_name,fld_obj in fld.objectItems( 'Folder' ):
>         checkFolder( fld_obj )
>     for fld_name,fld_obj in fld.objectItems( 'Folder (Ordered)' ):
>         checkFolder( fld_obj )
>
> I'm not sure about 'FormulatorForm', this may be 'Formulator Form' or
> something like that.

It's fld.objectItems(['Formulator Form'])

Sorry to put you to the trouble, I should have been more clear I had that 
part.

Thank you for your help :)

Gaute


More information about the Zope mailing list