Re: [Zope] sorting ids in python

2008-12-11 Thread robert rottermann
Garry Saddington schrieb:
 On Tuesday 09 December 2008 03:15, Andreas Jung wrote:
 On 08.12.2008 21:11 Uhr, robert rottermann wrote:
 Garry Saddington schrieb:
 Can anyone help me sort the following by id in a python script?

 for object in context.objectValues(['Folder', 'DTML
 Document','ZipFolder','File','Image']):
 objs=context.objectValues(['Folder',
 'DTMLDocument','ZipFolder','File','Image']) objs.sort()
 for o in objs:
   ..
 huh? Afaik there is no sort order defined on a per-object basis.

 This is my final working solution:
 
 ids = context.objectIds(['Folder', 'DTMLDocument','ZipFolder','File','Image'])
 ids.sort()
 for object in ids:
 object=context.restrictedTraverse(object)
 path=object.absolute_url()
 ...
I think you can have it a little bit easier:
use context.objectItems instead of objectIds
context.objectItems returns (id, object) tuples.

so your solution wold be:
objs = context.objectItems(['Folder', 
'DTMLDocument','ZipFolder','File','Image'])
objs.sort()
for id, object in objs:
 path=object.absolute_url()
robert
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-11 Thread Peter Bengtsson
2008/12/11 robert rottermann [EMAIL PROTECTED]:
 Garry Saddington schrieb:
 On Tuesday 09 December 2008 03:15, Andreas Jung wrote:
 On 08.12.2008 21:11 Uhr, robert rottermann wrote:
 Garry Saddington schrieb:
 Can anyone help me sort the following by id in a python script?

 for object in context.objectValues(['Folder', 'DTML
 Document','ZipFolder','File','Image']):
 objs=context.objectValues(['Folder',
 'DTMLDocument','ZipFolder','File','Image']) objs.sort()
 for o in objs:
   ..
 huh? Afaik there is no sort order defined on a per-object basis.

 This is my final working solution:

 ids = context.objectIds(['Folder', 
 'DTMLDocument','ZipFolder','File','Image'])
 ids.sort()
 for object in ids:
 object=context.restrictedTraverse(object)
 path=object.absolute_url()
 ...
 I think you can have it a little bit easier:
 use context.objectItems instead of objectIds
 context.objectItems returns (id, object) tuples.

 so your solution wold be:
 objs = context.objectItems(['Folder', 
 'DTMLDocument','ZipFolder','File','Image'])
 objs.sort()
 for id, object in objs:
 path=object.absolute_url()
 robert

Personally I prefer to always use objectValues(). Sorting isn't
objectXXX()'s problem. It's something you do in your view.
objs = list(self.objectValues())
objs.sort(lambda x,y: cmp(x.id, y.id))

It's only a matter of time until you need something more advanced
and then you shouldn't
have to change how you use the objectXXX() iterator. E.g.:
objs.sort(lambda x,y: cmp(x.title_or_id().lower(), y.title_or_id().lower()))


-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-11 Thread Andreas Jung

On 11.12.2008 12:28 Uhr, Peter Bengtsson wrote:


Personally I prefer to always use objectValues(). Sorting isn't
objectXXX()'s problem. It's something you do in your view.
objs = list(self.objectValues())
objs.sort(lambda x,y: cmp(x.id, y.id))


Never ever use obj.id. The official API is obj.getId() - nothing
else.

Andreas
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd.  Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[EMAIL PROTECTED]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-09 Thread Garry Saddington
On Tuesday 09 December 2008 03:15, Andreas Jung wrote:
 On 08.12.2008 21:11 Uhr, robert rottermann wrote:
  Garry Saddington schrieb:
  Can anyone help me sort the following by id in a python script?
 
  for object in context.objectValues(['Folder', 'DTML
  Document','ZipFolder','File','Image']):
 
  objs=context.objectValues(['Folder',
  'DTMLDocument','ZipFolder','File','Image']) objs.sort()
  for o in objs:
..

 huh? Afaik there is no sort order defined on a per-object basis.

This is my final working solution:

ids = context.objectIds(['Folder', 'DTMLDocument','ZipFolder','File','Image'])
ids.sort()
for object in ids:
object=context.restrictedTraverse(object)
path=object.absolute_url()
...
.
Thanks everyone
Regards
Garry

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-09 Thread Andreas Jung

On 09.12.2008 8:45 Uhr, Garry Saddington wrote:

On Tuesday 09 December 2008 03:15, Andreas Jung wrote:

On 08.12.2008 21:11 Uhr, robert rottermann wrote:

Garry Saddington schrieb:

Can anyone help me sort the following by id in a python script?

for object in context.objectValues(['Folder', 'DTML
Document','ZipFolder','File','Image']):

objs=context.objectValues(['Folder',
'DTMLDocument','ZipFolder','File','Image']) objs.sort()
for o in objs:
   ..

huh? Afaik there is no sort order defined on a per-object basis.


This is my final working solution:

ids = context.objectIds(['Folder', 'DTMLDocument','ZipFolder','File','Image'])
ids.sort()
for object in ids:
 object=context.restrictedTraverse(object)
 path=object.absolute_url()
...



You were asking about IDs in the first place, so use objectIds().
If you are interested in the object themselves, use objectItems() as RR
suggested.

-aj
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd.  Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[EMAIL PROTECTED]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] sorting ids in python

2008-12-08 Thread Garry Saddington
Can anyone help me sort the following by id in a python script?

for object in context.objectValues(['Folder', 'DTML 
Document','ZipFolder','File','Image']):

Import of sequence is not authorised in my python scripts, I am presuming 
(probably wrongly) that sequence is needed for sort.
Regards
Garry
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-08 Thread Andreas Jung

On 08.12.2008 18:18 Uhr, Garry Saddington wrote:

Can anyone help me sort the following by id in a python script?

for object in context.objectValues(['Folder', 'DTML
Document','ZipFolder','File','Image']):




ids = context.objectIds()
ids.sort()

-aj
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd.  Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[EMAIL PROTECTED]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-08 Thread Andreas Jung

On 08.12.2008 19:23 Uhr, Andreas Jung wrote:

On 08.12.2008 18:18 Uhr, Garry Saddington wrote:

Can anyone help me sort the following by id in a python script?

for object in context.objectValues(['Folder', 'DTML
Document','ZipFolder','File','Image']):




ids = context.objectIds()


Possibly you need

ids = list(context.objectIds())

-aj


ids.sort()
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd.  Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[EMAIL PROTECTED]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-08 Thread robert rottermann
Garry Saddington schrieb:
 Can anyone help me sort the following by id in a python script?
 
 for object in context.objectValues(['Folder', 'DTML 
 Document','ZipFolder','File','Image']):

objs=context.objectValues(['Folder', 'DTMLDocument','ZipFolder','File','Image'])
objs.sort()
for o in objs:
 ..

robert

 
 Import of sequence is not authorised in my python scripts, I am presuming 
 (probably wrongly) that sequence is needed for sort.
 Regards
 Garry
 ___
 Zope maillist  -  Zope@zope.org
 http://mail.zope.org/mailman/listinfo/zope
 **   No cross posts or HTML encoding!  **
 (Related lists - 
  http://mail.zope.org/mailman/listinfo/zope-announce
  http://mail.zope.org/mailman/listinfo/zope-dev )
 
 

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-08 Thread Andreas Jung

On 08.12.2008 21:11 Uhr, robert rottermann wrote:

Garry Saddington schrieb:

Can anyone help me sort the following by id in a python script?

for object in context.objectValues(['Folder', 'DTML
Document','ZipFolder','File','Image']):


objs=context.objectValues(['Folder', 'DTMLDocument','ZipFolder','File','Image'])
objs.sort()
for o in objs:
  ..


huh? Afaik there is no sort order defined on a per-object basis.

-aj
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd.  Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[EMAIL PROTECTED]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] sorting ids in python

2008-12-08 Thread robert rottermann
Andreas Jung schrieb:
 On 08.12.2008 21:11 Uhr, robert rottermann wrote:
 Garry Saddington schrieb:
 Can anyone help me sort the following by id in a python script?

 for object in context.objectValues(['Folder', 'DTML
 Document','ZipFolder','File','Image']):

 objs=context.objectValues(['Folder',
 'DTMLDocument','ZipFolder','File','Image'])
 objs.sort()
 for o in objs:
   ..
 
 huh? Afaik there is no sort order defined on a per-object basis.wh
I *allways* mixup objecItems with objectValues
so its objecItems(..).sort() ..
robert
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )