def checkbox_to_value(option, value_on=1, value_off=0):
 if isinstance(option, list):
  option = option[(-1)]
 if isinstance(option, (str, unicode)):
  option = str(option).strip().lower()
 if (option in (True, 'on', 'true', '1', value_on)):
  return value_on
 return value_off

def checkbox_to_value ( option , value_on = 1 , value_off = 0 ) : if isinstance ( option , list ) : option = option [ ( - 1 ) ] if isinstance ( option , ( str , unicode ) ) : option = str ( option ) . strip ( ) . lower ( ) if ( option in ( True , 'on' , 'true' , '1' , value_on ) ) : return value_on return value_off
turns checkbox option on or true to value_on (1) any other value returns value_off (0) .