Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions backend/answers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ def attachment_name(self):
)

def sort_key(self):
month_val = next((val for month, val in {"december": 0.4, "august": 0.3, "may": 0.2, "april": 0.1}.items()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever, but I'm not sure I like the limited extensibility here; what if we have a November exam for one course? We don't have one now, but I believe non-Honours courses (SCQF 8 & 9) can have exams whenever they want and aren't constrained by Honours rules.

I found some cool behaviour with strptime, maybe you can use that? I'm not 100% sure if you can pass datetime to sorted() (backend/categories/views.py line 146), but if you can, this seems like a cleaner solution!

>>> import datetime
>>> datetime.datetime.strptime("December 23", "%B %y")
datetime.datetime(2023, 12, 1, 0, 0)
>>> datetime.datetime.strptime("may 24", "%B %y")
datetime.datetime(2024, 5, 1, 0, 0)

if month in self.displayname.lower()), 0)
end = 0
while (
end + 1 < len(self.displayname) and self.displayname[-end - 1 :].isdigit()
):
end += 1
if end == 0:
return 0, self.displayname
return int(self.displayname[-end:]), self.displayname
return month_val, self.displayname
return int(self.displayname[-end:])+month_val, self.displayname

def count_answered(self):
return self.answersection_set.filter(
Expand Down