1 2 3 4 5 6 7 8 9 10 11 12 13 |
def get_boolean_from_request(request, key, method='POST'):
" gets the value from request and returns it's boolean state "
value = getattr(request, method).get(key, False)
if value == 'False' or value == 'false' or value == '0' or value == 0:
value = False
elif value:
value = True
else:
value = False
return value
|
More like this
- Get dict's associated value filter by zalun 4 years, 1 month ago
- ajax error sink by amitu 4 years, 7 months ago
- Ajax required decorator by zenx 4 years, 12 months ago
- A templatetag to insert the output of another view (or local URL) by jamesgpearce 3 years, 11 months ago
- Javascript HTTP response by davep 5 years, 10 months ago
Comments
is_true = lambda value: bool(value) and value.lower() not in ('false', '0')
is_true(request.POST.get(key))
#