I have a container ZClass Person. Person has a (string) property CurrentPosition which gives the id of a ZClass instance contained in Person. Example: DarranEdmundson (Person) bsc_degree (Degree) phd_degree (Degree) fellow (Academic) fujitsu (employment) vizlab (employment) where DarranEdmundson.CurrentPosition = "vizlab" I am having problems accessing the CurrentPosition object in a pythonMethod. list = [] for person in self.objectValues('Person'): position = _.getitem(person.CurrentPosition) list.append(person.LastName, position.anyProperty)) I can do it in DTML via <dtml-in "objectValues('Person')"> <dtml-with "_.getitem(CurrentPosition)"> <dtml-var LastName> <dtml-var anyProperty> </dtml-with> </dtml-in> I think the question really comes down to: how does one achieve <dtml-with name> in a pythonMethod? Cheers, Darran.
----- Original Message ----- From: "Darran Edmundson" <Darran.Edmundson@anu.edu.au>
I have a container ZClass Person. Person has a (string) property CurrentPosition which gives the id of a ZClass instance contained in Person.
list = [] for person in self.objectValues('Person'): position = _.getitem(person.CurrentPosition) list.append(person.LastName, position.anyProperty))
I think the question really comes down to: how does one achieve <dtml-with name> in a pythonMethod?
One doesn't. Instead one uses local variables, as you did with 'person'. Your solution is almost complete, actually, and should work if you replace '_.getitem(person.CurrentPosition)' with one of the following (I'm not sure which, you'll need to experiment): person[person.CurrentPosition] getattr(person, person.CurrentPosition) person.aq_acquire(person.CurrentPostion) Sorry I can't be more specific. In general, though, any place you would use dtml-with in DTML, you set up a local variable in PythonMethods. Cheers, Evan @ 4-am & digicool
participants (2)
-
Darran Edmundson -
Evan Simpson