1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Sorting semesters

This commit is contained in:
Mo 2022-05-16 18:35:42 +02:00
parent af7fcaa59c
commit a8117b7e72

View file

@ -10,12 +10,23 @@ def flashRandomPassword(password):
flash(f"Random password: {password}", category="warning") flash(f"Random password: {password}", category="warning")
def sortedSemestersStartingWithNewest(): def sortedSemestersStartingWithNewest(limit=0):
return Semester.query.order_by(Semester.year.desc()).order_by(Semester.label.desc()) # Inserting an older semester is not allowed!
# Therefore, the id is enough.
stmt = select(Semester).order_by(Semester.id.desc())
if limit > 0:
stmt = stmt.limit(limit)
return db.session.execute(stmt).scalars()
def lastSemester():
return sortedSemestersStartingWithNewest(limit=1).first()
def userActiveSemester(flashWarning=False): def userActiveSemester(flashWarning=False):
lastSemesterId = sortedSemestersStartingWithNewest().first().id # "WS" > "SS" lastSemesterId = lastSemester().id
if current_user.active_semester_id is None: if current_user.active_semester_id is None:
current_user.active_semester_id = lastSemesterId current_user.active_semester_id = lastSemesterId
db.session.commit() db.session.commit()