From e56aca7545ad2a3abf6c4833ff1eb74e0e6de131 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Fri, 30 Jul 2021 00:46:36 +0200 Subject: [PATCH] Added active semester default to UserView --- advlabdb/modelViews.py | 4 ++++ advlabdb/utils.py | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/advlabdb/modelViews.py b/advlabdb/modelViews.py index 74a334b..05eaf46 100644 --- a/advlabdb/modelViews.py +++ b/advlabdb/modelViews.py @@ -45,6 +45,9 @@ class UserView(SecureModelView): def semesterQueryFactory(): return Semester.query + def activeSemesterDefault(): + return userActiveSemester() + email = TextField("Email", validators=[DataRequired(), Email()]) roles = QuerySelectMultipleField( "Roles", @@ -58,6 +61,7 @@ class UserView(SecureModelView): query_factory=semesterQueryFactory, allow_blank=True, blank_text="-", + default=activeSemesterDefault, ) class EditForm(CreateForm): diff --git a/advlabdb/utils.py b/advlabdb/utils.py index b70a787..969b7e4 100644 --- a/advlabdb/utils.py +++ b/advlabdb/utils.py @@ -13,7 +13,9 @@ def randomPassword(): def userActiveSemester(flashWarning=False): - lastSemesterId = Semester.query.order_by(Semester.year.desc()).order_by(Semester.label.desc()).first().id + lastSemesterId = ( + Semester.query.order_by(Semester.year.desc()).order_by(Semester.label.desc()).first().id + ) # "WS" > "SS" if current_user.active_semester_id is None: current_user.active_semester_id = lastSemesterId db.session.commit()