Generalize the python boolean converter so we can use it in RBAC methods

This commit is contained in:
Matthew Jones
2015-01-26 11:57:21 -05:00
parent 9447c092ac
commit b5db74a7d9
3 changed files with 16 additions and 17 deletions

View File

@@ -61,6 +61,16 @@ def get_object_or_403(klass, *args, **kwargs):
except queryset.model.MultipleObjectsReturned, e:
raise PermissionDenied(*e.args)
def to_python_boolean(value, allow_none=False):
value = unicode(value)
if value.lower() in ('true', '1'):
return True
elif value.lower() in ('false', '0'):
return False
elif allow_none and value.lower() in ('none', 'null'):
return None
else:
raise ValueError(u'Unable to convert "%s" to boolean' % unicode(value))
def camelcase_to_underscore(s):
'''