Beispiel #1
0
def event_checkin(request):
	print('Checkin in progress')
	if request.is_ajax():
	#Start with gather the information from the request.
		action = request.POST['action']
		member_id = request.POST['member_id']
		event_id = request.POST['event_id']
		role_id = request.POST['role_id']
		event_role_id = request.POST['event_role_id']

		event_role = get_object_or_404(EventRole, id=event_role_id)
		print(event_role)
		#member = User.objects.get(id=2)
		#print(member)

		if action == 'attend':
			act = 'Y'
			try:
				ma = MemberAttendance.objects.get(event_role_id=event_role_id, member_id=member_id)
				print('>> MemberAttendance {} found'.format(ma))
				ma.response=act
			except Exception as e:
				ma = MemberAttendance(event_role_id=event_role_id, member_id=member_id, attendance=act,time_checkin = datetime.now())
				print('>> No MemberAttendance found. Creating a new one: {}'.format(ma))
				print(e)
				try:
					ma.clean_fields()
					ma.save()
					print('>> SAVED')
				except Exception as e:
					print('>> FAILED')
					print(e)
					return HttpResponse('Failed: could not save member response')
		elif action == 'checkout':
			try:
				ma = MemberAttendance.objects.get(event_role_id=event_role_id, member_id=member_id,)
				ma.time_checkout= datetime.now()
				ma.save()
			except Exception as e:
				print(act)
		
		attendance = MemberAttendance.objects.get(event_role_id=event_role_id, member_id=member_id)
		time_checkin = attendance.time_checkin
		time_checkout = attendance.time_checkout
		print(time_checkin)
		print(time_checkout)

		# Tooltip for times configured
		if time_checkout != None:
			tooltip = "INN: "+str(formats.date_format(time_checkin, 'TIME_FORMAT'))+"\n  ÚT: "+str(formats.date_format(time_checkout, 'TIME_FORMAT'))
		else :
			tooltip = "INN: "+str(formats.date_format(time_checkin, 'TIME_FORMAT'))
		print(tooltip)

		#print(time_inn)

		

	#print(event_role)
	data = {
		'action_r': action,
		'tooltip': tooltip
		}
	jsondata = json.dumps(data)
	return HttpResponse(json.dumps(data))