Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪲 fix preview class banner #5416

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@
{% if menu != False %}
{% include "incl/menubar.html" %}
{% endif %}
{% if session.preview_class %}
<div class="bg-red-500 text-white text-sm font-bold px-4 py-3" data-cy="preview_class_banner" role="alert">
<div class="text-center center-text">{{_('previewing_class').format(class_name=session.preview_class["name"])}} <a class="text-white" href="/for-teachers/clear-preview-class">{{_('exit_preview_mode')}}</a></div>
</div>
{% endif %}
{# Can't reindent this as it may contain preformatted code blocks whose indentation is important. #}
{% block full_width_content %}{% endblock %}

Expand Down
5 changes: 5 additions & 0 deletions templates/level-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

{% block full_width_content %}
{% if not raw %}
{% if not raw and session.preview_class %}
<div class="bg-red-500 text-white text-sm font-bold px-4 py-3" data-cy="preview_class_banner" role="alert">
<div class="text-center center-text">{{_('previewing_class').format(class_name=session.preview_class["name"])}} <a class="text-white" href="/for-teachers/clear-preview-class">{{_('exit_preview_mode')}}</a></div>
</div>
{% endif %}
{% if customizations and customizations["teachers_adventure"] %}
<div class="bg-red-500 text-white text-sm font-bold px-4 py-3" data-cy="preview_adventure_banner" role="alert">
<div class="text-center center-text">{{_('previewing_adventure')}}
Expand Down
7 changes: 7 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,3 +499,10 @@ def replace(match):
content += "<p>&nbsp;</p>"

return content


def remove_class_preview():
try:
del session["preview_class"]
except KeyError:
pass
3 changes: 2 additions & 1 deletion website/auth_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from config import config
from safe_format import safe_format
from hedy_content import ALL_LANGUAGES, COUNTRIES
from utils import extract_bcrypt_rounds, is_heroku, is_testing_request, timems, times
from utils import extract_bcrypt_rounds, is_heroku, is_testing_request, timems, times, remove_class_preview
from website.auth import (
MAILCHIMP_API_URL,
RESET_LENGTH,
Expand Down Expand Up @@ -247,6 +247,7 @@ def logout(self):
if request.cookies.get(TOKEN_COOKIE_NAME):
self.db.forget_token(request.cookies.get(TOKEN_COOKIE_NAME))
session[JUST_LOGGED_OUT] = True
remove_class_preview()
return "", 200

@ route("/destroy", methods=["POST"])
Expand Down
5 changes: 1 addition & 4 deletions website/for_teachers.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ def preview_class_as_teacher(self, user, class_id):
@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
utils.remove_class_preview()
return redirect("/for-teachers")

@route("/class/<class_id>/programs/<username>", methods=["GET", "POST"])
Expand Down
Loading