[Zope] Getting an object from it's id

2001-01-23 Thread Gale

Hi,

This is obviously a newbie question.

I have several places in my dtml code where in order to obtain an object I
loop through objects of that kind and make a test to determine if each
objects id matches the id I picked up from a form.

This is the only way I could get it to work; but I feel there must be a
better, more efficient way.

Here is an example:

dtml-in expr="objectValues('Folder')"
dtml-if "myId==id"

Once I get a match I then proceed to use it in subsequent code, such as a
dtml with id and it works since id now refers to the object I'm interested
in.

Is there a Zope API method that will allow me to get an object from it's id,
or can I write a simple Python method to do it, or am I missing something
even more obvious?

Thanks


Geoff Armstrong


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Getting an object from it's id

2001-01-23 Thread Erik Enge

[[EMAIL PROTECTED]]

| Is there a Zope API method that will allow me to get an object from
| it's id, or can I write a simple Python method to do it, or am I
| missing something even more obvious?

Well, sometimes objectItems or objectValues can be the right ones to
use.  Other times, (in Python Products at least) you use _getOb() to
fetch the object for you.

Let's say you have this object structure:

/Folder1
/Folder2

If you (in Python code) have Folder1 in the namespace, as self for
example, you can say object=self._getOb('Folder2'), and vila. :)
Don't know how you would do that in DTML, though.

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Getting an object from it's id

2001-01-23 Thread Oleg Broytmann

On Tue, 23 Jan 2001, Gale wrote:
 dtml-in expr="objectValues('Folder')"
 dtml-if "myId==id"

   You don't need to "get" the object, as the object is already on top of
the namespace stack (dtml-in put the object there on every iteration). Just
use the object's attributes (id, after all, is just yet another attribute).

Oleg.

 Oleg Broytmann http://www.zope.org/Members/phd/ [EMAIL PROTECTED]
   Programmers don't die, they just GOSUB without RETURN.


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Getting an object from it's id

2001-01-23 Thread Geoff Armstrong

on 1/23/01 12:34 PM, Oleg Broytmann at [EMAIL PROTECTED] wrote:

 On Tue, 23 Jan 2001, Gale wrote:
 dtml-in expr="objectValues('Folder')"
 dtml-if "myId==id"

What I'm trying to do here is avoid using dtml-in, since in order for it to
put the object in the namespace it has to iterate over all of them (there
could be any number).

All I have at the beginning is the name of the object in the REQUEST part of
the namespace as picked up from a form. My method is the action to that
form.

In DTML there doesn't seem to be a way of saying, "I have this string with
the name of an object, now fetch me the object."

Geoff


 
 You don't need to "get" the object, as the object is already on top of
 the namespace stack (dtml-in put the object there on every iteration). Just
 use the object's attributes (id, after all, is just yet another attribute).
 
 Oleg.
 
 Oleg Broytmann http://www.zope.org/Members/phd/ [EMAIL PROTECTED]
 Programmers don't die, they just GOSUB without RETURN.


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Getting an object from it's id

2001-01-23 Thread Andrew Kenneth Milton

+---[ Geoff Armstrong ]--
| on 1/23/01 12:34 PM, Oleg Broytmann at [EMAIL PROTECTED] wrote:
|
| In DTML there doesn't seem to be a way of saying, "I have this string with
| the name of an object, now fetch me the object."

if objectname is actually a variable with the name...

dtml-with "_.getitem(objectname,0)"

or dtml-call "REQUEST.set('fooobject',_.getitem(objectname,0))" to
get the object into a variable to pass or manipulate.

-- 
Totally Holistic Enterprises Internet|  P:+61 7 3870 0066   | Andrew Milton
The Internet (Aust) Pty Ltd  |  F:+61 7 3870 4477   | 
ACN: 082 081 472 ABN: 83 082 081 472 |  M:+61 416 022 411   | Carpe Daemon
PO Box 837 Indooroopilly QLD 4068|[EMAIL PROTECTED]| 

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Getting an object from it's id

