object creation in a specific folder...
hello all, this is my first zope app... i am trying to figure out how to create an object in a particular folder via script, when my current object may not be in the right tree... I tried to do a 'change folder' via restrictedTraverse (eg context.getRestrictedTraverse('/myapp/myfolder'), and then create the object using manage_addProduct... but it dosnt seem to work. any tips? thanks,
Rushabh Mehta wrote:
hello all,
this is my first zope app... i am trying to figure out how to create an object in a particular folder via script, when my current object may not be in the right tree...
I tried to do a 'change folder' via restrictedTraverse (eg context.getRestrictedTraverse('/myapp/myfolder'), and then create the object using manage_addProduct... but it dosnt seem to work. any tips?
thanks, _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Rushabh, Give the source that failed dont just describe it. Or, maybe first google "zope manage_addProduct" ... I found lots of examples. See if what you tried differs from the examples you find. David
Rushabh Mehta wrote:
hello all,
this is my first zope app... i am trying to figure out how to create an object in a particular folder via script, when my current object may not be in the right tree...
I tried to do a 'change folder' via restrictedTraverse (eg context.getRestrictedTraverse('/myapp/myfolder'), and then create the object using manage_addProduct... but it dosnt seem to work. any tips?
The manage_addProduct method creates an object in the context in which is was called. Which is to say, the object it is called on. If you say context.manage_addProduct(...) you're creating an object on the current object (or the current object's container.) The restrictedTraverse method gets and returns some object; it does not "change folders". (The API note reads: "Return the object obtained by traversing the given path from the object on which the method was called, performing security checks along the way.") You're thinking file-system-wise, and that doesn't work here. Think objects. (Note: I don't think 'getRestrictedTraverse' exists. 'restrictedTraverse' on the other hand, definitely does.) What you want to do, then, is call manage_addProduct on the object returned by restrictedTraverse:: context.restrictedTraverse('/wherever/a').manage_addProduct(...) Of course, you can also get a certain folder via acquisition:: context.wherever.a.manager_addProduct(...) unless you're getting paths dynamically. --jcc
participants (3)
-
David H -
J Cameron Cooper -
Rushabh Mehta