mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Share fields
This commit is contained in:
parent
4c64a8cefd
commit
e1411e87a0
3 changed files with 59 additions and 63 deletions
|
@ -39,7 +39,12 @@ from .customClasses import (
|
||||||
)
|
)
|
||||||
from .database_import import importFromFile
|
from .database_import import importFromFile
|
||||||
from .exceptions import DataBaseException, ModelViewException
|
from .exceptions import DataBaseException, ModelViewException
|
||||||
from .model_dependent_funs import initActiveSemesterMenuLinks
|
from .model_dependent_funs import (
|
||||||
|
generate_new_password_field,
|
||||||
|
initActiveSemesterMenuLinks,
|
||||||
|
mark_field,
|
||||||
|
user_info_fields,
|
||||||
|
)
|
||||||
from .model_independent_funs import randomPassword
|
from .model_independent_funs import randomPassword
|
||||||
from .models import (
|
from .models import (
|
||||||
MAX_MARK,
|
MAX_MARK,
|
||||||
|
@ -111,22 +116,8 @@ class UserView(SecureAdminModelView):
|
||||||
"Last Name",
|
"Last Name",
|
||||||
validators=[DataRequired()],
|
validators=[DataRequired()],
|
||||||
)
|
)
|
||||||
phone_number = StringField(
|
|
||||||
"Phone Number",
|
phone_number, mobile_phone_number, building, room = user_info_fields()
|
||||||
validators=[Optional()],
|
|
||||||
)
|
|
||||||
mobile_phone_number = StringField(
|
|
||||||
"Mobile Phone Number",
|
|
||||||
validators=[Optional()],
|
|
||||||
)
|
|
||||||
building = StringField(
|
|
||||||
"Building",
|
|
||||||
validators=[Optional()],
|
|
||||||
)
|
|
||||||
room = StringField(
|
|
||||||
"Room",
|
|
||||||
validators=[Optional()],
|
|
||||||
)
|
|
||||||
|
|
||||||
semester_experiments = QuerySelectMultipleField(
|
semester_experiments = QuerySelectMultipleField(
|
||||||
"Semester Experiments",
|
"Semester Experiments",
|
||||||
|
@ -151,10 +142,7 @@ class UserView(SecureAdminModelView):
|
||||||
class EditForm(CreateForm):
|
class EditForm(CreateForm):
|
||||||
semester_experiments = None
|
semester_experiments = None
|
||||||
|
|
||||||
generate_new_password = BooleanField(
|
generate_new_password = generate_new_password_field()
|
||||||
"Generate new random password. For security reasons, it is not possible to manually enter a password. Please use a password manager like Bitwarden or KeepassXC to save the randomly generated password.",
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
can_view_details = True
|
can_view_details = True
|
||||||
|
|
||||||
|
@ -1135,14 +1123,6 @@ class AppointmentView(SecureAdminModelView):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def mark_field(mark_type: str):
|
|
||||||
return IntegerField(
|
|
||||||
mark_type + " Mark",
|
|
||||||
validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)],
|
|
||||||
description=f"Between {MIN_MARK} and {MAX_MARK}.",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ExperimentMarkView(SecureAdminModelView):
|
class ExperimentMarkView(SecureAdminModelView):
|
||||||
class StudentFilter(FilterEqual):
|
class StudentFilter(FilterEqual):
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
|
|
|
@ -3,7 +3,6 @@ from flask_admin import expose
|
||||||
from flask_security import admin_change_password, current_user
|
from flask_security import admin_change_password, current_user
|
||||||
from wtforms import Form
|
from wtforms import Form
|
||||||
from wtforms.fields import BooleanField, IntegerField, StringField
|
from wtforms.fields import BooleanField, IntegerField, StringField
|
||||||
from wtforms.validators import NumberRange, Optional
|
|
||||||
|
|
||||||
from . import assistantSpace, db
|
from . import assistantSpace, db
|
||||||
from .advlabdb_independent_funs import (
|
from .advlabdb_independent_funs import (
|
||||||
|
@ -15,7 +14,12 @@ from .advlabdb_independent_funs import (
|
||||||
)
|
)
|
||||||
from .customClasses import SecureAssistantBaseView, SecureAssistantModelView
|
from .customClasses import SecureAssistantBaseView, SecureAssistantModelView
|
||||||
from .exceptions import DataBaseException, ModelViewException
|
from .exceptions import DataBaseException, ModelViewException
|
||||||
from .model_dependent_funs import initActiveSemesterMenuLinks
|
from .model_dependent_funs import (
|
||||||
|
generate_new_password_field,
|
||||||
|
initActiveSemesterMenuLinks,
|
||||||
|
mark_field,
|
||||||
|
user_info_fields,
|
||||||
|
)
|
||||||
from .model_independent_funs import randomPassword
|
from .model_independent_funs import randomPassword
|
||||||
from .models import (
|
from .models import (
|
||||||
MAX_MARK,
|
MAX_MARK,
|
||||||
|
@ -78,16 +82,8 @@ class AssistantAppointmentView(SecureAssistantModelView):
|
||||||
|
|
||||||
class AssistantExperimentMarkView(SecureAssistantModelView):
|
class AssistantExperimentMarkView(SecureAssistantModelView):
|
||||||
class EditForm(Form):
|
class EditForm(Form):
|
||||||
oral_mark = IntegerField(
|
oral_mark = mark_field("Oral")
|
||||||
"Oral Mark",
|
protocol_mark = mark_field("Protocol")
|
||||||
validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)],
|
|
||||||
description=f"Between {MIN_MARK} and {MAX_MARK}",
|
|
||||||
)
|
|
||||||
protocol_mark = IntegerField(
|
|
||||||
"Protocol Mark",
|
|
||||||
validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)],
|
|
||||||
description=f"Between {MIN_MARK} and {MAX_MARK}",
|
|
||||||
)
|
|
||||||
|
|
||||||
can_edit = True
|
can_edit = True
|
||||||
column_display_actions = True
|
column_display_actions = True
|
||||||
|
@ -164,28 +160,9 @@ class AssistantExperimentMarkView(SecureAssistantModelView):
|
||||||
|
|
||||||
class AssistantUserView(SecureAssistantModelView):
|
class AssistantUserView(SecureAssistantModelView):
|
||||||
class EditForm(Form):
|
class EditForm(Form):
|
||||||
phone_number = StringField(
|
phone_number, mobile_phone_number, building, room = user_info_fields()
|
||||||
"Phone Number",
|
|
||||||
validators=[Optional()],
|
|
||||||
)
|
|
||||||
mobile_phone_number = StringField(
|
|
||||||
"Mobile Phone Number",
|
|
||||||
validators=[Optional()],
|
|
||||||
)
|
|
||||||
|
|
||||||
building = StringField(
|
generate_new_password = generate_new_password_field()
|
||||||
"Building",
|
|
||||||
validators=[Optional()],
|
|
||||||
)
|
|
||||||
room = StringField(
|
|
||||||
"Room",
|
|
||||||
validators=[Optional()],
|
|
||||||
)
|
|
||||||
|
|
||||||
generate_new_password = BooleanField(
|
|
||||||
"Generate new random password. For security reasons, it is not possible to manually enter a password. Please use a password manager like Bitwarden or KeepassXC to save the randomly generated password.",
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
can_edit = True
|
can_edit = True
|
||||||
can_view_details = True
|
can_view_details = True
|
||||||
|
|
|
@ -4,9 +4,11 @@ from flask import flash, url_for
|
||||||
from flask_admin.menu import MenuLink
|
from flask_admin.menu import MenuLink
|
||||||
from flask_security import current_user
|
from flask_security import current_user
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
from wtforms.fields import BooleanField, IntegerField, StringField
|
||||||
|
from wtforms.validators import NumberRange, Optional
|
||||||
|
|
||||||
from . import app, db
|
from . import app, db
|
||||||
from .models import Semester
|
from .models import MAX_MARK, MIN_MARK, Semester
|
||||||
|
|
||||||
|
|
||||||
def initActiveSemesterMenuLinks(space):
|
def initActiveSemesterMenuLinks(space):
|
||||||
|
@ -44,3 +46,40 @@ def active_semester_str():
|
||||||
flash(f"You are in the old semester {active_semester_str}!", "warning")
|
flash(f"You are in the old semester {active_semester_str}!", "warning")
|
||||||
|
|
||||||
return active_semester_str
|
return active_semester_str
|
||||||
|
|
||||||
|
|
||||||
|
def mark_field(mark_type: str):
|
||||||
|
return IntegerField(
|
||||||
|
mark_type + " Mark",
|
||||||
|
validators=[Optional(), NumberRange(MIN_MARK, MAX_MARK)],
|
||||||
|
description=f"Between {MIN_MARK} and {MAX_MARK}.",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def user_info_fields():
|
||||||
|
phone_number = StringField(
|
||||||
|
"Phone Number",
|
||||||
|
validators=[Optional()],
|
||||||
|
)
|
||||||
|
mobile_phone_number = StringField(
|
||||||
|
"Mobile Phone Number",
|
||||||
|
validators=[Optional()],
|
||||||
|
)
|
||||||
|
|
||||||
|
building = StringField(
|
||||||
|
"Building",
|
||||||
|
validators=[Optional()],
|
||||||
|
)
|
||||||
|
room = StringField(
|
||||||
|
"Room",
|
||||||
|
validators=[Optional()],
|
||||||
|
)
|
||||||
|
|
||||||
|
return phone_number, mobile_phone_number, building, room
|
||||||
|
|
||||||
|
|
||||||
|
def generate_new_password_field():
|
||||||
|
return BooleanField(
|
||||||
|
"Generate new random password. For security reasons, it is not possible to manually enter a password. Please use a password manager like Bitwarden or KeepassXC to save the randomly generated password.",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue