From 3412657ca7e9443b05ae2576be3a05c1528a2a56 Mon Sep 17 00:00:00 2001 From: Mo8it Date: Wed, 1 Jun 2022 23:03:41 +0200 Subject: [PATCH] Replace editables with form for assistants' marks --- advlabdb/assistantModelViews.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/advlabdb/assistantModelViews.py b/advlabdb/assistantModelViews.py index 5ee32e6..87266c6 100644 --- a/advlabdb/assistantModelViews.py +++ b/advlabdb/assistantModelViews.py @@ -1,11 +1,12 @@ from flask import flash from flask_admin import expose from flask_security import admin_change_password, current_user -from wtforms import BooleanField, Form, StringField +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 flashRandomPassword +from .advlabdb_independent_funs import flashRandomPassword, missing_formatter from .customClasses import SecureAssistantBaseView, SecureAssistantModelView from .exceptions import DataBaseException, ModelViewException from .model_dependent_funs import initActiveSemesterMenuLinks @@ -58,7 +59,20 @@ 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}", + ) + can_edit = True + column_display_actions = True column_list = [ "oral_mark", @@ -99,16 +113,10 @@ class AssistantExperimentMarkView(SecureAssistantModelView): "part_student.student.contact_email", ] - column_editable_list = [ - "oral_mark", - "protocol_mark", - ] - form_columns = column_editable_list - - form_args = { - "oral_mark": {"validators": [Optional(), NumberRange(MIN_MARK, MAX_MARK)]}, - "protocol_mark": {"validators": [Optional(), NumberRange(MIN_MARK, MAX_MARK)]}, - } + column_formatters = dict( + oral_mark=missing_formatter, + protocol_mark=missing_formatter, + ) column_default_sort = [("oral_mark", False), ("protocol_mark", False)]