diff --git a/advlabdb/modelViews.py b/advlabdb/modelViews.py index 857e02a..5050c39 100644 --- a/advlabdb/modelViews.py +++ b/advlabdb/modelViews.py @@ -27,9 +27,9 @@ from advlabdb.models import ( Semester, Student, User, + Program, ) from advlabdb.utils import ( - partFromLabelInUserActiveSemester, randomPassword, setUserActiveSemester, userActiveSemester, @@ -100,12 +100,12 @@ class SemesterView(SecureModelView): can_delete = False can_view_details = True - column_list = ["label", "parts"] - column_details_list = column_list + ["active_users"] - form_columns = ["semester_label", "year", "transfer_parts", "transfer_assistants"] + column_list = ["label", "number", "parts"] + column_details_list = column_list + ["active_users", "groups"] + form_columns = ["label", "year", "transfer_parts", "transfer_assistants"] form_extra_fields = { - "semester_label": RadioField("Semester", choices=["WS", "SS"], validators=[DataRequired()]), + "label": RadioField("Semester", choices=["WS", "SS"], validators=[DataRequired()]), "year": TextField("Year", validators=[DataRequired()]), "transfer_parts": BooleanField( "Transfer parts", @@ -121,7 +121,7 @@ class SemesterView(SecureModelView): def create_model(self, form): try: - model = Semester(label=form.semester_label.data + form.year.data) + model = Semester(label=form.label.data, year=form.year.data) self.session.add(model) self.on_model_change(form, model, True) @@ -137,7 +137,7 @@ class SemesterView(SecureModelView): def after_model_change(self, form, model, is_created): admin.add_link( MenuLink( - name=model.label, + name=model.repr(), url=url_for("set_semester") + "?semester_id=" + str(model.id), category="Active semester", ) @@ -174,8 +174,8 @@ class SemesterView(SecureModelView): class PartView(SecureModelView): can_view_details = True - column_details_list = ["label", "semester", "part_students", "groups"] - form_columns = ["label", "semester"] + column_details_list = ["program", "number", "semester", "part_students"] + form_columns = ["program", "number", "semester"] def queryFilter(self): return Part.semester == userActiveSemester() @@ -212,7 +212,7 @@ def partQueryFactory(): def groupQueryFactory(): - return Group.query.filter(Group.part_id.in_([part.id for part in userActiveSemester().parts])) + return Group.query.filter(Group.semester == userActiveSemester()) markChoices = [(-1, "-")] + list(zip(range(16)[::-1], range(16)[::-1])) @@ -261,8 +261,7 @@ class PartStudentView(SecureModelView): return form(get_form_data(), obj=obj) def on_model_change(self, form, model, is_created): - if model.group and model.part != model.group.part: - raise ModelViewException("Student's part and group's part do not match!") + PartStudent.check(model.group, model.group) def update_model(self, form, model): if form.final_part_mark.data == -1: @@ -277,29 +276,21 @@ def partStudentsQueryFactory(): class GroupView(SecureModelView): class CreateForm(Form): - part = QuerySelectField( - "Part", - query_factory=partQueryFactory, - validators=[DataRequired()], - allow_blank=True, - blank_text="-", + part_students = QuerySelectMultipleField( + "Part Students", query_factory=partStudentsQueryFactory, validators=[DataRequired()] ) - part_students = QuerySelectMultipleField("Part Students", query_factory=partStudentsQueryFactory) - class EditForm(CreateForm): - part = None + form = CreateForm - form = EditForm - - column_list = ["number", "part", "part_students", "group_experiments"] - column_filters = ["number", "part"] + column_list = ["number", "semester", "program", "part_students", "group_experiments"] + column_filters = ["number", "semester", "program"] def queryFilter(self): - return Group.part_id.in_([part.id for part in userActiveSemester().parts]) + return Group.semester == userActiveSemester() def create_model(self, form): try: - model = Group.customInit(form.part.data, form.part_students.data) + model = Group.customInit(form.part_students.data) self.session.add(model) self.on_model_change(form, model, True) @@ -313,19 +304,15 @@ class GroupView(SecureModelView): return model def update_model(self, form, model): - Group.checkPartStudents(form.part_students.data) + Group.check(form.part_students.data, model.program) return super().update_model(form, model) - def create_form(self, obj=None): - form = self.CreateForm - return form(get_form_data(), obj=obj) - class ExperimentView(SecureModelView): can_view_details = True column_filters = ["active"] - column_list = ["label", "title", "active"] + column_list = ["number", "program", "title", "active"] column_details_list = column_list + [ "desciption", "wiki_link", @@ -420,10 +407,7 @@ class GroupExperimentView(SecureModelView): def queryFilter(self): return GroupExperiment.group_id.in_( - [ - group.id - for group in Group.query.filter(Group.part_id.in_([part.id for part in userActiveSemester().parts])) - ] + [group.id for group in Group.query.filter(Group.semester == userActiveSemester())] ) def create_model(self, form): @@ -617,6 +601,11 @@ class ExperimentMarkView(SecureModelView): self.session.rollback() +class ProgramView(SecureModelView): + column_list = ["label"] + column_details_list = column_list + ["parts", "experiments", "groups"] + + admin.add_view(StudentView(Student, db.session)) admin.add_view(PartStudentView(PartStudent, db.session)) admin.add_view(GroupView(Group, db.session)) @@ -626,6 +615,7 @@ admin.add_view(ExperimentMarkView(ExperimentMark, db.session)) admin.add_view(ExperimentView(Experiment, db.session)) admin.add_view(SemesterExperimentView(SemesterExperiment, db.session)) admin.add_view(AssistantView(Assistant, db.session)) +admin.add_view(ProgramView(Program, db.session)) admin.add_view(PartView(Part, db.session)) admin.add_view(SemesterView(Semester, db.session)) admin.add_view(UserView(User, db.session)) @@ -636,7 +626,7 @@ with app.app_context(): for semester in semesters: admin.add_link( MenuLink( - name=semester.label, + name=semester.repr(), url=url_for("set_semester") + "?semester_id=" + str(semester.id), category="Active semester", ) diff --git a/advlabdb/templates/admin_create.html b/advlabdb/templates/admin_create.html index 3d03b5d..eccc7f6 100644 --- a/advlabdb/templates/admin_create.html +++ b/advlabdb/templates/admin_create.html @@ -1,6 +1,6 @@ {% extends "admin/model/create.html" %} {% block body %} - User's active semester: {{userActiveSemester().label}} - {{super()}} -{% endblock %} +User's active semester: {{userActiveSemester().repr()}} +{{super()}} +{% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_edit.html b/advlabdb/templates/admin_edit.html index 86bc81f..66b2c8d 100644 --- a/advlabdb/templates/admin_edit.html +++ b/advlabdb/templates/admin_edit.html @@ -1,6 +1,6 @@ {% extends "admin/model/edit.html" %} {% block body %} - User's active semester: {{userActiveSemester().label}} - {{super()}} -{% endblock %} +User's active semester: {{userActiveSemester().repr()}} +{{super()}} +{% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_index.html b/advlabdb/templates/admin_index.html index bbe11ea..9c6dd12 100644 --- a/advlabdb/templates/admin_index.html +++ b/advlabdb/templates/admin_index.html @@ -1,7 +1,7 @@ {% extends "admin/index.html" %} {% block body %} - User's active semester: {{userActiveSemester(flashWarning=True).label}} -

Welcome back, commander!

- {{super()}} -{% endblock %} +User's active semester: {{userActiveSemester(flashWarning=True).repr()}} +

Welcome back, commander!

+{{super()}} +{% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/admin_list.html b/advlabdb/templates/admin_list.html index 609b1d8..1401d0b 100644 --- a/advlabdb/templates/admin_list.html +++ b/advlabdb/templates/admin_list.html @@ -1,6 +1,6 @@ {% extends "admin/model/list.html" %} {% block body %} - User's active semester: {{userActiveSemester(flashWarning=True).label}} - {{super()}} -{% endblock %} +User's active semester: {{userActiveSemester(flashWarning=True).repr()}} +{{super()}} +{% endblock %} \ No newline at end of file diff --git a/advlabdb/templates/layout.html b/advlabdb/templates/layout.html index b141405..97397c0 100644 --- a/advlabdb/templates/layout.html +++ b/advlabdb/templates/layout.html @@ -1,81 +1,79 @@ - - - - - - - - - - + + + + - {% if title %} - {{title}} - {% else %} - AdvLabDB - {% endif %} - - - + + + + + + + + AdvLabDB + + + + +
+
+ {% with messages = get_flashed_messages(with_categories=True) %} + {% if messages %} + {% for category, message in messages %} +
+ {{message}} +
+ {% endfor %} + {% endif %} + {% endwith %} - - - - - - - - - - - - - {% block scripts %}{% endblock scripts %} - - + {% block content %}{% endblock content %} +
+
+ + + + + + + + + + + + + + {% block scripts %}{% endblock scripts %} + + + \ No newline at end of file