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 3, 2024
1 parent 727da71 commit 7951469
Show file tree
Hide file tree
Showing 5 changed files with 40 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
19 changes: 19 additions & 0 deletions python/nav/web/templates/webfront/qr_code.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% 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 %}
{% if qr_code %}
<img src="data:image/png;base64,{{qr_code}}" alt="QR Code linking to previous side">
{% else %}
<div class="alert-box warning with-icon">
No previous side could be found. This functionality does not work when directly opening this page.
</div>
{% endif %}

{% 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'),
]
18 changes: 18 additions & 0 deletions python/nav/web/webfront/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 7951469

Please sign in to comment.