sequence.sort on a property of contained objects
Hi, I have several zope folders on the FSDV and I want to display their titles in a certain order with a ZPT. Since folders on FSDV can not have property of their own, I created a FS property object, whose id is 'property', in each of the folders. And each 'property' objects contains a property 'menu_order', according to which the folders should be sorted. I try to use the following code to sort the folders: <ul tal:define="folders here/get_folders; sort_on python:(('property/menu_order', 'cmp', 'asc'),); sorted_folders python:sequence.sort(folders, sort_on)"> But it seems the sort condition can not contain path expression to access 'property/menu_order'. It takes the whole as a property of the folder object and wouldn't treat 'property' as an object contained in the folder and get its property 'menu_order'. As a result, no sort is performed. Is there any solution to this except for writing a custom sort function of my own? Thanks, Hong Yuan
--On Samstag, 9. Oktober 2004 22:13 Uhr +0800 Hong Yuan <obichina@21cn.com> wrote:
I try to use the following code to sort the folders: <ul tal:define="folders here/get_folders; sort_on python:(('property/menu_order', 'cmp', 'asc'),); sorted_folders python:sequence.sort(folders, sort_on)">
But it seems the sort condition can not contain path expression to access 'property/menu_order'.
I have no idea why you think that you could use path expression at that point. The documentation of sequence.sort() does not tell you about using path expressions. Andreas
Andreas Jung wrote:
--On Samstag, 9. Oktober 2004 22:13 Uhr +0800 Hong Yuan <obichina@21cn.com> wrote:
I try to use the following code to sort the folders: <ul tal:define="folders here/get_folders; sort_on python:(('property/menu_order', 'cmp', 'asc'),); sorted_folders python:sequence.sort(folders, sort_on)">
But it seems the sort condition can not contain path expression to access 'property/menu_order'.
I have no idea why you think that you could use path expression at that point. The documentation of sequence.sort() does not tell you about using path expressions.
Andreas
I was a little bit confused about the difference beteween an attribute of an object per se and the path expression to get the attribute. So that means that sequence.sort() can only take in an attribute of an object as the sort key and not an attribute of an attribute. It seems that there is not short to do the desired sort in ZPT only, but that I have to write my own sort function in python. Is this correct? Best Regards, Hong Yuan
I am trying to track down some write conflict errors in a Product I am working on. The event.log is telling me (for example): ConflictError: database conflict error (oid 000000000011e870, serial was 0358665aa2650baa, now 0358665a4ba78c99) I would like to find out what class of object is producing the conflict, so I can write an _p_resolveConflict function to handle the problem, but the log doesn't tell me the conflicting objects type. What is the best/easiest way to get type information from the provided OID# ? --Sean
[Sean Hastings]
I am trying to track down some write conflict errors in a Product I am working on.
The event.log is telling me (for example):
ConflictError: database conflict error (oid 000000000011e870, serial was 0358665aa2650baa, now 0358665a4ba78c99)
I would like to find out what class of object is producing the conflict, so I can write an _p_resolveConflict function to handle the problem, but the log doesn't tell me the conflicting objects type.
What is the best/easiest way to get type information from the provided OID# ?
Useful info about FileStorage here: http://zope.org/Wikis/ZODB/FileStorageBackup If you're using FileStorage, the no-brainer approach is to use fsdump.py (see the link), and look for the oid. There are cleverer ways to do the specific thing you want to do right now, but learning to use fsdump can answer many questions.
Sean Hastings wrote at 2004-10-9 13:14 -0400:
I am trying to track down some write conflict errors in a Product I am working on.
The event.log is telling me (for example):
ConflictError: database conflict error (oid 000000000011e870, serial was 0358665aa2650baa, now 0358665a4ba78c99)
I would like to find out what class of object is producing the conflict, so I can write an _p_resolveConflict function to handle the problem, but the log doesn't tell me the conflicting objects type.
If you have a persistent object "o", then "o._p_jar" is its ZODB connection. If you have a ZODB connection "C" and an oid (as a binary string), then "C[oid]" loads the object and returns it. You can use "from binascii import a2b_hex" to convert the oid as given above into a binary string: e.g. "C[a2b_hex('000000000011e870')]" -- Dieter
participants (5)
-
Andreas Jung -
Dieter Maurer -
Hong Yuan -
Sean Hastings -
Tim Peters