The available functions are listed herein. Note that the from future import division causes integer division expressions to be evaluated as floats. For example "1/2" evaluates as 0.5 when it would otherwise have evaluated to 0 (assuming Python 2.X).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

from__future__importdivisionfromdjangoimportformsfrommathimport*safe_list=['math','acos','asin','atan','atan2','ceil','cos','cosh','de grees','e','exp','fabs','floor','fmod','frexp','hypot','ldexp','log','log10','modf','pi','pow','radians','sin','sinh','sqrt','tan','tanh']safe_dict=dict([(k,locals().get(k,None))forkinsafe_list])safe_dict['abs']=absclassMathFloatField(forms.FloatField):"FloatField which allows math expressions"defclean(self,value):try:returnfloat(eval(value,{"__builtins__":None},safe_dict))except:raiseforms.ValidationError("Enter a number or math expression")