diff --git a/zesje/pregrader.py b/zesje/pregrader.py index 2175ee9e304b5672c55c30d63a297650e9a4e5d8..c5907ddc83f30948dc227d1e349a12f898b903fe 100644 --- a/zesje/pregrader.py +++ b/zesje/pregrader.py @@ -5,16 +5,20 @@ from zesje.database import db, Solution from zesje.images import guess_dpi, get_box, fix_corner_markers -def add_feedback_to_solution(exam, page, page_img, corner_keypoints): +def add_feedback_to_solution(sub, exam, page, page_img, corner_keypoints): """ Adds the multiple choice options that are identified as marked as a feedback option to a solution - Params + Parameters ------ - exam: the current exam - page_img: image of the page - barcode: data from the barcode on the page - corner_keypoints: locations of the corner keypoints + sub : Submission + the current submission + exam : Exam + the current exam + page_img : Image + image of the page + corner_keypoints : array + locations of the corner keypoints as (x, y) tuples """ problems_on_page = [problem for problem in exam.problems if problem.widget.page == page] @@ -25,7 +29,7 @@ def add_feedback_to_solution(exam, page, page_img, corner_keypoints): top_left_point = sorted(fixed_corner_keypoints, key=lambda x: x[0])[0] if fixed_corner_keypoints else [] for problem in problems_on_page: - sol = Solution.query.filter(Solution.problem_id == problem.id).one_or_none() + sol = Solution.query.filter(Solution.problem_id == problem.id, Solution.submission_id == sub.id).one_or_none() for mc_option in problem.mc_options: box = (mc_option.x, mc_option.y) diff --git a/zesje/scans.py b/zesje/scans.py index e82223d00a4d05ebb70e2db76900080b11691c5c..ac0be8e012e25df255aa31bef4948780eefd0ed0 100644 --- a/zesje/scans.py +++ b/zesje/scans.py @@ -338,8 +338,8 @@ def process_page(image_data, exam_config, output_dir=None, strict=False): else: return True, "Testing, image not saved and database not updated." - exam = update_database(image_path, barcode) - add_feedback_to_solution(exam, barcode.page, image_array, corner_keypoints) + sub, exam = update_database(image_path, barcode) + add_feedback_to_solution(sub, exam, barcode.page, image_array, corner_keypoints) if barcode.page == 0: description = guess_student( @@ -387,8 +387,12 @@ def update_database(image_path, barcode): Returns ------- - signature_validated : bool - If the corresponding submission has a validated signature. + sub, exam where + + sub : Submission + the current submission + exam : Exam + the current exam """ exam = Exam.query.filter(Exam.token == barcode.token).first() if exam is None: @@ -408,7 +412,7 @@ def update_database(image_path, barcode): db.session.commit() - return exam + return sub, exam def decode_barcode(image, exam_config):