From 6f0db77aabb3d10d741c74cd23903fe5826d7b56 Mon Sep 17 00:00:00 2001 From: Becky Smith Date: Mon, 8 Jul 2024 11:37:58 +0100 Subject: [PATCH] Make disclaimers visible from profile --- accounts/urls.py | 3 ++- accounts/views.py | 10 ++++++++++ studioadmin/views/disclaimers.py | 20 ++++++++++++-------- templates/account/profile.html | 2 +- templates/studioadmin/user_disclaimer.html | 2 ++ 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/accounts/urls.py b/accounts/urls.py index 8bf450eb..d8f6b4d7 100644 --- a/accounts/urls.py +++ b/accounts/urls.py @@ -1,6 +1,6 @@ from django.urls import path from accounts.views import ProfileUpdateView, profile, \ - SignedDataPrivacyCreateView + SignedDataPrivacyCreateView, user_disclaimer app_name = 'profile' @@ -12,5 +12,6 @@ 'data-privacy-review/', SignedDataPrivacyCreateView.as_view(), name='data_privacy_review' ), + path("disclaimer", user_disclaimer, name='view_latest_disclaimer'), path('', profile, name='profile'), ] diff --git a/accounts/views.py b/accounts/views.py index ffe396c8..693719c1 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -25,6 +25,7 @@ from activitylog.models import ActivityLog from booking.email_helpers import send_mail from common.mailchimp_utils import update_mailchimp +from studioadmin.views.disclaimers import user_disclaimer_view_context @login_required @@ -357,3 +358,12 @@ def get_success_url(self, form=None): if form and form.next_url: return form.next_url return reverse('booking:lessons') + + +@login_required +def user_disclaimer(request): + ctx = user_disclaimer_view_context(user_id=request.user.id) + ctx["editable"] = False + return TemplateResponse( + request, "studioadmin/user_disclaimer.html", ctx + ) \ No newline at end of file diff --git a/studioadmin/views/disclaimers.py b/studioadmin/views/disclaimers.py index 1049ae79..1fe70b7b 100644 --- a/studioadmin/views/disclaimers.py +++ b/studioadmin/views/disclaimers.py @@ -141,21 +141,25 @@ def disclaimer_content_view(request, version): request, "studioadmin/disclaimer_content_view.html", ctx ) -@login_required -@is_instructor_or_staff -def user_disclaimer(request, encoded_user_id): - # get last disclaimer for this user - user_id = dechaffify(str_int(encoded_user_id)) +def user_disclaimer_view_context(user_id=None, encoded_user_id=None): + + # get last disclaimer for this user + user_id = user_id or dechaffify(str_int(encoded_user_id)) disclaimer = OnlineDisclaimer.objects.filter(user__id=user_id).last() disclaimer_content = DisclaimerContent.objects.get(version=disclaimer.version) - ctx = { + return { 'disclaimer': disclaimer, 'disclaimer_content': disclaimer_content, - 'encoded_user_id': encoded_user_id - } + 'encoded_user_id': encoded_user_id, + } +@login_required +@is_instructor_or_staff +def user_disclaimer(request, encoded_user_id): + ctx = user_disclaimer_view_context(encoded_user_id=encoded_user_id) + ctx["editable"] = True return TemplateResponse( request, "studioadmin/user_disclaimer.html", ctx ) diff --git a/templates/account/profile.html b/templates/account/profile.html index 4fa7dde8..de47269f 100644 --- a/templates/account/profile.html +++ b/templates/account/profile.html @@ -93,7 +93,7 @@

Account Info

Disclaimer: {% if disclaimer %} - Completed + Completed View {% elif expired_disclaimer %} Expired {% else %} diff --git a/templates/studioadmin/user_disclaimer.html b/templates/studioadmin/user_disclaimer.html index 9fbd534f..359c83db 100644 --- a/templates/studioadmin/user_disclaimer.html +++ b/templates/studioadmin/user_disclaimer.html @@ -5,6 +5,7 @@ {% block studioadmincontent %}
+ {% if editable %}
{% if request.user.is_staff or request.user.is_instructor %} @@ -25,6 +26,7 @@ {% endif %} {% endif %}
+ {% endif %}