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 .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 .models import (
|
||||
MAX_MARK,
|
||||
|
@ -111,22 +116,8 @@ class UserView(SecureAdminModelView):
|
|||
"Last Name",
|
||||
validators=[DataRequired()],
|
||||
)
|
||||
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()],
|
||||
)
|
||||
|
||||
phone_number, mobile_phone_number, building, room = user_info_fields()
|
||||
|
||||
semester_experiments = QuerySelectMultipleField(
|
||||
"Semester Experiments",
|
||||
|
@ -151,10 +142,7 @@ class UserView(SecureAdminModelView):
|
|||
class EditForm(CreateForm):
|
||||
semester_experiments = None
|
||||
|
||||
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,
|
||||
)
|
||||
generate_new_password = generate_new_password_field()
|
||||
|
||||
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 StudentFilter(FilterEqual):
|
||||
def validate(self, value):
|
||||
|
|
|
@ -3,7 +3,6 @@ from flask_admin import expose
|
|||
from flask_security import admin_change_password, current_user
|
||||
from wtforms import Form
|
||||
from wtforms.fields import BooleanField, IntegerField, StringField
|
||||
from wtforms.validators import NumberRange, Optional
|
||||
|
||||
from . import assistantSpace, db
|
||||
from .advlabdb_independent_funs import (
|
||||
|
@ -15,7 +14,12 @@ from .advlabdb_independent_funs import (
|
|||
)
|
||||
from .customClasses import SecureAssistantBaseView, SecureAssistantModelView
|
||||
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 .models import (
|
||||
MAX_MARK,
|
||||
|
@ -78,16 +82,8 @@ class AssistantAppointmentView(SecureAssistantModelView):
|
|||
|
||||
class AssistantExperimentMarkView(SecureAssistantModelView):
|
||||
class EditForm(Form):
|
||||
oral_mark = IntegerField(
|
||||
"Oral Mark",
|
||||
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}",
|
||||
)
|
||||
oral_mark = mark_field("Oral")
|
||||
protocol_mark = mark_field("Protocol")
|
||||
|
||||
can_edit = True
|
||||
column_display_actions = True
|
||||
|
@ -164,28 +160,9 @@ class AssistantExperimentMarkView(SecureAssistantModelView):
|
|||
|
||||
class AssistantUserView(SecureAssistantModelView):
|
||||
class EditForm(Form):
|
||||
phone_number = StringField(
|
||||
"Phone Number",
|
||||
validators=[Optional()],
|
||||
)
|
||||
mobile_phone_number = StringField(
|
||||
"Mobile Phone Number",
|
||||
validators=[Optional()],
|
||||
)
|
||||
phone_number, mobile_phone_number, building, room = user_info_fields()
|
||||
|
||||
building = StringField(
|
||||
"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,
|
||||
)
|
||||
generate_new_password = generate_new_password_field()
|
||||
|
||||
can_edit = True
|
||||
can_view_details = True
|
||||
|
|
|
@ -4,9 +4,11 @@ from flask import flash, url_for
|
|||
from flask_admin.menu import MenuLink
|
||||
from flask_security import current_user
|
||||
from sqlalchemy import select
|
||||
from wtforms.fields import BooleanField, IntegerField, StringField
|
||||
from wtforms.validators import NumberRange, Optional
|
||||
|
||||
from . import app, db
|
||||
from .models import Semester
|
||||
from .models import MAX_MARK, MIN_MARK, Semester
|
||||
|
||||
|
||||
def initActiveSemesterMenuLinks(space):
|
||||
|
@ -44,3 +46,40 @@ def active_semester_str():
|
|||
flash(f"You are in the old semester {active_semester_str}!", "warning")
|
||||
|
||||
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