View Single Post
Old 10-10-2013, 03:51 PM   #7
kcz
Member
kcz began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Oct 2013
Device: Kindle
Quote:
Originally Posted by chaley View Post
Defining a user-defined function is usually driven by complexity or performance. Sometimes the template language doesn't have the power to do what is needed or the solution is so cumbersome that it is absurd. Sometimes the performance of the template language solution is unacceptable, which can happen when several "test" conditions are being evaluated because the template interpreter does not shortcut. All arguments (conditions) are computed, then the conditions are evaluated.
I have created a user defined template function called format_index with 1 argument. Here is the code:

Code:
def evaluate(self, formatter, kwargs, mi, locals, val):
    return re.sub('\.00', '', format_number(field(val), '[[0:05.2f]]'), flags=re.I)
The template in the custom column looks like this:

{series_index:format_index()}

Unfortunately I get the following error:

TEMPLATE ERROR global name 're' is not defined

Any idea what the problem is?
kcz is offline   Reply With Quote