Getting the position of an object in a folder
Is there a simple and direct way to get the position of an object in a parent folder without iterating with a dtml-in loop through all the objects of the folder and countring until one gets to the id of the said object? Thanks in advance and my apologies for a newbie question... Pierre Godefroy 52 rue des Archives 75004 PARIS FRANCE Tél. : +33 (0)1 42 74 46 05
Pierre Godefroy wrote:
Is there a simple and direct way to get the position of an object in a parent folder without iterating with a dtml-in loop through all the objects of the folder and countring until one gets to the id of the said object?
a little python-script should do this trick for you: return context.objectIds().index('standard_html_header') cheers, maik -- Maik Jablonski __o www.zfl.uni-bielefeld.de _ \<_ Deutsche Zope User Group Bielefeld, Germany (_)/(_) www.dzug.org
Maik Jablonski wrote:
Pierre Godefroy wrote:
Is there a simple and direct way to get the position of an object in a parent folder without iterating with a dtml-in loop through all the objects of the folder and countring until one gets to the id of the said object?
a little python-script should do this trick for you:
return context.objectIds().index('standard_html_header')
Beware that this is not guaranteed to result always the same index, as objectIds is something like dict.keys(). The order of the elements in a mapping is not fixed. HTH, __Janko
Janko Hauser writes:
return context.objectIds().index('standard_html_header')
Beware that this is not guaranteed to result always the same index, as objectIds is something like dict.keys(). The order of the elements in a mapping is not fixed. "objectIds" (and friends) does not come from a dict but from a tuple, at least for the standard folders...
Dieter
Dieter Maurer wrote:
Janko Hauser writes:
return context.objectIds().index('standard_html_header')
Beware that this is not guaranteed to result always the same index, as objectIds is something like dict.keys(). The order of the elements in a mapping is not fixed. "objectIds" (and friends) does not come from a dict but from a tuple, at least for the standard folders...
I stand corrected, it's actually a tuple of dictionaries (self._objects) from which the relevant values are extracted Sorry for the confusion __Janko
participants (4)
-
Dieter Maurer -
Janko Hauser -
Maik Jablonski -
Pierre Godefroy