Re: [PythonReports-users] if / else for a field value
Brought to you by:
a1s
From: alexander s. <al...@go...> - 2013-01-02 07:26:17
|
On 01.01.2013 13:13, Werner F. Bruhin wrote: > > In some of my reports I have conditional values, how could I do this in > PythonReports: > > if ru.oCurrentvalue: # variable defined on an import alias "ru" > currentvalue # variable from report data set > else: > lastpurchaseprice # variable from report data set There are several possible ways to achieve that. If you are using Python 2.5 or newer, the simplest way is field expr="currentvalue if ru.oCurrentvalue else lastpurchaseprice". You may also do it using template conditionals: <field expr="currentvalue"> <style printwhen="ru.oCurrentvalue" /> </field> <field expr="lastpurchaseprice"> <style printwhen="not ru.oCurrentvalue" /> </field> Finally, you may create a Python module with any functions you need and import it into your template. Best wishes, alex. |