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
- ID in request GET or POST required decorator by markeyev 1 year, 5 months ago
- Ajax required decorator by zenx 3 years, 8 months ago
- Workaround Firefox bug 553888 by peroksid 10 months, 4 weeks ago
- Partial JSON template rendering by barbuza 4 years, 3 months ago
- limit view request rate decorator by anatoliy.larin 2 years, 8 months ago
Comments
is_true = lambda value: bool(value) and value.lower() not in ('false', '0')
is_true(request.POST.get(key))
#