WIP. fix for ambiguous assignment id

This commit is contained in:
Ruben van de Ven 2020-01-22 19:58:33 +01:00
parent ac96bbff64
commit a9f82a5feb
2 changed files with 28 additions and 2 deletions

View file

@ -197,6 +197,14 @@ class Assignment(Base):
values['turk_country_code'] = None values['turk_country_code'] = None
return values return values
def getOriginalAssignmentId(self):
"""
Initial assumption: assignmentId would be unique for each worker. But it is not.
Hence assignment_id now gets the value assigmentId_workerId (confusing to say the least!)
Sometimes we want to recover the assignment id from this combination
"""
return self.assignment_id.split('_')[0]
class Store: class Store:
def __init__(self, db_filename, logLevel=0): def __init__(self, db_filename, logLevel=0):
path = os.path.abspath(db_filename) path = os.path.abspath(db_filename)

View file

@ -309,6 +309,24 @@ class DrawPageHandler(tornado.web.RequestHandler):
try: try:
hit_id = int(self.get_query_argument('id')) hit_id = int(self.get_query_argument('id'))
if hit_id != self.store.currentHit.id: if hit_id != self.store.currentHit.id:
assignmentId = self.get_query_argument('assignmentId', '')
orig_assigmentId = assignmentId
if len(assignmentId):
assignmentId += '_' + str(self.get_query_argument('workerId', ''))
hit = self.store.getHitById(hit_id)
assignment = hit.getAssignmentById(assignmentId)
if not assignment:
self.write("Invalid HIT or assignment id")
return
submitUrl = self.get_query_argument('turkSubmitTo', '')
submitUrl += '/mturk/externalSubmit'
self.write("An error occured. Please re-submit your assignment validation code. We're really sorry for the inconvenience.")
self.write(f"<form method='post' action='{submitUrl}'>")
self.write(f"<input type='text' name='assignmentId' value='{orig_assigmentId}'>")
self.write(f"<input type='text' name='surveycode' value='{assignment.uuid}'>")
self.write(f"<input type='submit' value='Submit finished assignment'>")
self.write("</form>")
self.write("Invalid HIT") self.write("Invalid HIT")
return return
hit = self.store.currentHit hit = self.store.currentHit
@ -320,7 +338,7 @@ class DrawPageHandler(tornado.web.RequestHandler):
return return
assignmentId = self.get_query_argument('assignmentId', '') assignmentId = self.get_query_argument('assignmentId', '')
if len(assignmentId): if len(assignmentId) and assignmentId != "ASSIGNMENT_ID_NOT_AVAILABLE":
assignmentId += '_' + str(self.get_query_argument('workerId', '')) assignmentId += '_' + str(self.get_query_argument('workerId', ''))
if len(assignmentId) < 1: if len(assignmentId) < 1:
@ -360,7 +378,7 @@ class DrawPageHandler(tornado.web.RequestHandler):
.replace("{TOP_PADDING}", str(self.top_padding))\ .replace("{TOP_PADDING}", str(self.top_padding))\
.replace("{LEFT_PADDING}", str(self.left_padding))\ .replace("{LEFT_PADDING}", str(self.left_padding))\
.replace("{SCRIPT}", '' if previewOnly else '<script type="text/javascript" src="/assignment.js"></script>')\ .replace("{SCRIPT}", '' if previewOnly else '<script type="text/javascript" src="/assignment.js"></script>')\
.replace("{ASSIGNMENT}", '' if previewOnly else str(assignmentId)) # TODO: fix unsafe inserting of GET variable .replace("{ASSIGNMENT}", '' if previewOnly else str(assignment.getOriginalAssignmentId())) # TODO: fix unsafe inserting of GET variable
self.write(contents) self.write(contents)