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..d1385f44a1 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 generate_qr_codes_as_byte_strings 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_codes = generate_qr_codes_as_byte_strings({previous_url: previous_url}) + qr_code = qr_codes[0] + + context = { + 'navpath': [('Home', '/'), ('QR Code', None)], + 'title': 'QR Code', + 'qr_code': qr_code, + } + + 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"""