Hello,
Quick question: I would like in Zope5, in a Python script, create a generic object whose attributes would be initialized from a dictionary (whose content we do not know). I know I can create a product or an External Method to do this, but is there a generic instantiable object in a python script, in the ZMI, non-persistent that might do the trick?
Thank you in advance for your leads
You've to create a zope product. In the product, create a class that inherit from Persistent and an init method which creates attribute from dictionary:
Your question is not sufficiently precise: what kind of object do you want to create?
An object which should become part of the Zope object hierarchy (and with ZMI support) or some auxiliary object? a persistent object or a temporary object?
I likely would approach the task in the following way: define an adequate class in trusted Python code (there you have the full power of Python). Make this class importable and accessible in untrusted environments (--> AcessControl.allow_module
) and use it as appropriate to instantiate objects.
In fact, it was not worth it, Zope automatically creates record objects when you type the data of a form.
thank you
Hello
Just in case you need it in other contexts, you could try this:
def make_blank_object(**kwargs) -> object:
""" Returns a generic blank object.
Attributes can be created on the fly.
"""
o = type('', (), {})()
o.__dict__.update(kwargs)
return o