From b8a93b0b7569536b3ab61324ee90e43a2cac5004 Mon Sep 17 00:00:00 2001 From: otthorn Date: Sat, 19 Mar 2022 16:25:15 +0100 Subject: [PATCH 1/7] Add link to QR code --- apps/member/templates/member/includes/profile_info.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/member/templates/member/includes/profile_info.html b/apps/member/templates/member/includes/profile_info.html index 378d54e2..5c403917 100644 --- a/apps/member/templates/member/includes/profile_info.html +++ b/apps/member/templates/member/includes/profile_info.html @@ -54,5 +54,8 @@ {% trans 'API token' %} + + {% trans 'QR Code' %} + {% endif %} From 819b4214c9de08b0036a92e960ee4d8b113bfb2b Mon Sep 17 00:00:00 2001 From: otthorn Date: Tue, 22 Mar 2022 12:26:44 +0100 Subject: [PATCH 2/7] Add QRCode View, URL and test template --- apps/member/templates/member/qr_code.html | 11 +++++++++++ apps/member/urls.py | 1 + apps/member/views.py | 7 +++++++ 3 files changed, 19 insertions(+) create mode 100644 apps/member/templates/member/qr_code.html diff --git a/apps/member/templates/member/qr_code.html b/apps/member/templates/member/qr_code.html new file mode 100644 index 00000000..69b2a351 --- /dev/null +++ b/apps/member/templates/member/qr_code.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% comment %} +SPDX-License-Identifier: GPL-3.0-or-later +{% endcomment %} +{% load i18n %} + +{% block content %} + +Affichage du QR Code ici + +{% endblock %} diff --git a/apps/member/urls.py b/apps/member/urls.py index b1c537d5..ca759ccf 100644 --- a/apps/member/urls.py +++ b/apps/member/urls.py @@ -24,4 +24,5 @@ urlpatterns = [ path('user//update_pic/', views.ProfilePictureUpdateView.as_view(), name="user_update_pic"), path('user//aliases/', views.ProfileAliasView.as_view(), name="user_alias"), path('manage-auth-token/', views.ManageAuthTokens.as_view(), name='auth_token'), + path('user//qr_code/', views.QRCodeView.as_view(), name='qr_code'), ] diff --git a/apps/member/views.py b/apps/member/views.py index 6ce8d4c5..b4c77519 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -331,6 +331,13 @@ class ManageAuthTokens(LoginRequiredMixin, TemplateView): context['token'] = Token.objects.get_or_create(user=self.request.user)[0] return context +class QRCodeView(LoginRequiredMixin, TemplateView): + """ + Affiche le QR Code + """ + model = QRCode + template_name = "member/qr_code.html" + extra_context = {"title": _("QR Code")} # ******************************* # # CLUB # From 5038af9e341bf9046d5a933a2ce43491340875d3 Mon Sep 17 00:00:00 2001 From: otthorn Date: Tue, 22 Mar 2022 14:58:26 +0100 Subject: [PATCH 3/7] Final html template --- apps/member/templates/member/qr_code.html | 27 ++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/member/templates/member/qr_code.html b/apps/member/templates/member/qr_code.html index 69b2a351..da9d6042 100644 --- a/apps/member/templates/member/qr_code.html +++ b/apps/member/templates/member/qr_code.html @@ -5,7 +5,32 @@ SPDX-License-Identifier: GPL-3.0-or-later {% load i18n %} {% block content %} +
+

+ {% trans "QR Code for" %} {{ user_object.username }} ({{ user_object.first_name }} {{user_object.last_name }}) +

