From d045f5eb01a5a1100001622fec60afff54ad8b10 Mon Sep 17 00:00:00 2001 From: Joel Savitz Date: Tue, 5 Aug 2025 05:20:53 -0400 Subject: [PATCH] standardize query order_by argument To sort the results of a query with peewee orm, in descending order, we pass a column label to the order_by() method on a select() call and either prefix it with the '-' symbol or call its.desc() method. Currently we do some of both. Change all order_by({X.desc()} => {-X}) to make the code easier to read and more consistent. Signed-off-by: Joel Savitz --- denis/utilities.py | 2 +- orbit/radius.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/denis/utilities.py b/denis/utilities.py index 09e34f74..ab0fd4d7 100644 --- a/denis/utilities.py +++ b/denis/utilities.py @@ -17,7 +17,7 @@ def user_to_sub(assignment, component): relevant_gradeables = (grd_tbl.select() .where(grd_tbl.assignment == assignment) .where(grd_tbl.component == component) - .order_by(grd_tbl.timestamp.desc())) + .order_by(-grd_tbl.timestamp)) for user in orbit.db.User.select(): username = user.username sub = (relevant_gradeables diff --git a/orbit/radius.py b/orbit/radius.py index 6ca6a6fb..f4267fd7 100644 --- a/orbit/radius.py +++ b/orbit/radius.py @@ -390,7 +390,7 @@ def handle_activity(rocket): submissions = (mailman.db.Submission.select() .where(mailman.db.Submission.user == rocket.session.username) - .order_by(- mailman.db.Submission.timestamp)) + .order_by(-mailman.db.Submission.timestamp)) def submission_fields(sub): return (datetime.fromtimestamp(sub.timestamp).astimezone().isoformat(), @@ -623,7 +623,7 @@ def handle_dashboard(rocket): grd_tbl = mailman.db.Gradeable user_gradeables = (grd_tbl.select() .where(grd_tbl.user == rocket.session.username) - .order_by(grd_tbl.timestamp.desc())) + .order_by(-grd_tbl.timestamp)) assignments = asmt_tbl.select().order_by(asmt_tbl.initial_due_date) ret = '
' for assignment in assignments: