mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Made modal
This commit is contained in:
parent
c09ab2ffdc
commit
0a91f4a331
4 changed files with 73 additions and 11 deletions
File diff suppressed because one or more lines are too long
|
@ -51,9 +51,9 @@ This URL leads to the home page where you can login with this testing admin acco
|
|||
|
||||
# To-Do:
|
||||
- Rest of admin model views
|
||||
- Validators
|
||||
- Experiments history for students
|
||||
- Assistants space
|
||||
- Homepage text changeable
|
||||
- Email integration?
|
||||
- 2FA?
|
||||
- Students code for getting information?
|
||||
|
|
|
@ -16,6 +16,10 @@ class SecureModelView(ModelView):
|
|||
can_export = True
|
||||
can_set_page_size = True
|
||||
|
||||
create_modal = True
|
||||
edit_modal = True
|
||||
details_modal = True
|
||||
|
||||
list_template = "admin_list.html"
|
||||
create_template = "admin_create.html"
|
||||
edit_template = "admin_edit.html"
|
||||
|
|
|
@ -7,6 +7,7 @@ from wtforms import Form, BooleanField, SelectField, TextField, RadioField, Floa
|
|||
from wtforms.validators import DataRequired, Email, Optional
|
||||
from flask_admin.contrib.sqla.fields import QuerySelectMultipleField, QuerySelectField
|
||||
from flask_admin.helpers import get_form_data
|
||||
from wtforms.fields.html5 import DateField
|
||||
|
||||
from advlabdb import admin, app, db, user_datastore
|
||||
from advlabdb.configUtils import getConfig
|
||||
|
@ -39,6 +40,7 @@ class UserView(SecureModelView):
|
|||
column_searchable_list = ["email"]
|
||||
column_filters = ["active"]
|
||||
form_columns = ["email", "active", "roles"]
|
||||
column_editable_list = ["active"]
|
||||
|
||||
form_args = {
|
||||
"email": {"validators": [Email()]},
|
||||
|
@ -208,14 +210,15 @@ def partQueryFactory():
|
|||
return Part.query.filter(Part.id.in_([part.id for part in userActiveSemester().parts]))
|
||||
|
||||
|
||||
def groupQueryFactory():
|
||||
return Group.query.filter(Group.part_id.in_([part.id for part in userActiveSemester().parts]))
|
||||
|
||||
|
||||
class PartStudentView(SecureModelView):
|
||||
class CreateForm(Form):
|
||||
def studentQueryFactory():
|
||||
return Student.query
|
||||
|
||||
def groupQueryFactory():
|
||||
return Group.query.filter(Group.part_id.in_([part.id for part in userActiveSemester().parts]))
|
||||
|
||||
student = QuerySelectField(
|
||||
"Student", query_factory=studentQueryFactory, validators=[DataRequired()], allow_blank=True, blank_text="-"
|
||||
)
|
||||
|
@ -266,9 +269,9 @@ class GroupView(SecureModelView):
|
|||
return PartStudent.query.filter(PartStudent.part_id.in_([part.id for part in userActiveSemester().parts]))
|
||||
|
||||
part = QuerySelectField(
|
||||
label="Part", query_factory=partQueryFactory, validators=[DataRequired()], allow_blank=True, blank_text="-"
|
||||
"Part", query_factory=partQueryFactory, validators=[DataRequired()], allow_blank=True, blank_text="-"
|
||||
)
|
||||
part_students = QuerySelectMultipleField(label="Part Students", query_factory=partStudentsQueryFactory)
|
||||
part_students = QuerySelectMultipleField("Part Students", query_factory=partStudentsQueryFactory)
|
||||
|
||||
class EditForm(CreateForm):
|
||||
part = None
|
||||
|
@ -276,8 +279,7 @@ class GroupView(SecureModelView):
|
|||
form = EditForm
|
||||
|
||||
column_list = ["number", "part", "part_students"]
|
||||
column_filters = ["part"]
|
||||
column_searchable_list = ["number"]
|
||||
column_filters = ["number", "part"]
|
||||
|
||||
partStudentPartPartMismatchException = "Part and StudentParts part don't match!"
|
||||
|
||||
|
@ -355,13 +357,65 @@ class PartExperimentView(SecureModelView):
|
|||
class AssistantView(SecureModelView):
|
||||
can_view_details = True
|
||||
column_list = ["first_name", "last_name", "email", "user", "part_experiments"]
|
||||
column_details_list = column_list + ["phone_number", "mobile_phone_number", "room", "building", "experiment_marks"]
|
||||
column_details_list = column_list + [
|
||||
"phone_number",
|
||||
"mobile_phone_number",
|
||||
"room",
|
||||
"building",
|
||||
"appointments",
|
||||
"experiment_marks",
|
||||
]
|
||||
column_filters = ["user.active"]
|
||||
form_excluded_columns = ["experiment_marks"]
|
||||
|
||||
|
||||
class GroupExperimentView(SecureModelView):
|
||||
class CreateForm(Form):
|
||||
def partExperimentQueryFactory():
|
||||
return PartExperiment.query.filter(
|
||||
PartExperiment.part_id.in_([part.id for part in userActiveSemester().parts])
|
||||
)
|
||||
|
||||
def assistantQueryFactory():
|
||||
return Assistant.query.filter(
|
||||
Assistant.user_id.in_([user.id for user in User.query.filter(User.active == True)])
|
||||
)
|
||||
|
||||
group = QuerySelectField(
|
||||
"Group", query_factory=groupQueryFactory, validators=[DataRequired()], allow_blank=True, blank_text="-"
|
||||
)
|
||||
part_experiment = QuerySelectField(
|
||||
"Part Experiment",
|
||||
query_factory=partExperimentQueryFactory,
|
||||
validators=[DataRequired()],
|
||||
allow_blank=True,
|
||||
blank_text="-",
|
||||
)
|
||||
|
||||
assistantBlankText = "Auto assign if experiment has only one assistant"
|
||||
|
||||
appointment1 = DateField("Appointment 1")
|
||||
appointment1_special = BooleanField("Appointment 1 special", default=False)
|
||||
appointment1_assistant = QuerySelectField(
|
||||
"Appointment 1 Assistant",
|
||||
query_factory=assistantQueryFactory,
|
||||
allow_blank=True,
|
||||
blank_text=assistantBlankText,
|
||||
)
|
||||
|
||||
appointment2 = DateField("Appointment 2")
|
||||
appointment2_special = BooleanField("Appointment 2 special", default=False)
|
||||
appointment2_assistant = QuerySelectField(
|
||||
"Appointment 2 Assistant",
|
||||
query_factory=assistantQueryFactory,
|
||||
allow_blank=True,
|
||||
blank_text=assistantBlankText,
|
||||
)
|
||||
|
||||
form = CreateForm
|
||||
|
||||
column_list = ["group", "part_experiment", "appointments", "experiment_marks"]
|
||||
column_filters = ["group", "part_experiment.experiment", "appointments"]
|
||||
|
||||
def get_query(self):
|
||||
return (
|
||||
|
@ -392,6 +446,10 @@ class GroupExperimentView(SecureModelView):
|
|||
)
|
||||
|
||||
|
||||
class AppointmentView(SecureModelView):
|
||||
column_list = ["date", "special", "group_experiment", "assistant"]
|
||||
|
||||
|
||||
admin.add_view(StudentView(Student, db.session))
|
||||
admin.add_view(PartStudentView(PartStudent, db.session))
|
||||
admin.add_view(GroupView(Group, db.session))
|
||||
|
@ -399,7 +457,7 @@ admin.add_view(GroupExperimentView(GroupExperiment, db.session))
|
|||
admin.add_view(ExperimentView(Experiment, db.session))
|
||||
admin.add_view(PartExperimentView(PartExperiment, db.session))
|
||||
admin.add_view(AssistantView(Assistant, db.session))
|
||||
admin.add_view(SecureModelView(Appointment, db.session))
|
||||
admin.add_view(AppointmentView(Appointment, db.session))
|
||||
admin.add_view(PartView(Part, db.session))
|
||||
admin.add_view(SemesterView(Semester, db.session))
|
||||
admin.add_view(SecureModelView(ExperimentMark, db.session))
|
||||
|
|
Loading…
Reference in a new issue