Filter isn't played for None value

Thibaud Roussillat <[email protected]> Wed, 9 Nov 2011 13:59:02 +0100
Newsgroups gmane.comp.python.cheetah
Message-ID <CAMDdHNf4Wo5h76Se75iuDXWPUUsRo-LT6wTzW3UvnP=99Qmy9w@mail.gmail.com>
--===============1438562264970976270==
Content-Type: multipart/alternative; boundary=0015174be2262417f604b14cdac4

--0015174be2262417f604b14cdac4
Content-Type: text/plain; charset=ISO-8859-1

Hello,

I have to apply filter to placeholders which can have None value. However,
the filter isn't apply.

For example :

import Cheetah.Template
from Cheetah.Filters import Filter

class MyFilter(Filter):

    def filter(self, val, **kw):

        return "tit"


if __name__ == '__main__':

    print "test01"

    searchList=[{'myvar1': u'test'}, {'myvar2': None}]

    t = Cheetah.Template.Template('''
        1. -${getVar('myvar1', '456')}-
        2. -${getVar('myvar2', ''), maxlen=2}-
        3. -${getVar('myvar3', None), maxlen=2}-
        ''', searchList,
        filter=MyFilter
        )
    print t

The output is as follow :

1. -tit-
2. --
3. --

Is there any way to apply filter to None value ?

Thanks a lot.

Thibaud

--0015174be2262417f604b14cdac4
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hello,<br><br>I have to apply filter to placeholders which can have None va=
lue. However, the filter isn&#39;t apply.<br><br>For example :<br><br><span=
 style=3D"font-family: courier new,monospace;">import Cheetah.Template</spa=
n><br style=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">from Cheetah.Filters im=
port Filter</span><br style=3D"font-family: arial,helvetica,sans-serif;"><b=
r style=3D"font-family: arial,helvetica,sans-serif;"><span style=3D"font-fa=
mily: courier new,monospace;">class MyFilter(Filter):</span><br style=3D"fo=
nt-family: courier new,monospace;">
<br style=3D"font-family: courier new,monospace;"><span style=3D"font-famil=
y: courier new,monospace;">=A0=A0=A0 def filter(self, val, **kw):</span><sp=
an style=3D"font-family: courier new,monospace;"></span><br style=3D"font-f=
amily: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 <=
/span><br style=3D"font-family: courier new,monospace;"><span style=3D"font=
-family: courier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 return &quot;tit&quo=
t;</span><br style=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 <=
/span><span style=3D"font-family: courier new,monospace;"></span><br style=
=3D"font-family: courier new,monospace;"><br style=3D"font-family: courier =
new,monospace;"><span style=3D"font-family: courier new,monospace;">if __na=
me__ =3D=3D &#39;__main__&#39;:</span><br style=3D"font-family: courier new=
,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0 </span><br st=
yle=3D"font-family: courier new,monospace;"><span style=3D"font-family: cou=
rier new,monospace;">=A0=A0=A0 print &quot;test01&quot;</span><br style=3D"=
font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0 </span><br st=
yle=3D"font-family: courier new,monospace;"><span style=3D"font-family: cou=
rier new,monospace;">=A0=A0=A0 searchList=3D[{&#39;myvar1&#39;: u&#39;test&=
#39;}, {&#39;myvar2&#39;: None}]</span><span style=3D"font-family: courier =
new,monospace;"></span><br style=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0 </span><br st=
yle=3D"font-family: courier new,monospace;"><span style=3D"font-family: cou=
rier new,monospace;">=A0=A0=A0 t =3D Cheetah.Template.Template(&#39;&#39;&#=
39;</span><br style=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 1=
. -${getVar(&#39;myvar1&#39;, &#39;456&#39;)}-</span><br style=3D"font-fami=
ly: courier new,monospace;"><span style=3D"font-family: courier new,monospa=
ce;">=A0=A0=A0=A0=A0=A0=A0 2. -${getVar(&#39;myvar2&#39;, &#39;&#39;), maxl=
en=3D2}-</span><br style=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 3=
. -${getVar(&#39;myvar3&#39;, None), maxlen=3D2}-</span><br style=3D"font-f=
amily: courier new,monospace;"><span style=3D"font-family: courier new,mono=
space;">=A0=A0=A0=A0=A0=A0=A0 &#39;&#39;&#39;, searchList,</span><br style=
=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 f=
ilter=3DMyFilter</span><br style=3D"font-family: courier new,monospace;"><s=
pan style=3D"font-family: courier new,monospace;">=A0=A0=A0=A0=A0=A0=A0 )</=
span><br style=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">=A0=A0=A0 print t</span=
><br><br><font face=3D"arial,helvetica,sans-serif">The output is as follow =
:<br><br><span style=3D"font-family: courier new,monospace;">1. -tit-</span=
><br style=3D"font-family: courier new,monospace;">
<span style=3D"font-family: courier new,monospace;">2. --</span><br style=
=3D"font-family: courier new,monospace;"><span style=3D"font-family: courie=
r new,monospace;">3. --</span><br><br style=3D"font-family: arial,helvetica=
,sans-serif;" clear=3D"all">
</font>Is there any way to apply filter to None value ?<br><br>Thanks a lot=
.<br><br>Thibaud<br><br>

--0015174be2262417f604b14cdac4--


--===============1438562264970976270==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
--===============1438562264970976270==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss

--===============1438562264970976270==--