diff --git a/advlabdb/__init__.py b/advlabdb/__init__.py index 1486bca..1ad3195 100644 --- a/advlabdb/__init__.py +++ b/advlabdb/__init__.py @@ -41,9 +41,7 @@ assistantSpace = Admin( url="/assistant", endpoint="assistantSpace", template_mode="bootstrap3", - index_view=customClasses.SecureAssistantIndexView( - name="Assistant", template="assistant_index.html", url="/assistant", endpoint="assistantSpace" - ), + index_view=customClasses.SecureAssistantIndexView(name="Assistant", url="/assistant", endpoint="assistantSpace"), ) from advlabdb import models diff --git a/advlabdb/customClasses.py b/advlabdb/customClasses.py index 0d505d0..8fa0f61 100644 --- a/advlabdb/customClasses.py +++ b/advlabdb/customClasses.py @@ -2,9 +2,10 @@ from flask import flash, redirect, request, url_for from flask_admin import AdminIndexView, BaseView, expose from flask_admin.contrib.sqla import ModelView from flask_security import current_user +from sqlalchemy import and_ from advlabdb.exceptions import DataBaseException, ModelViewException -from advlabdb.models import ExperimentMark, Part, PartStudent +from advlabdb.models import ExperimentMark, Part, PartStudent, GroupExperiment, SemesterExperiment, Assistant from advlabdb.utils import reportBadAttempt, userActiveSemester @@ -28,13 +29,20 @@ class SecureAdminIndexView(CustomIndexView): @expose() def index(self): - number_of_missing_final_experiment_marks = ExperimentMark.query.filter( - ExperimentMark.part_student.has(PartStudent.part.has(Part.semester == userActiveSemester())), - ExperimentMark.final_experiment_mark == None, + active_semester_experiment_marks_query = ExperimentMark.query.filter( + ExperimentMark.part_student.has(PartStudent.part.has(Part.semester == userActiveSemester())) + ) + + number_of_all_experiment_marks = active_semester_experiment_marks_query.count() + + number_of_missing_final_experiment_marks = active_semester_experiment_marks_query.filter( + ExperimentMark.final_experiment_mark == None ).count() return self.render( - "admin_index.html", number_of_missing_final_experiment_marks=number_of_missing_final_experiment_marks + "admin_index.html", + number_of_missing_final_experiment_marks=number_of_missing_final_experiment_marks, + number_of_all_experiment_marks=number_of_all_experiment_marks, ) @@ -42,6 +50,31 @@ class SecureAssistantIndexView(CustomIndexView): def is_accessible(self): return assistantViewIsAccessible() + @expose() + def index(self): + active_semester_experiment_marks_query = ExperimentMark.query.filter( + ExperimentMark.group_experiment.has( + GroupExperiment.semester_experiment.has( + and_( + SemesterExperiment.semester == userActiveSemester(), + SemesterExperiment.assistants.any(Assistant.user == current_user), + ) + ) + ) + ) + + number_of_all_experiment_marks = active_semester_experiment_marks_query.count() + + number_of_missing_final_experiment_marks = active_semester_experiment_marks_query.filter( + ExperimentMark.final_experiment_mark == None + ).count() + + return self.render( + "assistant_index.html", + number_of_missing_final_experiment_marks=number_of_missing_final_experiment_marks, + number_of_all_experiment_marks=number_of_all_experiment_marks, + ) + class CustomModelView(ModelView): create_modal = True diff --git a/advlabdb/templates/admin_create.html b/advlabdb/templates/admin_create.html index 101410e..2c0c31a 100644 --- a/advlabdb/templates/admin_create.html +++ b/advlabdb/templates/admin_create.html @@ -2,6 +2,6 @@ {% extends "admin/model/create.html" %} {% block body %} -{{ information(current_user, userActiveSemester, role="admin") }} -{{super()}} +{{information(current_user, userActiveSemester, role="admin")}} +{{ super() }} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_edit.html b/advlabdb/templates/admin_edit.html index 5085861..62d4d34 100644 --- a/advlabdb/templates/admin_edit.html +++ b/advlabdb/templates/admin_edit.html @@ -2,6 +2,6 @@ {% extends "admin/model/edit.html" %} {% block body %} -{{ information(current_user, userActiveSemester, role="admin") }} -{{super()}} +{{information(current_user, userActiveSemester, role="admin")}} +{{ super() }} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_index.html b/advlabdb/templates/admin_index.html index 8c10c37..567b641 100644 --- a/advlabdb/templates/admin_index.html +++ b/advlabdb/templates/admin_index.html @@ -1,11 +1,11 @@ -{% from "macros.html" import information %} +{% from "macros.html" import information, missing_final_experiment_marks %} {% extends "admin/index.html" %} {% block body %} -{{ information(current_user, userActiveSemester, role="admin") }} +{{information(current_user, userActiveSemester, role="admin")}}

Welcome back, commander!

-

Number of missing final experiment marks: {{ number_of_missing_final_experiment_marks }}

+{{missing_final_experiment_marks(number_of_missing_final_experiment_marks, number_of_all_experiment_marks)}} -{{super()}} +{{ super() }} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_list.html b/advlabdb/templates/admin_list.html index 22fea54..a71b7ee 100644 --- a/advlabdb/templates/admin_list.html +++ b/advlabdb/templates/admin_list.html @@ -2,6 +2,6 @@ {% extends "admin/model/list.html" %} {% block body %} -{{ information(current_user, userActiveSemester, role="admin") }} -{{super()}} +{{information(current_user, userActiveSemester, role="admin")}} +{{ super() }} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/assistant_create.html b/advlabdb/templates/assistant_create.html index 2935891..c5804d5 100644 --- a/advlabdb/templates/assistant_create.html +++ b/advlabdb/templates/assistant_create.html @@ -3,5 +3,5 @@ {% block body %} {{ information(current_user, userActiveSemester, role="assistant") }} -{{super()}} +{{ super() }} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/assistant_edit.html b/advlabdb/templates/assistant_edit.html index cdcd722..1ec0883 100644 --- a/advlabdb/templates/assistant_edit.html +++ b/advlabdb/templates/assistant_edit.html @@ -2,6 +2,6 @@ {% extends "admin/model/edit.html" %} {% block body %} -{{ information(current_user, userActiveSemester, role="assistant") }} -{{super()}} +{{information(current_user, userActiveSemester, role="assistant")}} +{{ super() }} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/assistant_index.html b/advlabdb/templates/assistant_index.html index 08e6184..65753c1 100644 --- a/advlabdb/templates/assistant_index.html +++ b/advlabdb/templates/assistant_index.html @@ -1,8 +1,11 @@ -{% from "macros.html" import information %} +{% from "macros.html" import information, missing_final_experiment_marks %} {% extends "admin/index.html" %} {% block body %} -{{ information(current_user, userActiveSemester, role="assistant") }} +{{information(current_user, userActiveSemester, role="assistant")}}

Welcome back!

-{{super()}} + +{{missing_final_experiment_marks(number_of_missing_final_experiment_marks, number_of_all_experiment_marks)}} + +{{ super() }} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/assistant_list.html b/advlabdb/templates/assistant_list.html index 83abd6e..f201bca 100644 --- a/advlabdb/templates/assistant_list.html +++ b/advlabdb/templates/assistant_list.html @@ -2,6 +2,6 @@ {% extends "admin/model/list.html" %} {% block body %} -{{ information(current_user, userActiveSemester, role="assistant") }} -{{super()}} +{{information(current_user, userActiveSemester, role="assistant")}} +{{ super() }} {% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/import.html b/advlabdb/templates/import.html index 4061415..2185e82 100644 --- a/advlabdb/templates/import.html +++ b/advlabdb/templates/import.html @@ -2,11 +2,11 @@ {% extends "admin/master.html" %} {% block body %} -{{ information(current_user, userActiveSemester, role="admin") }} +{{information(current_user, userActiveSemester, role="admin")}} {% for error in form.file.errors %}
- Error! {{error}} + Error! {{ error }}
{% endfor %} diff --git a/advlabdb/templates/macros.html b/advlabdb/templates/macros.html index 15cd6f3..75b2228 100644 --- a/advlabdb/templates/macros.html +++ b/advlabdb/templates/macros.html @@ -1,11 +1,18 @@ {% macro information(current_user, userActiveSemester, role) %} -User: {{current_user.repr()}} +User: {{ current_user.repr() }} -| Active semester: {{userActiveSemester(flashWarning=True).repr()}} +| Active semester: {{ userActiveSemester(flashWarning=True).repr() }} {% if (role == "admin") and (current_user.has_role("assistant")) %} -| Assistant space. +| Assistant space. {% elif (role == "assistant") and (current_user.has_role("admin")) %} -| Admin space. +| Admin space. {% endif %} +{% endmacro %} + +{% macro missing_final_experiment_marks(number_of_missing_final_experiment_marks, number_of_all_experiment_marks) %} +

+ Number of missing final experiment marks: + {{ number_of_missing_final_experiment_marks }} / {{ number_of_all_experiment_marks }} +

{% endmacro %} \ No newline at end of file