From a9f82a5feb50d0401a95d27120111227a88c90be Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Wed, 22 Jan 2020 19:58:33 +0100 Subject: [PATCH] WIP. fix for ambiguous assignment id --- sorteerhoed/HITStore.py | 8 ++++++++ sorteerhoed/webserver.py | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/sorteerhoed/HITStore.py b/sorteerhoed/HITStore.py index f557fb0..4ea1556 100644 --- a/sorteerhoed/HITStore.py +++ b/sorteerhoed/HITStore.py @@ -197,6 +197,14 @@ class Assignment(Base): values['turk_country_code'] = None 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: def __init__(self, db_filename, logLevel=0): path = os.path.abspath(db_filename) diff --git a/sorteerhoed/webserver.py b/sorteerhoed/webserver.py index c6353f1..7ca3bc2 100644 --- a/sorteerhoed/webserver.py +++ b/sorteerhoed/webserver.py @@ -309,6 +309,24 @@ class DrawPageHandler(tornado.web.RequestHandler): try: hit_id = int(self.get_query_argument('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"
") + self.write(f"") + self.write(f"") + self.write(f"") + self.write("
") + self.write("Invalid HIT") return hit = self.store.currentHit @@ -320,7 +338,7 @@ class DrawPageHandler(tornado.web.RequestHandler): return 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', '')) if len(assignmentId) < 1: @@ -360,7 +378,7 @@ class DrawPageHandler(tornado.web.RequestHandler): .replace("{TOP_PADDING}", str(self.top_padding))\ .replace("{LEFT_PADDING}", str(self.left_padding))\ .replace("{SCRIPT}", '' if previewOnly else '')\ - .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)