1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Improved feedback after changing experiment mark

This commit is contained in:
Mo 2021-08-21 22:58:23 +02:00
parent e998839bf1
commit 9430654ea1
2 changed files with 30 additions and 11 deletions

View file

@ -7,7 +7,7 @@ from flask_admin.model.template import EndpointLinkRowAction
from flask_security import admin_change_password, current_user, hash_password from flask_security import admin_change_password, current_user, hash_password
from sqlalchemy import func, or_, and_ from sqlalchemy import func, or_, and_
from wtforms import BooleanField, Form, RadioField, SelectField, TextField from wtforms import BooleanField, Form, RadioField, SelectField, TextField
from wtforms.fields.html5 import DateField from wtforms.fields.html5 import DateField, IntegerField
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
from advlabdb import adminSpace, app, assistantSpace, db, user_datastore from advlabdb import adminSpace, app, assistantSpace, db, user_datastore
@ -689,9 +689,19 @@ class ExperimentMarkView(SecureAdminModelView):
blank_text="-", blank_text="-",
) )
form = CreateForm class EditForm(Form):
oral_mark = IntegerField(
"Oral Mark",
validators=[NumberRange(min=0, max=15), Optional()],
description="Between 0 and 15",
)
protocol_mark = IntegerField(
"Protocol Mark",
validators=[NumberRange(min=0, max=15), Optional()],
description="Between 0 and 15",
)
can_edit = False form = EditForm
column_descriptions = { column_descriptions = {
"oral_mark": "Between 0 and 15", "oral_mark": "Between 0 and 15",
@ -700,12 +710,6 @@ class ExperimentMarkView(SecureAdminModelView):
"edited_by_admin": "If the mark was edited by an admin", "edited_by_admin": "If the mark was edited by an admin",
} }
column_editable_list = ["oral_mark", "protocol_mark"]
form_args = {
"oral_mark": {"validators": [NumberRange(0, 15)]},
"protocol_mark": {"validators": [NumberRange(0, 15)]},
}
column_filters = [ column_filters = [
StudentIdFilter(PartStudent.id, "Student / ID"), StudentIdFilter(PartStudent.id, "Student / ID"),
"part_student.part.program", "part_student.part.program",
@ -727,6 +731,10 @@ class ExperimentMarkView(SecureAdminModelView):
) )
""" """
def create_form(self, obj=None):
form = self.CreateForm
return form(get_form_data(), obj=obj)
def customCreateModel(self, form): def customCreateModel(self, form):
return ExperimentMark.customInit( return ExperimentMark.customInit(
part_student=form.part_student.data, group_experiment=form.group_experiment.data part_student=form.part_student.data, group_experiment=form.group_experiment.data

View file

@ -8,6 +8,7 @@ https://flask-sqlalchemy.palletsprojects.com/en/2.x/models/
# Imports # Imports
from flask import flash, has_request_context from flask import flash, has_request_context
from flask_security import current_user
from flask_security.models.fsqla_v2 import FsRoleMixin, FsUserMixin from flask_security.models.fsqla_v2 import FsRoleMixin, FsUserMixin
from decimal import Decimal, ROUND_HALF_UP from decimal import Decimal, ROUND_HALF_UP
@ -114,8 +115,18 @@ class PartStudent(db.Model):
self.session.rollback() self.session.rollback()
else: else:
if oldFinalPartMark != self.final_part_mark: if current_user.has_role("admin"):
flash(f"Final part mark changed for {self} from {oldFinalPartMark} to {self.final_part_mark}.") if oldFinalPartMark != self.final_part_mark:
if oldFinalPartMark > self.final_part_mark:
category = "danger"
else:
category = "warning"
flash(
f"Final part mark changed for {self} from {oldFinalPartMark} to {self.final_part_mark}.",
category,
)
else:
flash(f"Final part mark did not change for {self} from {oldFinalPartMark}.")
def repr(self): def repr(self):
return f"{self.student.repr()} {self.part.repr()}" return f"{self.student.repr()} {self.part.repr()}"