[Zope] Propblem with script from Zope book

Geir Bækholt Geir Bækholt
Fri, 11 Apr 2003 23:06:53 +0200


On  Fri, 11 Apr 2003 16:57:24 -0400 GMT (..22:57 where i live(GMT+2) )
Jamie asked the Zope mailinglist about the following:

J> I changed it around to fit my purposes (I am trying to build a DTML
J> Method that changes the order my Content objects are displayed in. The
J> objects are sorted by an integer property called SortOrder. So far the
J> DTML Method returns a value for SortOrder of the object to be moved up,
J> this is the variable SortNum. Eventually I would like to be able to move
J> items up or down in the sort order from this method, but am trying to
J> get it working just moving them up first then I will worry about moving
J> them down. What I need is this script to find the id of the object with
J> a SortOrder of SortNum. Then I can determine the objects with
J> SortOrder's either above or below the one to move and change the
J> SortOrder of all objects effected by the move.

You want to interate through a sequence of 'Content' objects and
return the first one you hit that has SortOrder equal to SortNum ?
(You seem to know that one exists, and that there is only one..)

will this (untested) do the job ?

for object in context.objectValues('Content'):
    if object.SortOrder == SortNum:
        return object
return "no matching object found"




--
Geir Bækholt