Skip to content

Commit

Permalink
Add QR Code link to My Stuff
Browse files Browse the repository at this point in the history
Clicking the link will show a page with a QR Code linking to the previous page
  • Loading branch information
johannaengland committed May 2, 2024
1 parent d64ca1c commit b46efd6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/+qr-code-my-stuff.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add link to My Stuff that leads to a generated QR Code linking to the page it is called from
1 change: 1 addition & 0 deletions python/nav/web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ <h1>
<li><a href="{{ link.uri }}">{{ link.name }}</a></li>
{% endfor %}
<li class="divider"><a href="{% url 'webfront-preferences' %}">My account <i class="fa fa-gear"></i></a></li>
<li class="divider"><a href="{% url 'webfront-qr-code' %}">QR Code <i class="fa fa-qrcode"></i></a></li>
</ul>
</li>
{% endif %}
Expand Down
14 changes: 14 additions & 0 deletions python/nav/web/templates/webfront/qr_code.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "base.html" %}

{% load crispy_forms_tags %}

{% block base_header_additional_head %}
<link rel="stylesheet" href="{{ STATIC_URL }}css/nav.css" />
<script>require(['src/navigation_preferences']);</script>
{% endblock %}

{% block base_content %}

<img src="data:image/png;base64,{{qr_code}}" alt="QR Code linking to previous side">

{% endblock %}
1 change: 1 addition & 0 deletions python/nav/web/webfront/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@
views.set_account_preference,
name='set-account-preference',
),
re_path(r'^qr-code/$', views.qr_code, name='webfront-qr-code'),
]
19 changes: 19 additions & 0 deletions python/nav/web/webfront/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import json
import logging
from operator import attrgetter
import re
from urllib.parse import quote as urlquote

from django.http import (
Expand All @@ -41,6 +42,7 @@
from nav.web import auth
from nav.web.auth import ldap
from nav.web.auth.utils import set_account
from nav.web.seeddb.utils.generate_qr_code import 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 (
Expand Down Expand Up @@ -325,6 +327,23 @@ def preferences(request):
return render(request, 'webfront/preferences.html', context)


def qr_code(request):
"""Show qr code linking to previous page"""
url = request.headers["referer"]
stripped_url = re.sub("https?://", "", url)

context = {
'navpath': [('Home', '/'), ('QR Code', None)],
'title': 'QR Code',
'qr_code': generate_qr_code(
url=url,
name=stripped_url,
),
}

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"""
Expand Down

0 comments on commit b46efd6

Please sign in to comment.