Exemplo n.º 1
0
def hit_consignment(id):
	form = EventForm()
	h = models.Hit.query.get(id)
	events = range(2)
	if request.method == 'GET':
		#get the following variables from Amazon when the GET request originates from there
		if request.args.get("workerId"): #prevent overwrite on GET via AWS by Tassl Employee
			h.worker_id = request.args.get("workerId") #could break if worker gives up assignment
			h.status = 'in progress'
		if request.args.get("assignmentId") != 'ASSIGNMENT_ID_NOT_AVAILABLE': #prevent overwrite on GET via AWS by Tassl Employee
			h.assignment_id = request.args.get("assignmentId")
		db.session.commit()
		#print "worker id: ", h.worker_id
		#print "assignment id: ", h.assignment_id
		task_id = request.args.get("hitId") #get hitID, as assigned by amazon
		form.host_name.choices, x = get_host_choices(h.school) #dynamically set hosts
		form.event_type.choices, x = get_event_types()
		return render_template('task.html', 
						id = id,
						hit = h,
						hit_id = task_id,
						provided_link= h.url,
						provided_description= h.title,
						worker_id = request.args.get("workerId"), #kept this way to keep non-workers from logging events
						assignment_id = h.assignment_id,
						external_submit_url = os.environ['EXTERNAL_SUBMIT_SANDBOX_URL'],
						events = events,
						maps_key = os.environ['GOOGLE_PLACES_DEV_KEY'],
						form=form)
	if request.method == 'POST':
		h.status = 'reviewable'
		db.session.commit()
		return 'success'
Exemplo n.º 2
0
def logevent():
	eventData = request.get_json() # puts request JSON in a python dict
	e = models.Event()
	for key in eventData:
			setattr(e, key, eventData[key])
	e.hit_id = eventData['eventHit']
	db.session.add(e)
	db.session.commit()
	#need to get host choices on new form
	school_id = e.hit.school
	form = EventForm()
	form.event_type.choices, x = get_event_types()
	form.host_name.choices, x = get_host_choices(school_id)
	#response_html = "<td>" + eventData['event_name'] + "</td><td>" + eventData['start_date'] + "</td></tr>"
	return render_template('event_form.html', form = form)
Exemplo n.º 3
0
def view_hit(id):
	h = models.Hit.query.get(id)
	form = FeedbackForm()
	x, schools_dict = get_school_choices() #get school name from school id stored in HIT
	school = schools_dict[h.school] #needed for proper display of school (name instead of id)
	y, hosts_dict = get_host_choices(h.school) #needed for proper display of host (name instead of id)
	z, event_type_dict = get_event_types() #needed for proper display of event type (name instead of id)
	events = h.events.all()
	events = sorted(events, key = lambda x:x.id) #sort by id
	print event_type_dict
	print events
	return render_template('view_hit.html', 
						hit = h,
						events = events,
						school = school, 
						hosts_dict = hosts_dict,
						schools_dict = schools_dict,
						event_type_dict = event_type_dict,
						form = form)
Exemplo n.º 4
0
def edit_event(id):
	e = models.Event.query.get(id)
	hit_id = e.hit_id #get the id of the Hit the event corresponds to, as indexed by our db
	form = EventForm()
	if request.method == 'GET':
		form = EventForm(obj=e)
		form.host_name.choices, x = get_host_choices(e.hit.school) #populate select field dynamically
		form.event_type.choices, y = get_event_types()
		return render_template('edit_event.html', 
			form = form, 
			event = e, 
			hit_id = hit_id, 
			maps_key = os.environ['GOOGLE_PLACES_DEV_KEY'] )
	if request.method == 'POST':
		for fieldname, value in form.data.items():
			setattr(e, fieldname, value)
			#print fieldname, value
		# print e #sanity test
		db.session.commit()
		dest = '/hits/' + str(hit_id)
		print dest
		return redirect(dest) #no idea why url_for doesn't work here