Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit 054e6c8

Browse files
committed
Fix: use assignment_id if given to disambiguate question names
1 parent 92b3833 commit 054e6c8

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

controllers/admin.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,9 @@ def add__or_update_assignment_question():
20992099
# This assumes that question will always be in DB already, before an assignment_question is created
21002100
logger.debug("course_id %s", auth.user.course_id)
21012101
if not question_id:
2102-
question_id = _get_question_id(question_name, auth.user.course_id)
2102+
question_id = _get_question_id(
2103+
question_name, auth.user.course_id, assignment_id=assignment_id
2104+
)
21032105
if question_id is None:
21042106
logger.error(
21052107
"Question Not found for name = {} course = {}".format(
@@ -2219,20 +2221,31 @@ def add__or_update_assignment_question():
22192221
# by name. If there is only one match then no problem. If there is more than one
22202222
# then the base course of the current user should be preferred to ensure
22212223
# backward compatibility.
2222-
def _get_question_id(question_name, course_id):
2224+
def _get_question_id(question_name, course_id, assignment_id=None):
22232225
# first try to just get the question by name.
22242226
question = db((db.questions.name == question_name)).select(db.questions.id)
22252227
# if there is more than one then use the course_id
22262228
if len(question) > 1:
2227-
question = (
2228-
db(
2229-
(db.questions.name == question_name)
2230-
& (db.questions.base_course == db.courses.base_course)
2231-
& (db.courses.id == course_id)
2229+
if assignment_id:
2230+
question = (
2231+
db(
2232+
(db.questions.name == question_name)
2233+
& (db.questions.id == db.assignment_questions.question_id)
2234+
& (db.assignment_questions.assignment_id == assignment_id)
2235+
)
2236+
.select(db.questions.id)
2237+
.first()
2238+
)
2239+
else:
2240+
question = (
2241+
db(
2242+
(db.questions.name == question_name)
2243+
& (db.questions.base_course == db.courses.base_course)
2244+
& (db.courses.id == course_id)
2245+
)
2246+
.select(db.questions.id)
2247+
.first()
22322248
)
2233-
.select(db.questions.id)
2234-
.first()
2235-
)
22362249
else:
22372250
question = question[0]
22382251

@@ -2281,7 +2294,9 @@ def delete_assignment_question():
22812294
try:
22822295
question_name = request.vars["name"]
22832296
assignment_id = int(request.vars["assignment_id"])
2284-
question_id = _get_question_id(question_name, auth.user.course_id)
2297+
question_id = _get_question_id(
2298+
question_name, auth.user.course_id, assignment_id=assignment_id
2299+
)
22852300
logger.debug("DELETEING A: %s Q:%s ", assignment_id, question_id)
22862301
db(
22872302
(db.assignment_questions.assignment_id == assignment_id)
@@ -2344,7 +2359,9 @@ def reorder_assignment_questions():
23442359
i = 0
23452360
for name in question_names:
23462361
i += 1
2347-
question_id = _get_question_id(name, auth.user.course_id)
2362+
question_id = _get_question_id(
2363+
name, auth.user.course_id, assignment_id=assignment_id
2364+
)
23482365
db(
23492366
(db.assignment_questions.question_id == question_id)
23502367
& (db.assignment_questions.assignment_id == assignment_id)

0 commit comments

Comments
 (0)