mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Added activeSemesterDropDown and logout in assistantSpace
This commit is contained in:
parent
b9621345d7
commit
a50ad2f73f
3 changed files with 42 additions and 26 deletions
|
@ -8,9 +8,9 @@ from flask_security import admin_change_password, current_user, hash_password
|
|||
from sqlalchemy import func, or_
|
||||
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
|
||||
from wtforms.fields.html5 import DateField
|
||||
from wtforms.validators import URL, DataRequired, Email, Optional, NumberRange
|
||||
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
|
||||
|
||||
from advlabdb import adminSpace, app, db, user_datastore
|
||||
from advlabdb import adminSpace, app, assistantSpace, db, user_datastore
|
||||
from advlabdb.configUtils import getConfig
|
||||
from advlabdb.customClasses import SecureAdminModelView
|
||||
from advlabdb.exceptions import DataBaseException, ModelViewException
|
||||
|
@ -30,7 +30,12 @@ from advlabdb.models import (
|
|||
Student,
|
||||
User,
|
||||
)
|
||||
from advlabdb.utils import randomPassword, setUserActiveSemester, userActiveSemester
|
||||
from advlabdb.utils import (
|
||||
initActiveSemesterMenuLinks,
|
||||
randomPassword,
|
||||
setUserActiveSemester,
|
||||
userActiveSemester,
|
||||
)
|
||||
|
||||
|
||||
class UserView(SecureAdminModelView):
|
||||
|
@ -184,17 +189,21 @@ class SemesterView(SecureAdminModelView):
|
|||
transferAssistants=form.transfer_assistants.data,
|
||||
)
|
||||
|
||||
def after_model_change(self, form, model, is_created):
|
||||
setUserActiveSemester(model.id)
|
||||
|
||||
adminSpace.add_link(
|
||||
def addMenuLink(space, newSemester):
|
||||
space.add_link(
|
||||
MenuLink(
|
||||
name=model.repr(),
|
||||
url=url_for("set_semester") + "?semester_id=" + str(model.id),
|
||||
name=newSemester.repr(),
|
||||
url=url_for("set_semester") + "?semester_id=" + str(newSemester.id),
|
||||
category="Active semester",
|
||||
)
|
||||
)
|
||||
|
||||
def after_model_change(self, form, model, is_created):
|
||||
setUserActiveSemester(model.id)
|
||||
|
||||
SemesterView.addMenuLink(adminSpace, model)
|
||||
SemesterView.addMenuLink(assistantSpace, model)
|
||||
|
||||
|
||||
def programQueryFactory():
|
||||
return Program.query
|
||||
|
@ -701,15 +710,4 @@ adminSpace.add_view(SemesterView(Semester, db.session))
|
|||
adminSpace.add_view(UserView(User, db.session))
|
||||
adminSpace.add_view(RoleView(Role, db.session))
|
||||
|
||||
with app.app_context():
|
||||
semesters = Semester.query.order_by(Semester.id)
|
||||
for semester in semesters:
|
||||
adminSpace.add_link(
|
||||
MenuLink(
|
||||
name=semester.repr(),
|
||||
url=url_for("set_semester") + "?semester_id=" + str(semester.id),
|
||||
category="Active semester",
|
||||
)
|
||||
)
|
||||
|
||||
adminSpace.add_link(MenuLink(name="Logout", url=url_for("security.logout")))
|
||||
initActiveSemesterMenuLinks(adminSpace)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from flask import flash
|
||||
from flask_admin.contrib.sqla.fields import QuerySelectField, QuerySelectMultipleField
|
||||
from flask_security import current_user
|
||||
from sqlalchemy import and_
|
||||
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
|
||||
from wtforms.fields.html5 import DateField
|
||||
from flask_admin.contrib.sqla.fields import QuerySelectField, QuerySelectMultipleField
|
||||
from sqlalchemy import and_
|
||||
from wtforms.validators import NumberRange
|
||||
|
||||
from advlabdb import assistantSpace, db
|
||||
|
@ -25,7 +25,7 @@ from advlabdb.models import (
|
|||
Student,
|
||||
User,
|
||||
)
|
||||
from advlabdb.utils import userActiveSemester
|
||||
from advlabdb.utils import initActiveSemesterMenuLinks, userActiveSemester
|
||||
|
||||
|
||||
class AssistantAppointmentView(SecureAssistantModelView):
|
||||
|
@ -94,3 +94,5 @@ assistantSpace.add_view(
|
|||
assistantSpace.add_view(
|
||||
AssistantExperimentMarkView(ExperimentMark, db.session, endpoint="assistant_experimentmark", url="experimentmark")
|
||||
)
|
||||
|
||||
initActiveSemesterMenuLinks(assistantSpace)
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from random import choice
|
||||
from string import ascii_letters, digits
|
||||
|
||||
from flask import flash
|
||||
from flask import flash, url_for
|
||||
from flask_admin.menu import MenuLink
|
||||
from flask_security import current_user
|
||||
|
||||
from advlabdb import db
|
||||
from advlabdb import app, db
|
||||
from advlabdb.models import Semester
|
||||
|
||||
|
||||
|
@ -47,3 +48,18 @@ def setUserActiveSemester(semesterId):
|
|||
flash(f"Active semester changed to {semester.repr()}!", "warning")
|
||||
else:
|
||||
flash(f"No semester with ID {semesterId}!", "error")
|
||||
|
||||
|
||||
def initActiveSemesterMenuLinks(space):
|
||||
with app.app_context():
|
||||
semesters = Semester.query.order_by(Semester.id)
|
||||
for semester in semesters:
|
||||
space.add_link(
|
||||
MenuLink(
|
||||
name=semester.repr(),
|
||||
url=url_for("set_semester") + "?semester_id=" + str(semester.id),
|
||||
category="Active semester",
|
||||
)
|
||||
)
|
||||
|
||||
space.add_link(MenuLink(name="Logout", url=url_for("security.logout")))
|
||||
|
|
Loading…
Reference in a new issue