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 sqlalchemy import func, or_
|
||||||
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
|
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
|
||||||
from wtforms.fields.html5 import DateField
|
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.configUtils import getConfig
|
||||||
from advlabdb.customClasses import SecureAdminModelView
|
from advlabdb.customClasses import SecureAdminModelView
|
||||||
from advlabdb.exceptions import DataBaseException, ModelViewException
|
from advlabdb.exceptions import DataBaseException, ModelViewException
|
||||||
|
@ -30,7 +30,12 @@ from advlabdb.models import (
|
||||||
Student,
|
Student,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
from advlabdb.utils import randomPassword, setUserActiveSemester, userActiveSemester
|
from advlabdb.utils import (
|
||||||
|
initActiveSemesterMenuLinks,
|
||||||
|
randomPassword,
|
||||||
|
setUserActiveSemester,
|
||||||
|
userActiveSemester,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UserView(SecureAdminModelView):
|
class UserView(SecureAdminModelView):
|
||||||
|
@ -184,17 +189,21 @@ class SemesterView(SecureAdminModelView):
|
||||||
transferAssistants=form.transfer_assistants.data,
|
transferAssistants=form.transfer_assistants.data,
|
||||||
)
|
)
|
||||||
|
|
||||||
def after_model_change(self, form, model, is_created):
|
def addMenuLink(space, newSemester):
|
||||||
setUserActiveSemester(model.id)
|
space.add_link(
|
||||||
|
|
||||||
adminSpace.add_link(
|
|
||||||
MenuLink(
|
MenuLink(
|
||||||
name=model.repr(),
|
name=newSemester.repr(),
|
||||||
url=url_for("set_semester") + "?semester_id=" + str(model.id),
|
url=url_for("set_semester") + "?semester_id=" + str(newSemester.id),
|
||||||
category="Active semester",
|
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():
|
def programQueryFactory():
|
||||||
return Program.query
|
return Program.query
|
||||||
|
@ -701,15 +710,4 @@ adminSpace.add_view(SemesterView(Semester, db.session))
|
||||||
adminSpace.add_view(UserView(User, db.session))
|
adminSpace.add_view(UserView(User, db.session))
|
||||||
adminSpace.add_view(RoleView(Role, db.session))
|
adminSpace.add_view(RoleView(Role, db.session))
|
||||||
|
|
||||||
with app.app_context():
|
initActiveSemesterMenuLinks(adminSpace)
|
||||||
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")))
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from flask import flash
|
from flask import flash
|
||||||
|
from flask_admin.contrib.sqla.fields import QuerySelectField, QuerySelectMultipleField
|
||||||
from flask_security import current_user
|
from flask_security import current_user
|
||||||
|
from sqlalchemy import and_
|
||||||
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
|
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
|
||||||
from wtforms.fields.html5 import DateField
|
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 wtforms.validators import NumberRange
|
||||||
|
|
||||||
from advlabdb import assistantSpace, db
|
from advlabdb import assistantSpace, db
|
||||||
|
@ -25,7 +25,7 @@ from advlabdb.models import (
|
||||||
Student,
|
Student,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
from advlabdb.utils import userActiveSemester
|
from advlabdb.utils import initActiveSemesterMenuLinks, userActiveSemester
|
||||||
|
|
||||||
|
|
||||||
class AssistantAppointmentView(SecureAssistantModelView):
|
class AssistantAppointmentView(SecureAssistantModelView):
|
||||||
|
@ -94,3 +94,5 @@ assistantSpace.add_view(
|
||||||
assistantSpace.add_view(
|
assistantSpace.add_view(
|
||||||
AssistantExperimentMarkView(ExperimentMark, db.session, endpoint="assistant_experimentmark", url="experimentmark")
|
AssistantExperimentMarkView(ExperimentMark, db.session, endpoint="assistant_experimentmark", url="experimentmark")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
initActiveSemesterMenuLinks(assistantSpace)
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from random import choice
|
from random import choice
|
||||||
from string import ascii_letters, digits
|
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 flask_security import current_user
|
||||||
|
|
||||||
from advlabdb import db
|
from advlabdb import app, db
|
||||||
from advlabdb.models import Semester
|
from advlabdb.models import Semester
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,3 +48,18 @@ def setUserActiveSemester(semesterId):
|
||||||
flash(f"Active semester changed to {semester.repr()}!", "warning")
|
flash(f"Active semester changed to {semester.repr()}!", "warning")
|
||||||
else:
|
else:
|
||||||
flash(f"No semester with ID {semesterId}!", "error")
|
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