diff --git a/advlabdb/assistantModelViews.py b/advlabdb/assistantModelViews.py index 4165bef..36a3b00 100644 --- a/advlabdb/assistantModelViews.py +++ b/advlabdb/assistantModelViews.py @@ -3,6 +3,7 @@ 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 markupsafe import Markup from wtforms.fields import TextAreaField from wtforms.validators import Optional @@ -54,25 +55,7 @@ class AssistantGroupExperimentView(SecureAssistantModelView): "group.part_students": "Students", } - 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 - - def appointments_formatter(view, context, model, name): - appointments = deep_getattr(model, name) - if appointments is not None: - return ", ".join([str(appointment.date) for appointment in appointments]) - - return attr - - column_formatters = { - "semester_experiment.experiment": str_formatter, - "group.part_students": part_students_formatter, - "appointments": appointments_formatter, - } + column_default_sort = ("experiment_marks_missing", True) column_extra_row_actions = [ EndpointLinkRowAction( @@ -82,6 +65,34 @@ class AssistantGroupExperimentView(SecureAssistantModelView): ) ] + 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 "" + + def appointments_formatter(view, context, model, name): + appointments = deep_getattr(model, name) + if appointments is not None: + return ", ".join([str(appointment.date) for appointment in appointments]) + + return "" + + def experiment_marks_missing_formatter(view, context, model, name): + experiment_marks_missing = getattr(model, name) + if experiment_marks_missing is True: + return Markup("Yes") + + return "No" + + column_formatters = { + "semester_experiment.experiment": str_formatter, + "group.part_students": part_students_formatter, + "appointments": appointments_formatter, + "experiment_marks_missing": experiment_marks_missing_formatter, + } + def query_modifier(self, query): return ( query.join(SemesterExperiment)