[ZPT] Re: Help with tal:condition please

Tres Seaver tseaver at palladion.com
Mon Sep 5 12:50:29 EDT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jon Bowlas wrote:
> Hi All,
> 
> I've written the snip of code below but I cant get it work, can anyone point
> out my glaring error?
> 
> This code should display the first readonly input field if the Id of the
> object is either uclattributes or uclaudjectsfilter, otherwise it should
> display the editable field.
> 
> 
> <tal:editableids tal:define="objId object/getId;
> 	     isatts python:objId=='uclattributes';
> 	     isaudjects python:objId=='uclaudjectsfilter'">
> 			<input tal:condition="python: isatts or isaudjects"
> type="text" name="name"
> style="width: 100%" value="value" tal:attributes="name
> string:id_${object/getId}; value 			object/getId"
> readonly="readonly" />
> 			<input tal:condition="python: not isatts or
> isaudjects" type="text" name="name"
> style="width: 100%" value="value" tal:attributes="name
> string:id_${object/getId}; value 			object/getId" />
> </tal:editableids>
> 
> However it seems to work fine for the object with the 'uclattributes' Id,
> but it displays both fields when it encounters an object with the Id
> 'uclaudjectsfilter'.
> 
> Hope somebody can help.
> 
> Jon

You have a precedence problem in the last condition.  Here is Python
code which demonstrates it::

 $ python
 Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
 [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> def foo(objId):
 ...     isatts = objId == 'uclattributes'
 ...     isaudjects = objId == 'uclaudjectsfilter'
 ...     print 'readonly: ', isatts or isaudjects
 ...     print 'editable: ', not isatts or isaudjects
 ...
 >>> foo('xyzzy')
 readonly:  False
 editable:  True
 >>> foo('uclattributes')
 readonly:  True
 editable:  False
 >>> foo('uclaudjectsfilter')
 readonly:  True
 editable:  True


Tres.
- --
===================================================================
Tres Seaver          +1 202-558-7113          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD4DBQFDHHdV+gerLs4ltQ4RAiQwAJiqyv7gNSY1eGd0QSbHr4ltrpgLAJ49qeLs
fE7UJ4qNvT3lKLAzmUviog==
=Kobr
-----END PGP SIGNATURE-----



More information about the ZPT mailing list