[Zope3-Users] Cloning interfaces/interface fields - how?
dusty at qwer.tk
Tue Feb 19 10:46:29 EST 2008
I'm over and over confronted with a simple pattern, where I need to clone
interface field. For instance, I have the content object, which has an
name = TextLine()
address = TextLine()
Then, I have for instance a search form, which consists of fields of other
interfaces, therefore I tried this:
name = IPerson['name']
The above interface has the problem that the field is referenced, thus
changing attributes (e.g. name.required=False) changes also the attributes of
the original field.
Therefore I now copy the field, which seems to work (but I'm not 100%
name = copy.deepcopy(IPerson['name'])
Another idea is to entirley skip the IPersonSearch interface and create the
interface "on the fly", like this:
fields = z3c.form.field.Fields(copy.deepcopy(IPerson).select('name'))
However, this does not seem to work as still some things are referenced
instead of copied, so copy.deepcopy seems to fail on interfaces.
What's your opinion on this, how do you apply this pattern?
hermann at qwer.tk
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7
More information about the Zope3-users