Making pythonscript changes to formulator fields persistent
Hi. Trying to change various properties of a few hundred formulator fields programmatically. For example assigning to field.values['required'] = False. This seemed to work, but of course was not persisted, and disappeared gradualy. Quite magical to see :) Tried to take a copy of values and "overwrite" values with the changed ones, to trigger the presistence machinery, but that is not allowed. The same goes for setting field._p_changed = True, and accessing field._edit(). I can use field.manage_edit() but then I have to masage all the data from field.values into "request format" to have it accepted, otherwise I get "required" errors, or values gets deleted. What to do? I guess some developer has worked hard to prevent me from doing just this at some point, but why? Do I need to write a product to do it? Is anyone at all using this crazy development model where "semi trusted users" do stuff in the ZMI??? But I digress.. If anyone knows how to solve this I would be less frustrated for a while ;-) Regrads Gaute Amundsen
What to do?
I guess some developer has worked hard to prevent me from doing just this at some point, but why? Do I need to write a product to do it? Is anyone at all using this crazy development model where "semi trusted users" do stuff in the ZMI??? But I digress..
If anyone knows how to solve this I would be less frustrated for a while ;-) Use ExternalMethod - easy just like python scripts and it's code is trusted.
-- Maciej Wisniowski
On Monday 02 April 2007 17:51, Maciej Wisniowski wrote:
What to do?
I guess some developer has worked hard to prevent me from doing just this at some point, but why? Do I need to write a product to do it? Is anyone at all using this crazy development model where "semi trusted users" do stuff in the ZMI??? But I digress..
If anyone knows how to solve this I would be less frustrated for a while ;-)
Use ExternalMethod - easy just like python scripts and it's code is trusted.
I was thinking of that... How would you do that? Do you know formulator enough to say? 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 find it a bit cumbersome to develop in EMs, reloading and all, so I tend to avoid it.) Gaute
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?
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 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.
(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.
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. -- Maciej Wisniowski
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
participants (2)
-
Gaute Amundsen -
Maciej Wisniowski