1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Add active semester to user settings in assistants space

This commit is contained in:
Mo 2022-09-12 17:59:54 +02:00
parent 0b4316a713
commit a66d95ffb5

View file

@ -1,11 +1,13 @@
from flask import flash, redirect, request, url_for from flask import flash, redirect, request, url_for
from flask_admin import Admin as FlaskAdmin from flask_admin import Admin as FlaskAdmin
from flask_admin import expose from flask_admin import expose
from flask_admin.contrib.sqla.fields import QuerySelectField
from flask_admin.menu import MenuLink from flask_admin.menu import MenuLink
from flask_admin.model.template import EndpointLinkRowAction from flask_admin.model.template import EndpointLinkRowAction
from flask_login import current_user from flask_login import current_user
from flask_security.changeable import admin_change_password from flask_security.changeable import admin_change_password
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms.validators import DataRequired
from .advlabdb_independent_funs import ( from .advlabdb_independent_funs import (
deep_getattr, deep_getattr,
@ -26,7 +28,7 @@ from .model_dependent_funs import (
user_info_fields, user_info_fields,
) )
from .model_independent_funs import randomPassword, reportBadAttempt from .model_independent_funs import randomPassword, reportBadAttempt
from .models import Assistant, GroupExperiment, SemesterExperiment, User, db from .models import Assistant, GroupExperiment, Semester, SemesterExperiment, User, db
assistantSpace = FlaskAdmin( assistantSpace = FlaskAdmin(
name="Assistant@AdvLabDB", name="Assistant@AdvLabDB",
@ -184,6 +186,19 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
class AssistantUserView(SecureAssistantModelView): class AssistantUserView(SecureAssistantModelView):
class EditForm(FlaskForm): class EditForm(FlaskForm):
@staticmethod
def semesterQueryFactory():
# Show only last two semesters to assistants
return Semester.query.order_by(Semester.id.desc()).limit(2)
active_semester = QuerySelectField(
"Active Semester",
query_factory=semesterQueryFactory,
validators=[DataRequired()],
default=Semester.lastSemester,
description="You should change the active semester to the last semester. Do not forget to click save!",
)
phone_number, mobile_phone_number, building, room = user_info_fields() phone_number, mobile_phone_number, building, room = user_info_fields()
generate_new_password = generate_new_password_field() generate_new_password = generate_new_password_field()