[Zope] DTML #var null= problem/patch

Richard Jones richard.jones@fulcrum.com.au
Fri, 26 Feb 1999 11:26:48 +1100


Hi all,

    I'm having trouble getting DTML to format None values the way I want them.

    I have a database table with a bunch of string columns which may be NULL. 
They range in size from 2 characters to 256. I want to be able to edit them in 
a HTML form. The way I've been constructing this form is something like:

<INPUT TYPE="TEXT" NAME="title" VALUE="<!--#var COURSE-->" MAXLENGTH=256 
SIZE=20>
<INPUT TYPE="TEXT" NAME="language" VALUE="<!--#var LANGUAGE null=""-->" 
MAXLENGTH=2 SIZE=2>

   and so on...

   The null="" argument to var doesn't get used unless I supply a fmt= argument 
_and_ that format string fails to format the value. The problem is that the 
representation I want is fmt="%s", and that formats a None value quite nicely. 
I can just hear Jim Fulton saying "this problem disappears using Missing.Value" 
but I don't want to have to integrate Missing.Value into the rest of the 
codebase we have.

   At the moment, I've patched the DT_Var.py render() method so it detects the 
null= argument regardless of the fmt= argument:

*** DT_Var.py.old       Fri Feb 26 11:19:49 1999
--- DT_Var.py   Fri Feb 26 11:19:53 1999
***************
*** 269,274 ****
--- 269,276 ----
                      val = special_formats[fmt](val, name, md)
                  elif fmt=='': val=''
                  else: val = fmt % val
+         elif have_arg('null') and val is None:
+             val = args['null']
  
          # finally, pump it through the actual string format...
          fmt=self.fmt



    YMMV,

       Richard