Improve sorting of exercises when adding to assignment via book browse - #1403
Open
oscarlevin wants to merge 2 commits into
Open
Improve sorting of exercises when adding to assignment via book browse#1403oscarlevin wants to merge 2 commits into
oscarlevin wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect lexicographic ordering of exercise identifiers when instructors browse book sections to add exercises to an assignment, by introducing a natural-sort key and re-sorting questions per subchapter after the DB query.
Changes:
- Added a
_natural_sort_keyhelper to compare numeric runs numerically (e.g.,3.2.1before3.10.1). - Re-sorted each subchapter’s question list in Python using the natural sort key to override DB string ordering.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+832
to
+836
| for chapter_questions in questions.values(): | ||
| for subchapter_questions in chapter_questions.values(): | ||
| subchapter_questions.sort( | ||
| key=lambda q: _natural_sort_key(q.qnumber or q.name) | ||
| ) |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
components/rsptx/db/crud/question.py:837
- This introduces new ordering logic for chapter/subchapter question lists but there’s no regression test covering the natural sort behavior (e.g., ensuring "Exercise 1.3.2" sorts before "Exercise 1.3.11"). Since this endpoint drives assignment creation UI, adding a focused test would help prevent future regressions.
for chapter_questions in questions.values():
for subchapter_questions in chapter_questions.values():
subchapter_questions.sort(
key=lambda q: _natural_sort_key(q.qnumber or q.name)
)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently if an instructor tries to add exercises to an assignment by browsing problems in the book, when navigating to a section, they get the exercises sorted by exercise name, which might be something like "Exercise 1.3.2" or "Exercise 1.3.11". But these are sorted as strings, so the 11th exercise appears before then 2nd.
This pr fixes that by adding a natural sort key function that sorts them "correctly"