Get boolean value from request send by Ajax

 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

  1. Get dict's associated value filter by zalun 4 years, 1 month ago
  2. ajax error sink by amitu 4 years, 7 months ago
  3. Ajax required decorator by zenx 5 years ago
  4. A templatetag to insert the output of another view (or local URL) by jamesgpearce 3 years, 11 months ago
  5. Javascript HTTP response by davep 5 years, 10 months ago

Comments

SmileyChris (on July 1, 2009):

is_true = lambda value: bool(value) and value.lower() not in ('false', '0')

is_true(request.POST.get(key))

#

(Forgotten your password?)