2001-01-23 Thread Ivan Cornell

Geoff Armstrong wrote:

 What I'm trying to do here is avoid using dtml-in, since in order for it to
 put the object in the namespace it has to iterate over all of them (there
 could be any number).

 All I have at the beginning is the name of the object in the REQUEST part of
 the namespace as picked up from a form. My method is the action to that
 form.

 In DTML there doesn't seem to be a way of saying, "I have this string with
 the name of an object, now fetch me the object."


Hi Geoff,

Try using _.getitem(), as in:
dtml-let myObject="_.getitem(myId)"
... dtml-call myObject.foo ...
/dtml-let
or probably:
dtml-let myObject="_.getitem(REQUEST['myId'])"

If you aren't sure of the existance of the object, wrap the above in:
dtml-if "_.hasattr(this(), REQUEST['myId'])"
/dtml-if

Ivan


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




RE: [Zope] Getting an object from it's id

2001-01-23 Thread Max Møller Rasmussen

From: Geoff Armstrong [mailto:[EMAIL PROTECTED]]

In DTML there doesn't seem to be a way of saying, "I have this string with
the name of an object, now fetch me the object."

Shure there is:

dtml-var "some_container_object[remote_id].title"

As far as I remember.

regards Max M

A snippet I use somewhere:

dtml-in "emner[_['sequence-item']].objectValues('maal')"
dtml-var titlebr
dtml-var descriptionbrbr
/dtml-in

___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Getting an object from it's id

2001-01-23 Thread Geoff Armstrong

on 1/23/01 1:12 PM, Erik Enge at [EMAIL PROTECTED] wrote:

Thanks; but being new to this could you help me a bit more by providing an
example of how to use 'getOb' within dtml code. I tried testing in; but
couldn't get it work.

Geoff

 [[EMAIL PROTECTED]]
 
 | Is there a Zope API method that will allow me to get an object from
 | it's id, or can I write a simple Python method to do it, or am I
 | missing something even more obvious?
 
 Well, sometimes objectItems or objectValues can be the right ones to
 use.  Other times, (in Python Products at least) you use _getOb() to
 fetch the object for you.
 
 Let's say you have this object structure:
 
 /Folder1
 /Folder2
 
 If you (in Python code) have Folder1 in the namespace, as self for
 example, you can say object=self._getOb('Folder2'), and vila. :)
 Don't know how you would do that in DTML, though.
 
 ___
 Zope maillist  -  [EMAIL PROTECTED]
 http://lists.zope.org/mailman/listinfo/zope
 **   No cross posts or HTML encoding!  **
 (Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




Re: [Zope] Getting an object from it's id

2001-01-23 Thread Geoff Armstrong

on 1/23/01 1:20 PM, Ivan Cornell at [EMAIL PROTECTED] wrote:


Hi Ivan,

Thanks. The "_.getitem(myId)" works well. I've made a note of the "hasattr"
trick as well for future reference.


Geoff
 Geoff Armstrong wrote:
 
 What I'm trying to do here is avoid using dtml-in, since in order for it to
 put the object in the namespace it has to iterate over all of them (there
 could be any number).
 
 All I have at the beginning is the name of the object in the REQUEST part of
 the namespace as picked up from a form. My method is the action to that
 form.
 
 In DTML there doesn't seem to be a way of saying, "I have this string with
 the name of an object, now fetch me the object."
 
 
 Hi Geoff,
 
 Try using _.getitem(), as in:
 dtml-let myObject="_.getitem(myId)"
 ... dtml-call myObject.foo ...
 /dtml-let
 or probably:
 dtml-let myObject="_.getitem(REQUEST['myId'])"
 
 If you aren't sure of the existance of the object, wrap the above in:
 dtml-if "_.hasattr(this(), REQUEST['myId'])"
 /dtml-if
 
 Ivan
 
 
 ___
 Zope maillist  -  [EMAIL PROTECTED]
 http://lists.zope.org/mailman/listinfo/zope
 **   No cross posts or HTML encoding!  **
 (Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )