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]).

So what is a smart solution to this ? I've tried putting a repeat statement around this, and tried defining a variable called projectExist using len on the function. This however makes the page template very complex when calling another sql method such as:

<div tal:python:here.membersInSectionAndProject(section=sectionList[0].section,
                               project=projectList[0].project)" />

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.

Zope-DB mailing list

Reply via email to