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 @@
+
Preview mode
+
You are previewing a class as a teacher. Exit preview mode
+
+ {% 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/