def recreateHIT(id): h = models.Hit.query.get(id) h.status = 'expired' #set HIT to 'expired' in our DB db.session.commit() mturk.expire_hit(h.hit_id) #expire old HIT in Amazon form = CreateHITForm() if request.method == 'GET': #populate with existing data form = CreateHITForm(obj=h) form.school.choices, x = get_school_choices() return render_template('create_HIT.html', form=form) if request.method == 'POST': q = models.Hit() #need to create a new model with our DB first q.title = form.title.data q.url = form.url.data q.status = "open" q.bounty = form.bounty.data q.instructions = form.instructions.data q.keywords = form.keywords.data q.created_at = datetime.datetime.now() q.deadline = int(form.deadline.data) q.school = form.school.data db.session.add(q) db.session.commit() #then need to return a URL, title, keywords, bounty, used to create the HIT in Amazon #create_task(id, title, description, keywords, deadline, bounty) AWS_id = create_task(q.id, q.title, q.instructions, q.keywords.split(','), q.deadline, q.bounty) #then need to update our DB with the task-ID as assigned by Amazon q.hit_id = AWS_id db.session.commit() return redirect(url_for('all_hits')) #can be changed later
def createHIT(): form = CreateHITForm() if request.method == 'GET': form.school.choices, x = get_school_choices() return render_template('create_HIT.html', form=form) if request.method == 'POST': h = models.Hit() #need to create with our DB first h.title = form.title.data h.url = form.url.data h.status = "open" h.bounty = form.bounty.data h.instructions = form.instructions.data h.keywords = form.keywords.data h.created_at = datetime.datetime.now() h.deadline = int(form.deadline.data) h.school = form.school.data db.session.add(h) db.session.commit() #then need to return a URL, title, keywords, bounty, used to create the HIT in Amazon #create_task(id, title, description, keywords, deadline, bounty) AWS_id = create_task(h.id, h.title, h.instructions, h.keywords.split(','), h.deadline, h.bounty) #then need to update our DB with the task-ID as assigned by Amazon h.hit_id = AWS_id db.session.commit() return redirect(url_for('all_hits')) #can be changed later
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)