Quote:
Originally Posted by readin
But I'm stuck on this one:
Code:
name: icon_if_val
arg count: 3
doc: icon_if_val(field, val, icon) -- if 'field' contains 'val', returns icon filename ('icon' + '.png'), else returns 'blank.png'
program code:
def evaluate(self, formatter, kwargs, mi, locals, field, val, icon):
import re
if re.search(val, mi.get(field)):
return icon + '.png'
return 'blank.png'
Result:
EXCEPTION: expected string or buffer
|
You didn't supply a call example, but I can see one potential problem. If 'field' is like tags then the result from mi.get will be an array (in python a 'list'), not a string. If you know that 'field' is always 'like tags' then you can solve this problem using
Code:
import re
f = ','.join(mi.get(field))
if re.search(val, f):
If you don't know then you can do something like
Code:
import re
f = mi.get(field)
if isinstance(f, list):
f = ','.join(f)
if re.search(val, f):
We are getting very technical here.