[Zope] Getting counts from a ZCatalog - it must be easier than my feeble attempt!

S.Wilson s.wilson@bangor.ac.uk
Fri, 03 Aug 2001 16:39:37 +0100


The sticking point is that "len" is not a recognised namespace item when
called from dtml-var.

The [0] actually refers to the first MyBrain instance in the LazyMap that
this method returns when called from within a Python script.

As an aside, if you just want to get the id of the first item in a results
set in a python script you can use mycatalog({myquery})[0][0] -
occasionally handy even if it does look like a hack. For example in my
custom 404 page:

#
# see if the last element of the url after the / is the name of a Group
# in the Group catalog.
# if so, redirect the user to the homepage for that Group
#
sPath = request.URLPATH0
sPath = sPath[-(len(sPath)-1):]
if (context.groupCatalog.searchResults({'Name':sPath}) ):
  groupid = context.groupCatalog({'Name':sPath})[0][0]
  sUrl='/templates/group?groupid=' + groupid
  response.redirect(sUrl,lock=1)


Erik Enge wrote:

> | <dtml-var
> | expr="len(articleIndex({'SubjectContext':_.getitem('sequence-item')})[0])">
> 
> Isn't that because you have that [0] added to the back of that
> sequence?