mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Sorting semesters
This commit is contained in:
parent
af7fcaa59c
commit
a8117b7e72
1 changed files with 14 additions and 3 deletions
|
@ -10,12 +10,23 @@ def flashRandomPassword(password):
|
|||
flash(f"Random password: {password}", category="warning")
|
||||
|
||||
|
||||
def sortedSemestersStartingWithNewest():
|
||||
return Semester.query.order_by(Semester.year.desc()).order_by(Semester.label.desc())
|
||||
def sortedSemestersStartingWithNewest(limit=0):
|
||||
# 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):
|
||||
lastSemesterId = sortedSemestersStartingWithNewest().first().id # "WS" > "SS"
|
||||
lastSemesterId = lastSemester().id
|
||||
if current_user.active_semester_id is None:
|
||||
current_user.active_semester_id = lastSemesterId
|
||||
db.session.commit()
|
||||
|
|
Loading…
Reference in a new issue