Skip to content

Conversation

@mostafam99
Copy link

modified sort_key function to adjust slightly for exam months. the values are small so they don't conflict with year ordering. i don't know if this is a good fix or not

Copy link
Member

@yutotakano yutotakano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I like the 0.1/0.2/0.3/0.4 idea, but I'm not sure I like adding hardcoded values to these sort keys. I found an interesting function in the Python standard library that maybe we can use, could you look into that?

)

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants