diff --git a/app.py b/app.py index 637f6ee6c51..83d84ddfbab 100644 --- a/app.py +++ b/app.py @@ -1313,7 +1313,8 @@ def index(level, program_id): customizations = {} if current_user()['username']: - customizations = DATABASE.get_student_class_customizations(current_user()['username']) + customizations = DATABASE.get_student_class_customizations( + current_user()['username'], preview_class_as_teacher=session.get("preview_class")) if 'levels' in customizations: available_levels = customizations['levels'] diff --git a/templates/for-teachers.html b/templates/for-teachers.html index 6fd921b4dda..0a3aa850c0a 100644 --- a/templates/for-teachers.html +++ b/templates/for-teachers.html @@ -22,6 +22,7 @@

{{_('my_classes')}}

{{_('students')[0]|upper}}{{_('students')[1:]}} {{_('duplicate')}} + {{_('preview')}} {{_('remove')}} @@ -32,6 +33,7 @@

{{_('my_classes')}}

{{class.teacher}} {{class.students|length}} + 👁 🗑️ {% endfor %} diff --git a/templates/layout.html b/templates/layout.html index 73e204b4e0b..537498b75ea 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -78,6 +78,12 @@ {% if menu != False %} {% include "incl/menubar.html" %} {% endif %} + {% if session.preview_class %} + + {% endif %} {# Can't reindent this as it may contain preformatted code blocks whose indentation is important. #} {% block full_width_content %}{% endblock %} diff --git a/website/database.py b/website/database.py index 4a848564376..5d957d7ba06 100644 --- a/website/database.py +++ b/website/database.py @@ -765,7 +765,7 @@ def get_class_customizations(self, class_id): customizations = CUSTOMIZATIONS.get({"id": class_id}) return customizations - def get_student_class_customizations(self, user): + def get_student_class_customizations(self, user, preview_class_as_teacher=None): """Return customizations for the very first class this user is part of. If the user is part of multiple classes, they will only get the customizations @@ -775,6 +775,11 @@ def get_student_class_customizations(self, user): if student_classes: class_customizations = self.get_class_customizations(student_classes[0]["id"]) return class_customizations or {} + elif preview_class_as_teacher: + for Class in self.get_teacher_classes(user): + if preview_class_as_teacher == Class["id"]: + class_customizations = self.get_class_customizations(preview_class_as_teacher) + return class_customizations or {} return {} def progress_by_username(self, username): diff --git a/website/for_teachers.py b/website/for_teachers.py index 2f1101e048e..d8a5df97130 100644 --- a/website/for_teachers.py +++ b/website/for_teachers.py @@ -3,7 +3,7 @@ import os import uuid -from flask import g, jsonify, request, session, url_for +from flask import g, jsonify, request, session, url_for, redirect from jinja_partials import render_partial from flask_babel import gettext @@ -208,6 +208,26 @@ def get_class(self, user, class_id): survey_later=survey_later, ) + @route("/class//preview", methods=["GET"]) + @requires_login + def preview_class_as_teacher(self, user, class_id): + if not is_teacher(user) and not is_admin(user): + return utils.error_page(error=403, ui_message=gettext("retrieve_class_error")) + Class = self.db.get_class(class_id) + if not Class or (not utils.can_edit_class(user, Class) and not is_admin(user)): + return utils.error_page(error=404, ui_message=gettext("no_such_class")) + session["preview_class"] = Class["id"] + return redirect("/hedy") + + @route("/clear-preview-class", methods=["GET"]) + # Note: we explicitly do not need login here, anyone can exit preview mode + def clear_preview_class(self): + try: + del session["preview_class"] + except KeyError: + pass + return redirect("/for-teachers") + @route("/class//programs/", methods=["GET", "POST"]) @requires_teacher def public_programs(self, user, class_id, username):