0

I am trying to have 2 Tal Conditional statements that check to see if the code is one of 2 things, and then perform the according calculations. but what happens is that it prints out the results of both conditionals side by side.

Thanks!

Unit    4.5522 0.0000
unit.. . 3.7628 0.0000
Unit     0.0000 14.6083
unit     0.0000 31.9430
<td style="text-align: right;">
  <span tal:condition="python:float(result.totdirrn)!=0 and (result.wkld1_desc!='Proceedures' and result.wkld1_desc!='Visits')">
  <span tal:replace="python:'%.4f'%(float(result.cenmn)/((((float(result.dirhrs)*(float(float(result.totdirrn)/float(result.dirhrs))))/14)/12)/2))">currentindex</span>
  <span tal:condition="python:float(result.totdirrn)!=0 and (result.wkld1_desc!='Census')">
  <span tal:replace="python:'%.4f'%(float(result.vipr)/((((float(result.dirhrs)*(float(float(result.totdirrn)/float(result.dirhrs))))/14)/12)/2))">currentindex</span></span>

  </span>
  <span tal:condition="python:(float(result.totdirrn)==0)">
  <span tal:replace="python:'%.1f'%(0.0)"></span></span>
</td>
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
John
  • 45
  • 1
  • 5

1 Answers1

1

It is rather unclear what you are trying to do, or what your expected output is. I've addressed general issues with your template code, lets see if that addresses your issues:

It appears you have your opening and closing <span/> tags muddled up. Currently your structure looks like:

<span condition>
    <span replace></span>
    <span condition>
        <span replace></span>
    </span>
<span>
<span condition>
    <span replace></span>
</span>

while I suspect you really wanted:

<span condition>
    <span replace></span>
<span>
<span condition>
    <span replace></span>
</span>
<span condition>
    <span replace></span>
</span>

You can combine the conditional spans with tal:content attributes instead of replacing nested <span> tags, forming:

<span condition content></span>
<span condition content></span>
<span condition content></span>

or, applied to your sample code, with some improvements to make things a little more readable:

<td style="text-align: right;"
      tal:define="desc result/wkld1_desc;
                  totdirrn python:float(result.totdirrn);
                  cenmn python:float(result.cenmn);
                  dirhrs python:float(result.dirhrs);
                  vipr python:float(result.vipr);
                 ">
  <span tal:condition="python:totdirrn and desc not in ('Proceedures', 'Visits')"
        tal:content="python:'%.4f' % (cenmn / (dirhrs * (totdirrn / dirhrs) / 336))">currentindex</span>
  <span tal:condition="python:totdirrn and desc != 'Census'" 
        tal:content="python:'%.4f' % (vipr / (dirhrs * (totdirrn / dirhrs) / 336))">currentindex</span>
  <span tal:condition="python:not totdirrn">0.0</span>
</td>

You perhaps want to make sure that those for float results are already floating point values and avoid all those float() calls in your view.

Also take into account that floating point values could be not quite zero, a value of 0.000001 is not equal to 0 but would be printed as 0.000 if you ask for a precision of 4 digits behind the comma.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • I will look at this and see how it works! thanks for the reply! What i was trying to do is have it choose one equation or the other, based off of which workload the unit is in. and if the equation divides by 0, then it gives me a 0.0 the 4 decimal places is just something i had in there. – John Jul 18 '13 at 19:28
  • I tested this and I am getting operation errors claiming that one of those floats in the denominator is a string. – John Jul 18 '13 at 19:38