From 58c59679296720c02cac84304ddcf9f78b3b4e42 Mon Sep 17 00:00:00 2001 From: Marcos Prieto Date: Mon, 18 Nov 2024 16:21:18 +0100 Subject: [PATCH] Sort segments by name in the API --- lms/services/assignment.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lms/services/assignment.py b/lms/services/assignment.py index b95825808e..c077dea69f 100644 --- a/lms/services/assignment.py +++ b/lms/services/assignment.py @@ -342,20 +342,24 @@ def get_assignment_groups(self, assignment) -> Sequence[Grouping]: """Get the relevant groups for the assignment from the DB.""" if group_set_id := assignment.extra.get("group_set_id"): return self._db.scalars( - select(Grouping).where( + select(Grouping) + .where( Grouping.parent_id == assignment.course_id, Grouping.extra["group_set_id"].astext == str(group_set_id), ) + .order_by(Grouping.lms_name.asc()) ).all() return [] def get_assignment_sections(self, assignment) -> Sequence[Grouping]: """Get the relevant groups for the assignment from the DB.""" return self._db.scalars( - select(Grouping).where( + select(Grouping) + .where( Grouping.parent_id == assignment.course_id, Grouping.type == "canvas_section", ) + .order_by(Grouping.lms_name.asc()) ).all() def _update_auto_grading_config(