Propblem with script from Zope book
I'm having problems running this example script from the Zope Book, Advanced Scripting Chapter, p. 183 """ Returns all sub-objects that have a given status property. """ results=[] for object in context.objectValues(): if object.getProperty('status') == status: results.append(object) return results It seems to be starting an endless loop or something, the browser can sit for a half an hour and still not change. Jamie White Jamie@brobus.net
On Fri, 11 Apr 2003 11:20:53 -0400 GMT (..17:20 where i live(GMT+1) ) Jamie asked the Zope mailinglist about the following: J> I'm having problems running this example script from the Zope Book, J> Advanced Scripting Chapter, p. 183 J> """ J> Returns all sub-objects that have a given status J> property. J> """ J> results=[] J> for object in context.objectValues(): J> if object.getProperty('status') == status: J> results.append(object) J> return results J> It seems to be starting an endless loop or something, the browser can J> sit for a half an hour and still not change. Might just be that your loops finds no objects for which status == status.. When a script returns false (0, None, empty list etc.. ) the browser does not get any visible response... try changing this one line: results=[] to results=["dummy"] and see if it still hangs.... :) -- Geir Bækholt
The script will run now but it just returns ['dummy'] I changed it around to fit my purposes (I am trying to build a DTML Method that changes the order my Content objects are displayed in. The objects are sorted by an integer property called SortOrder. So far the DTML Method returns a value for SortOrder of the object to be moved up, this is the variable SortNum. Eventually I would like to be able to move items up or down in the sort order from this method, but am trying to get it working just moving them up first then I will worry about moving them down. What I need is this script to find the id of the object with a SortOrder of SortNum. Then I can determine the objects with SortOrder's either above or below the one to move and change the SortOrder of all objects effected by the move. results=['dummy'] for object in context.objectValues('Content'): if object.propertysheets.userProperties.getProperty('SortOrder') == SortNum results.append(object) return results Any ideas? Jamie White Jamie@brobus.net -----Original Message----- From: Geir Bækholt [mailto:lists@elvix.com] Sent: Friday, April 11, 2003 11:45 AM To: Jamie on The Zope Mailinglist Cc: Zope mailinglist Subject: Re: [Zope] Propblem with script from Zope book On Fri, 11 Apr 2003 11:20:53 -0400 GMT (..17:20 where i live(GMT+1) ) Jamie asked the Zope mailinglist about the following: J> I'm having problems running this example script from the Zope Book, J> Advanced Scripting Chapter, p. 183 J> """ J> Returns all sub-objects that have a given status J> property. J> """ J> results=[] J> for object in context.objectValues(): J> if object.getProperty('status') == status: J> results.append(object) J> return results J> It seems to be starting an endless loop or something, the browser can J> sit for a half an hour and still not change. Might just be that your loops finds no objects for which status == status.. When a script returns false (0, None, empty list etc.. ) the browser does not get any visible response... try changing this one line: results=[] to results=["dummy"] and see if it still hangs.... :) -- Geir Bækholt
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
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..) it doesn't do it, it returns no matching object found. Though I know that there is a Content object with the value I used for SortNum 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
On Fri, 11 Apr 2003 17:26:40 -0400 GMT (..23:26 where i live(GMT+2) ) Jamie asked the Zope mailinglist about the following: J> it doesn't do it, it returns no matching object found. Though I know J> that there is a Content object with the value I used for SortNum
J> will this (untested) do the job ?
J> for object in context.objectValues('Content'): J> if object.SortOrder == SortNum: J> return object J> return "no matching object found"
Are you sure your SortNums are of the same type ? "2" and 2 are not equal.. ;) If you just pass it in a a request parameter, it defaults to a string. check this one: http://www.zope.org/Members/Zen/howto/FormVariableTypes and you can try making yourself some debugging script: for object in context.objectValues('Content'): print "object.SortOrder is %s and SortNum is %s" %(object.SortOrder, SortNum) return printed vary as needed to investigate what fails :) -- Geir Bækholt
participants (2)
-
Geir Bækholt -
Jamie