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

Commit a688e15

Browse files
committed
Merge branch 'fix_order'
2 parents 87849fc + 7648ed6 commit a688e15

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

controllers/admin.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,11 +1534,16 @@ def add__or_update_assignment_question():
15341534
chapter = db.questions[question_id].chapter
15351535
subchapter = db.questions[question_id].subchapter
15361536
auto_grade = db.questions[question_id].autograde
1537+
1538+
# Get the current sorting priority for a question, if its there.
1539+
# otherwise assign it to the end of the list.
15371540
tmpSp = _get_question_sorting_priority(assignment_id, question_id)
1538-
if tmpSp != None:
1541+
1542+
if tmpSp is None:
1543+
tmpSp = _get_max_sorting_priority(assignment_id) or 0
15391544
sp = 1 + tmpSp
15401545
else:
1541-
sp = 0
1546+
sp = tmpSp
15421547

15431548
activity_count = 0
15441549
if question_type == 'page':
@@ -1617,9 +1622,27 @@ def _get_question_id(question_name, course_id):
16171622
# (db.courses.id == course_id)
16181623
# ).select(db.questions.id).first().id)
16191624

1620-
def _get_question_sorting_priority(assignment_id, question_id):
1625+
def _get_max_sorting_priority(assignment_id):
16211626
max = db.assignment_questions.sorting_priority.max()
1622-
return db((db.assignment_questions.assignment_id == assignment_id)).select(max).first()[max]
1627+
return (
1628+
db((db.assignment_questions.assignment_id == assignment_id))
1629+
.select(max)
1630+
.first()[max]
1631+
)
1632+
1633+
def _get_question_sorting_priority(assignment_id, question_id):
1634+
res = (
1635+
db((db.assignment_questions.assignment_id == assignment_id)
1636+
& (db.assignment_questions.question_id == question_id)
1637+
)
1638+
.select(db.assignment_questions.sorting_priority)
1639+
.first()
1640+
)
1641+
if res is not None:
1642+
return res['sorting_priority']
1643+
else:
1644+
return res
1645+
16231646

16241647
@auth.requires(lambda: verifyInstructorStatus(auth.user.course_name, auth.user), requires_login=True)
16251648
def delete_assignment_question():

0 commit comments

Comments
 (0)