[Zope-DB] TAL and empty sql-list

Jimmy small mallaice at gmail.com
Tue Mar 21 09:21:29 EST 2006


sorry for the double post --
A python script would be your best bet.  You would be able to use that
in other areas of your site in that case.

On 3/21/06, Charlie Clark <charlie at egenix.com> wrote:
>
> On 2006-03-20 at 12:01:55 [+0100], Jonas Nielsen <jonasn at mail.tele.dk>
> wrote:
> > I have an sql statement that given a username it returns a project.
> >
> > So my first question is: Is it possible to let the statement return a
> > string instead of a list. i.e. 'project' instead of ['project'] ?
> >
> > So, if call it from a page template, I can use
> >
> > <div tal:content="python:here.project(uname=username)[0].project" />
> >
> > But if the project method returns an empty list, this statement will
> > fail (because of [0]).
>
> > if I'm using, say, the Python Database API I would just call fetchone()
> > on the cursor object. It is that functionality I am looking for.
>
> Yes, it's very frustrating.
>
> You've got two choices: either use a tal:repeat around your content which
> is not only more code but as you point out not always helpful. You can also
> use a Python statement or PythonScript to help you out:
>
> <block tal:define="result python:here.project(uname=username)[0].project or
> ''"></block>
>
> Charlie
> _______________________________________________
> Zope-DB mailing list
> Zope-DB at zope.org
> http://mail.zope.org/mailman/listinfo/zope-db
>


More information about the Zope-DB mailing list