[Zope] get a object using its id inside a pythong script
Oleg Broytmann
Oleg Broytmann <phd@phd.fep.ru>
Sun, 13 May 2001 12:52:26 +0400 (MSD)
On Sun, 13 May 2001, alan runyan wrote:
> for award in context.assignedAwards:
> if award in context.marketingAwards.objectIds():
> retObjs.append(context.marketingAwards.award) #get a award
> Attribute Error.. how do i do this?
> #appears in DTML you would use teh _.getitem(objId) hack, where is getitem?
Error beacuse
retObjs.append(context.marketingAwards.award)
is equivalent to
retObjs.append(getattr(context.marketingAwards, "award"))
and there is no "award" in Awards!
So use
<untested>
retObjs.append(getattr(context.marketingAwards, award))
</untested>
> Question 1: how can i please do this efficiently?
I suppose:
awards = context.marketingAwards.objectIds()
for award in context.assignedAwards:
if award in awards:
retObjs.append(getattr(context.marketingAwards, award))
> Question 2: why doesnt ObjectManager have a getObject(self, objectId) method
> on it? or am i overlooking something?
I think you can just use getattr or context.marketingAwards[award].
Oleg.
----
Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.