mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-30 18:03:52 +00:00
Remove old views
This commit is contained in:
parent
82e2e9977f
commit
22ee6f7c54
1 changed files with 22 additions and 141 deletions
|
@ -1,5 +1,6 @@
|
|||
from flask import flash, redirect, request, url_for
|
||||
from flask_admin import expose
|
||||
from flask_admin.model.template import EndpointLinkRowAction
|
||||
from flask_security import admin_change_password, current_user
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms.fields import TextAreaField
|
||||
|
@ -37,14 +38,6 @@ from .models import (
|
|||
|
||||
|
||||
class AssistantGroupExperimentView(SecureAssistantModelView):
|
||||
class EditForm(FlaskForm):
|
||||
note = TextAreaField(
|
||||
"Note",
|
||||
validators=[Optional()],
|
||||
description="This note is optional and can be seen and edited by admins and assistants that are responsible for this semester experiment. This note is for information related to the experiment and group. Examples: Protocol received, submission until ..., etc.",
|
||||
)
|
||||
|
||||
can_edit = True
|
||||
column_display_actions = True
|
||||
|
||||
column_list = [
|
||||
|
@ -81,6 +74,14 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
|
|||
"appointments": appointments_formatter,
|
||||
}
|
||||
|
||||
column_extra_row_actions = [
|
||||
EndpointLinkRowAction(
|
||||
icon_class="fa fa-pencil",
|
||||
endpoint="assistant_groupexperiment.form_view",
|
||||
title="Edit",
|
||||
)
|
||||
]
|
||||
|
||||
def query_modifier(self, query):
|
||||
return (
|
||||
query.join(SemesterExperiment)
|
||||
|
@ -128,8 +129,19 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
|
|||
appointment.date = appointment_fields[ind].data
|
||||
|
||||
for ind, experiment_mark in enumerate(experiment_marks):
|
||||
experiment_mark.oral_mark = parse_selection_mark_field(oral_experiment_mark_fields[ind])
|
||||
experiment_mark.protocol_mark = parse_selection_mark_field(protocol_experiment_mark_fields[ind])
|
||||
form_oral_mark = parse_selection_mark_field(oral_experiment_mark_fields[ind])
|
||||
form_protocol_mark = parse_selection_mark_field(protocol_experiment_mark_fields[ind])
|
||||
|
||||
if (
|
||||
form_oral_mark != experiment_mark.oral_mark
|
||||
or form_protocol_mark != experiment_mark.protocol_mark
|
||||
):
|
||||
experiment_mark.oral_mark = form_oral_mark
|
||||
experiment_mark.protocol_mark = form_protocol_mark
|
||||
|
||||
experiment_mark.assistant = current_user.assistant
|
||||
|
||||
experiment_mark.part_student.checkThenSetFinalPartMark()
|
||||
|
||||
group_experiment.note = form.note.data
|
||||
|
||||
|
@ -159,131 +171,6 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
|
|||
)
|
||||
|
||||
|
||||
class AssistantAppointmentView(SecureAssistantModelView):
|
||||
can_edit = True
|
||||
|
||||
column_list = [
|
||||
"date",
|
||||
"special",
|
||||
"group_experiment.semester_experiment.experiment",
|
||||
"group_experiment.group.number",
|
||||
"group_experiment.group.part_students",
|
||||
]
|
||||
column_labels = {
|
||||
"group_experiment.semester_experiment.experiment": "Experiment",
|
||||
"group_experiment.group.number": "Group number",
|
||||
"group_experiment.group.part_students": "Students",
|
||||
}
|
||||
|
||||
column_editable_list = [
|
||||
"date",
|
||||
]
|
||||
form_columns = column_editable_list
|
||||
column_descriptions = {
|
||||
"special": "A special appointment should take place in the semester break",
|
||||
}
|
||||
|
||||
def part_students_formatter(view, context, model, name):
|
||||
part_students = deep_getattr(model, name)
|
||||
if part_students is not None:
|
||||
return ", ".join([str(part_student.student) for part_student in part_students])
|
||||
|
||||
return attr
|
||||
|
||||
column_formatters = {
|
||||
"group_experiment.semester_experiment.experiment": str_formatter,
|
||||
"group_experiment.group.part_students": part_students_formatter,
|
||||
}
|
||||
|
||||
def query_modifier(self, query):
|
||||
return (
|
||||
query.join(GroupExperiment)
|
||||
.join(SemesterExperiment)
|
||||
.where(
|
||||
SemesterExperiment.semester == current_user.active_semester,
|
||||
Appointment.assistant == current_user.assistant,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class AssistantExperimentMarkView(SecureAssistantModelView):
|
||||
class EditForm(FlaskForm):
|
||||
oral_mark = mark_field("Oral")
|
||||
protocol_mark = mark_field("Protocol")
|
||||
|
||||
can_edit = True
|
||||
column_display_actions = True
|
||||
|
||||
column_list = [
|
||||
"oral_mark",
|
||||
"protocol_mark",
|
||||
"final_experiment_mark",
|
||||
"group_experiment.semester_experiment.experiment.number",
|
||||
"part_student.student",
|
||||
"part_student.group.number",
|
||||
"part_student.student.uni_email",
|
||||
"part_student.student.contact_email",
|
||||
"part_student.part",
|
||||
"assistant",
|
||||
"admin",
|
||||
]
|
||||
column_labels = {
|
||||
"group_experiment.semester_experiment.experiment.number": "Experiment number",
|
||||
"part_student.student": "Student",
|
||||
"part_student.group.number": "Group number",
|
||||
"part_student.student.uni_email": "Uni Email",
|
||||
"part_student.student.contact_email": "Contact Email",
|
||||
"part_student.part": "Part",
|
||||
}
|
||||
column_descriptions = {
|
||||
"oral_mark": f"Between {MIN_MARK} and {MAX_MARK}",
|
||||
"protocol_mark": f"Between {MIN_MARK} and {MAX_MARK}",
|
||||
"final_experiment_mark": "Calculated automatically with oral and protocol marks and weightings",
|
||||
"part_student.student.contact_email": "The preferred contact email address if entered by the student",
|
||||
"assistant": "The last assistant who edited the mark",
|
||||
"admin": "The last admin who edited the mark",
|
||||
}
|
||||
|
||||
column_searchable_list = [
|
||||
"part_student.student.first_name",
|
||||
"part_student.student.last_name",
|
||||
"part_student.student.uni_email",
|
||||
"part_student.student.contact_email",
|
||||
]
|
||||
|
||||
column_formatters = {
|
||||
"oral_mark": missing_formatter,
|
||||
"protocol_mark": missing_formatter,
|
||||
"part_student.part": str_without_semester_formatter,
|
||||
}
|
||||
|
||||
column_default_sort = [("oral_mark", False), ("protocol_mark", False)]
|
||||
|
||||
def query_modifier(self, query):
|
||||
return (
|
||||
query.join(GroupExperiment)
|
||||
.join(SemesterExperiment)
|
||||
.where(SemesterExperiment.semester == current_user.active_semester)
|
||||
.join(SemesterExperiment.assistants)
|
||||
.where(Assistant.user == current_user)
|
||||
)
|
||||
|
||||
def update_model(self, form, model):
|
||||
if (form.oral_mark is not None and form.oral_mark.data != model.oral_mark) or (
|
||||
form.protocol_mark is not None and form.protocol_mark.data != model.protocol_mark
|
||||
):
|
||||
model.assistant = current_user.assistant
|
||||
|
||||
updateSuccessful = super().update_model(form, model)
|
||||
|
||||
model.part_student.checkThenSetFinalPartMark()
|
||||
|
||||
return updateSuccessful
|
||||
else:
|
||||
# Nothing changed
|
||||
return True
|
||||
|
||||
|
||||
class AssistantUserView(SecureAssistantModelView):
|
||||
class EditForm(FlaskForm):
|
||||
phone_number, mobile_phone_number, building, room = user_info_fields()
|
||||
|
@ -330,12 +217,6 @@ assistantSpace.add_view(
|
|||
GroupExperiment, db.session, endpoint="assistant_groupexperiment", url="group_experiment"
|
||||
)
|
||||
)
|
||||
assistantSpace.add_view(
|
||||
AssistantAppointmentView(Appointment, db.session, endpoint="assistant_appointment", url="appointment")
|
||||
)
|
||||
assistantSpace.add_view(
|
||||
AssistantExperimentMarkView(ExperimentMark, db.session, endpoint="assistant_experimentmark", url="experiment_mark")
|
||||
)
|
||||
assistantSpace.add_view(AssistantUserView(User, db.session, endpoint="assistant_user", url="user"))
|
||||
assistantSpace.add_view(AssistantDocsView(name="Docs", endpoint="assistant_docs", url="docs"))
|
||||
|
||||
|
|
Loading…
Reference in a new issue