[Zope] Python script check for existence of variable - there has to be a better way to do this.
Paul Zwarts
paz@oratrix.com
Thu, 13 Jun 2002 11:27:50 +0200
Greetings Ria,
Do you mean you want <dtml-var variable null=""> ??
Cheers,
Paz
-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org] On Behalf Of Ria
Marinussen
Sent: Thursday, June 13, 2002 11:24 AM
To: 'zope@zope.org'
Subject: [Zope] Python script check for existence of variable - there
has to be a better way to do this.
Hi,
In a database I have some information about our employees. Some fields
are
not filled in, so there value is NULL.
When iterating over the results of a ZSQL query (select * from
"Medewerkers") the non-existent variables (value=NULL) are reported with
the
word "None".
I don't want show this keyword in my report-table, so I've created a
python
script that checks for the existence of the variable, and when it
doesn't
exist, I fill in a non-breaking space html -code.
Basically I do two things in the script: I check the parameter and
generate
the name of the variable (that has to be checked)based on the parameter
entered. Next I generate the output and return it.
I'm convinced that the first part (check parameter, generate
variablenaam to
check) can be done in a more elegant way (less code), but trying to
concatenate the value of the parameter to "context." isn't working....
Ideas, anyone?
I use this (and more) in my dtml-document:
<table>
<tr>
<td><dtml-var "bestaat(test='voorletters')"></td>
<td><dtml-var "bestaat(test='voorvoegsel')"></td>
<td><dtml-var "bestaat(test='achternaam')"></td>
</tr>
</table>
The script is named "bestaat":
## Parameter list test
## Bound Names context, container, script, _, traverse_subpath
# Check the input and set the variable to check
if test == 'voorletters':
quest = context.voorletters
elif test == 'voorvoegsel':
quest = context.voorvoegsel
elif test == 'titel':
quest = context.titel
elif test == 'telefoon':
quest = context.telefoon
elif test == 'telefoon_bgg':
quest = context.telefoon_bgg
elif test == 'login':
quest = context.login
elif test == 'leerstoel':
quest = context.leerstoel
elif test == 'kamernr':
quest = context.kamernr
elif test == 'geslacht':
quest = context.geslacht
elif test == 'foto':
quest = context.foto
elif test == 'faculteit1':
quest = context.faculteit1
elif test == 'faculteit2':
quest = context.faculteit2
elif test == 'emailadres':
quest = context.emailadres
elif test == 'achternaam':
quest = context.achternaam
else:
quest = 'missing'
# Generate the output
if not quest:
regel=' '
else:
regel=quest
return regel
TIA,
Ria Marinussen
Webmaster Department of Computer Science
University of Twente
The Netherlands
_______________________________________________
Zope maillist - Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope-dev )