From 9a492e47587855665688393973446824478f4a0d Mon Sep 17 00:00:00 2001 From: pampletousse <51699553+pampletousse@users.noreply.github.com> Date: Thu, 25 Jan 2024 10:47:32 +0100 Subject: [PATCH] [DONE] Pampletousse/feature download qrcode (#1015) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add download button for qr code + fix border red too big * Mutualize qrcode generation and display between video and live(event) * Add same template modification to live event * Try to mutualize qr code generation between video and event * Add event slug to downloaded file name * éAdd alternative text to parameters * PEP8 conformity * Fix PEP8 E303 blank line * Fix PEP8 F811 * Uniformize QR code designation * Generate translations for QR Code managment * éAdd types into functions and doc + normalize id in template * Fix translations * Fix translation video into event in event-info template * Delete fuzzy translations * Add return types on functions in register tags (video and event) * Add quotes for alt in qr code img tag --------- Co-authored-by: pampletousse --- pod/live/admin.py | 2 +- pod/live/models.py | 24 +--------- pod/live/templates/live/event-info.html | 22 ++++----- pod/live/templatetags/event_tags.py | 17 +++++++ pod/locale/fr/LC_MESSAGES/django.mo | Bin 176203 -> 176513 bytes pod/locale/fr/LC_MESSAGES/django.po | 40 ++++++++++------- pod/locale/fr/LC_MESSAGES/djangojs.po | 2 +- pod/locale/nl/LC_MESSAGES/django.po | 50 ++++++++++++++++----- pod/locale/nl/LC_MESSAGES/djangojs.po | 2 +- pod/main/static/js/main.js | 33 ++++++++++++++ pod/main/utils.py | 43 ++++++++++++++++++ pod/video/templates/videos/video-info.html | 18 ++++---- pod/video/templatetags/video_tags.py | 17 +++++++ 13 files changed, 197 insertions(+), 73 deletions(-) diff --git a/pod/live/admin.py b/pod/live/admin.py index 7a1316a06a..6f6898bb1e 100644 --- a/pod/live/admin.py +++ b/pod/live/admin.py @@ -139,7 +139,7 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs): def qrcode(self, obj): return obj.qrcode - qrcode.short_description = _("QR Code") + qrcode.short_description = _("QR code") qrcode.allow_tags = True class Media: diff --git a/pod/live/models.py b/pod/live/models.py index 804ff795fc..12f0dedc7c 100644 --- a/pod/live/models.py +++ b/pod/live/models.py @@ -1,8 +1,5 @@ """Esup-Pod "live" models.""" -import base64 import hashlib -import io -import qrcode import os from ckeditor.fields import RichTextField @@ -21,12 +18,12 @@ from django.urls import reverse from django.utils import timezone from django.utils.html import format_html -from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ from pod.main.lang_settings import ALL_LANG_CHOICES as __ALL_LANG_CHOICES__ from pod.main.lang_settings import PREF_LANG_CHOICES as __PREF_LANG_CHOICES__ from django.utils.translation import get_language +from pod.main.utils import generate_qrcode from pod.authentication.models import AccessGroup from pod.main.models import get_nextautoincrement from pod.video.models import Video, Type @@ -272,25 +269,8 @@ def is_recording_admin(self): @property def qrcode(self, request=None): - url_scheme = "https" if SECURE_SSL_REDIRECT else "http" - url_immediate_event = reverse("live:event_immediate_edit", args={self.id}) - data = "".join( - [ - url_scheme, - "://", - get_current_site(request).domain, - url_immediate_event, - ] - ) - img = qrcode.make(data) - buffer = io.BytesIO() - img.save(buffer, format="PNG") - img_str = base64.b64encode(buffer.getvalue()).decode("utf-8") alt = _("QR code to record immediately an event") - return mark_safe( - f'{alt}' - ) + return generate_qrcode("live:event_immediate_edit", self.id, alt, request) def set_broadcaster_file(self, filename): trans_folder = os.path.join(MEDIA_ROOT, LIVE_TRANSCRIPTIONS_FOLDER) diff --git a/pod/live/templates/live/event-info.html b/pod/live/templates/live/event-info.html index 484319f8c3..20bd1a58d1 100644 --- a/pod/live/templates/live/event-info.html +++ b/pod/live/templates/live/event-info.html @@ -2,6 +2,7 @@ {% load static %} {% load tagging_tags %} {% load thumbnail %} +{% load event_tags %}
{% if event.description %} @@ -58,7 +59,7 @@

{% trans 'Type:' %}

{% if event.is_draft == False or event.owner == request.user or request.user in event.additional_owners.all or request.user.is_superuser %} -