+
+
+
-Affichage du QR Code ici {% endblock %} + +{% block extrajavascript %} + + +{% endblock %} + +{% block extracss %} + +{% endblock %} From 8ffb0ebb563c853487647d439f5f8e5b8f65509a Mon Sep 17 00:00:00 2001 From: otthorn Date: Tue, 22 Mar 2022 14:59:01 +0100 Subject: [PATCH 4/7] Use DetailView --- apps/member/views.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index b4c77519..4db41c9a 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -331,14 +331,20 @@ class ManageAuthTokens(LoginRequiredMixin, TemplateView): context['token'] = Token.objects.get_or_create(user=self.request.user)[0] return context -class QRCodeView(LoginRequiredMixin, TemplateView): +class QRCodeView(LoginRequiredMixin, DetailView): """ Affiche le QR Code """ - model = QRCode + model = User + context_object_name = "user_object" template_name = "member/qr_code.html" extra_context = {"title": _("QR Code")} +# def get_context_data(self, **kwargs): +# context = super().get_context_data(**kwargs) +# context["plop"] = "test" +# return context + # ******************************* # # CLUB # # ******************************* # From d3ba95cdca3d9171b0a66cf733b8f7d3df2b6073 Mon Sep 17 00:00:00 2001 From: otthorn Date: Tue, 22 Mar 2022 15:04:41 +0100 Subject: [PATCH 5/7] Insecable space for more clarity --- apps/member/templates/member/includes/profile_info.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/member/templates/member/includes/profile_info.html b/apps/member/templates/member/includes/profile_info.html index 5c403917..f474cfd7 100644 --- a/apps/member/templates/member/includes/profile_info.html +++ b/apps/member/templates/member/includes/profile_info.html @@ -52,10 +52,10 @@ {% if user_object.pk == user.pk %} {% endif %} From 145e55da75ac88683d632431a5c2b7cbf0fb2e01 Mon Sep 17 00:00:00 2001 From: otthorn Date: Tue, 22 Mar 2022 15:06:04 +0100 Subject: [PATCH 6/7] remove useless comment --- apps/member/views.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index 4db41c9a..8ecffa3e 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -340,11 +340,6 @@ class QRCodeView(LoginRequiredMixin, DetailView): template_name = "member/qr_code.html" extra_context = {"title": _("QR Code")} -# def get_context_data(self, **kwargs): -# context = super().get_context_data(**kwargs) -# context["plop"] = "test" -# return context - # ******************************* # # CLUB # # ******************************* # From e6f308458894d549e1dfc2d2583dc6f8fbde72f0 Mon Sep 17 00:00:00 2001 From: Nicolas Margulies Date: Wed, 11 Oct 2023 18:01:04 +0200 Subject: [PATCH 7/7] Added a first pass for automatically entering an activity with a qrcode --- .../templates/activity/activity_entry.html | 34 ++++++++++++++++++- apps/member/templates/member/qr_code.html | 2 +- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/apps/activity/templates/activity/activity_entry.html b/apps/activity/templates/activity/activity_entry.html index 0286bdb7..c5368c2d 100644 --- a/apps/activity/templates/activity/activity_entry.html +++ b/apps/activity/templates/activity/activity_entry.html @@ -38,6 +38,7 @@ SPDX-License-Identifier: GPL-3.0-or-later +
@@ -63,15 +64,46 @@ SPDX-License-Identifier: GPL-3.0-or-later refreshBalance(); } + function process_qrcode() { + let name = alias_obj.val(); + $.get("/api/note/note?search=" + name + "&format=json").done( + function (res) { + let note = res.results[0]; + $.post("/api/activity/entry/?format=json", { + csrfmiddlewaretoken: CSRF_TOKEN, + activity: {{ activity.id }}, + note: note.id, + guest: null + }).done(function () { + addMsg(interpolate(gettext( + "Entry made for %s whose balance is %s €"), + [note.name, note.balance / 100]), "success", 4000); + reloadTable(true); + }).fail(function (xhr) { + errMsg(xhr.responseJSON, 4000); + }); + }).fail(function (xhr) { + errMsg(xhr.responseJSON, 4000); + }); + } + alias_obj.keyup(function(event) { let code = event.originalEvent.keyCode if (65 <= code <= 122 || code === 13) { debounce(reloadTable)() } + if (code === 0) + process_qrcode(); }); $(document).ready(init); + alias_obj2 = document.getElementById("alias"); + $("#trigger").click(function (e) { + addMsg("Clicked", "success", 1000); + alias_obj.val(alias_obj.val() + "\0"); + alias_obj2.dispatchEvent(new KeyboardEvent('keyup')); + }) function init() { $(".table-row").click(function (e) { let target = e.target.parentElement; @@ -168,4 +200,4 @@ SPDX-License-Identifier: GPL-3.0-or-later }); } -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/apps/member/templates/member/qr_code.html b/apps/member/templates/member/qr_code.html index da9d6042..00e1256c 100644 --- a/apps/member/templates/member/qr_code.html +++ b/apps/member/templates/member/qr_code.html @@ -20,7 +20,7 @@ SPDX-License-Identifier: GPL-3.0-or-later