mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +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")
|
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()
|
||||||
|
|
Loading…
Reference in a new issue