From 7951469fd8d4f92a546b2aa796332bc3c36c9f98 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Fri, 3 May 2024 15:43:46 +0200 Subject: [PATCH] Add QR Code link to My Stuff Clicking the link will show a page with a QR Code linking to the previous page --- changelog.d/+qr-code-my-stuff.added.md | 1 + python/nav/web/templates/base.html | 1 + .../nav/web/templates/webfront/qr_code.html | 19 +++++++++++++++++++ python/nav/web/webfront/urls.py | 1 + python/nav/web/webfront/views.py | 18 ++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 changelog.d/+qr-code-my-stuff.added.md create mode 100644 python/nav/web/templates/webfront/qr_code.html diff --git a/changelog.d/+qr-code-my-stuff.added.md b/changelog.d/+qr-code-my-stuff.added.md new file mode 100644 index 0000000000..12b191305f --- /dev/null +++ b/changelog.d/+qr-code-my-stuff.added.md @@ -0,0 +1 @@ +Add link to My Stuff that leads to a generated QR Code linking to the page it is called from \ No newline at end of file diff --git a/python/nav/web/templates/base.html b/python/nav/web/templates/base.html index bab92e56ec..de4bc07273 100644 --- a/python/nav/web/templates/base.html +++ b/python/nav/web/templates/base.html @@ -100,6 +100,7 @@

  • {{ link.name }}
  • {% endfor %}
  • My account
  • +
  • QR Code
  • {% endif %} diff --git a/python/nav/web/templates/webfront/qr_code.html b/python/nav/web/templates/webfront/qr_code.html new file mode 100644 index 0000000000..a0ad87f527 --- /dev/null +++ b/python/nav/web/templates/webfront/qr_code.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% load crispy_forms_tags %} + +{% block base_header_additional_head %} + + +{% endblock %} + +{% block base_content %} + {% if qr_code %} + QR Code linking to previous side + {% else %} +
    + No previous side could be found. This functionality does not work when directly opening this page. +
    + {% endif %} + +{% endblock %} diff --git a/python/nav/web/webfront/urls.py b/python/nav/web/webfront/urls.py index fb174e9436..fe4070abaa 100644 --- a/python/nav/web/webfront/urls.py +++ b/python/nav/web/webfront/urls.py @@ -97,4 +97,5 @@ views.set_account_preference, name='set-account-preference', ), + re_path(r'^qr-code/$', views.qr_code, name='webfront-qr-code'), ] diff --git a/python/nav/web/webfront/views.py b/python/nav/web/webfront/views.py index c98f0e7732..e9be534f21 100644 --- a/python/nav/web/webfront/views.py +++ b/python/nav/web/webfront/views.py @@ -41,6 +41,7 @@ from nav.web import auth from nav.web.auth import ldap from nav.web.auth.utils import set_account +from nav.web.utils import convert_pil_object_to_bytes_string, generate_qr_code from nav.web.utils import require_param from nav.web.webfront.utils import quick_read, tool_list from nav.web.webfront.forms import ( @@ -325,6 +326,23 @@ def preferences(request): return render(request, 'webfront/preferences.html', context) +def qr_code(request): + """Show qr code linking to previous page""" + qr_code = None + previous_url = request.headers.get("referer") + if previous_url: + qr_code = generate_qr_code(url=previous_url, name=previous_url) + qr_code_bytes_str = convert_pil_object_to_bytes_string(pil_image=qr_code) + + context = { + 'navpath': [('Home', '/'), ('QR Code', None)], + 'title': 'QR Code', + 'qr_code': qr_code_bytes_str, + } + + return render(request, 'webfront/qr_code.html', context) + + @sensitive_post_parameters('old_password', 'new_password1', 'new_password2') def change_password(request): """Handles POST requests to change a users password"""