Exemplo n.º 1
0
def stats(request, arg=None):
	country = ''
	data = {}
	# Alert-box type
	if str(request.get_full_path()).endswith('?v'):
		data['type'] = 'success'
		data['alert_info'] = 'Vote counted correctly'
	if str(request.get_full_path()).endswith('?d'):
		data['type'] = 'error'
		data['alert_info'] = 'Vote unaccounted'
	if str(arg) == '':
		country = 'all'
	else:
		country = str(arg).replace('/', '')
	poll = Poll.get_by_key_name(country)
	if poll is None:
		# The country not exits
		data['type'] = 'warning'
		data['alert_info'] = 'No data for that country'
		poll = Poll.get_by_key_name('all')
	if poll is not None:
		data['country']=poll.country
		total = poll.clockwise + poll.counter_clockwise
		data['clockwise'] = poll.clockwise*100/total
		data['counter_clockwise'] = poll.counter_clockwise*100/total
		countries = []
		for p in Poll.all():
			countries.append(p.country)
		data['countries']=countries
	response = render_to_response('countries.html',data)
	return response
Exemplo n.º 2
0
		def allVote():
			poll = Poll.get_by_key_name('all')
			if poll is None:
				poll = Poll(key_name='all')
				poll.country = 'all'
				poll.clockwise = 0
				poll.counter_clockwise = 0
			if choice == 'clockwise':
				poll.clockwise += 1
			else:
				poll.counter_clockwise += 1
			poll.put()
Exemplo n.º 3
0
		def countryVote():
			poll = Poll.get_by_key_name(country)
			if poll is None:
				poll = Poll(key_name=country)
				poll.country = country
				poll.clockwise = 0
				poll.counter_clockwise = 0
			if choice == 'clockwise':
				poll.clockwise += 1
			else:
				poll.counter_clockwise += 1
			poll.put()