objectValues(meta_type) in python script
Hello, I am in the process of optimizing some of my scripts and moving some code from dtml methods into python Scripts. I am trying to find an object in a folder. I know there is only one object with this metatype ('MMM Shop Shopping Cart') in the folder. But this doesn't work: for item in memberfolder.objectValues('MMM Shop Shopping Cart'): shopping_cart = context.getId() return shopping_cart Now I expected to recieve a string containing 'Shopping Cart', but I recieved a string containing 'CD001' which is a product, not a shopping cart. Doesn't objectValues() work in python scripts ? TIA, -- Gitte Wange Jensen Sys Admin, Developer and a lot more MMmanager.org Aps, Denmark Phone: +45 29 72 79 72 Email: gitte@mmmanager.org Web: www.mmmanager.org Quote of the day: [unrestricted Python scripts] cannot be created or edited unless a special environment variable is set. In order to create or edit XXX Python Scripts, you have to set "ALL_YOUR_BASE_ARE_BELONG_TO" equal to "US". - Evan, http://www.zope.org/Members/4am/XXXPythonScripts
But this doesn't work:
for item in memberfolder.objectValues('MMM Shop Shopping Cart'): shopping_cart = context.getId()
return shopping_cart
Now I expected to recieve a string containing 'Shopping Cart', but I recieved a string containing 'CD001' which is a product, not a shopping cart.
Doesn't objectValues() work in python scripts ?
if it's : for item in memberfolder.objectValues('MMM Shop Shopping Cart'): shopping_cart = item.getId() return shopping_cart then I can consider I'm no more a "newbie" ;-) context is not changed by the for in loop or is it ? If it doens't work, send me hate mail ;-) Philippe
ons, 2001-10-24 kl. 12:47 skrev Philippe Jadin:
But this doesn't work:
for item in memberfolder.objectValues('MMM Shop Shopping Cart'): shopping_cart = context.getId()
return shopping_cart
Now I expected to recieve a string containing 'Shopping Cart', but I recieved a string containing 'CD001' which is a product, not a shopping cart.
Doesn't objectValues() work in python scripts ?
if it's :
for item in memberfolder.objectValues('MMM Shop Shopping Cart'): shopping_cart = item.getId()
return shopping_cart
then I can consider I'm no more a "newbie" ;-)
context is not changed by the for in loop or is it ?
If it doens't work, send me hate mail ;-)
Philippe
Well I just discovered that .... damn me :-) but then the object itself is just item ? And the object's id must by item.getId() ... I'm learning :-))) (You need to think different when doing things in a PythonScript, that you usually do i dtml) ... Gitte Wange
for item in memberfolder.objectValues('MMM Shop Shopping Cart'): shopping_cart = item.getId()
return shopping_cart
Well I just discovered that .... damn me :-)
but then the object itself is just item ? And the object's id must by item.getId() ...
I'm learning :-))) (You need to think different when doing things in a PythonScript, that you usually do i dtml) ...
well, context is exactly that : context. (zope context) In python, when you loop over elements using for .. in, the current element is the var you give it as first "argument" for item in xxxx: item will be here = to the current item being looped over hth Philippe
ons, 2001-10-24 kl. 12:39 skrev Gitte Wange:
Hello,
I am in the process of optimizing some of my scripts and moving some code from dtml methods into python Scripts.
I am trying to find an object in a folder. I know there is only one object with this metatype ('MMM Shop Shopping Cart') in the folder.
But this doesn't work:
for item in memberfolder.objectValues('MMM Shop Shopping Cart'): shopping_cart = context.getId()
return shopping_cart
Now I expected to recieve a string containing 'Shopping Cart', but I recieved a string containing 'CD001' which is a product, not a shopping cart.
Doesn't objectValues() work in python scripts ?
ARG !!! I just discovered that context.getId() returns the id of the object I "stand on" (the object that is in the URL). So perhaps it works .. I just need to call something else than context.getId() .. But what? How do I get hold of the objects that objectValues() returns ? TIA, Gitte Wange
participants (2)
-
Gitte Wange -
Philippe Jadin