Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DONE] Pampletousse/feature download qrcode #1015

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pod/live/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 2 additions & 22 deletions pod/live/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""Esup-Pod "live" models."""
import base64
import hashlib
import io
import qrcode
import os

from ckeditor.fields import RichTextField
Expand All @@ -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
Expand Down Expand Up @@ -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'<img src="data:image/png;base64, {img_str}" '
+ f'width="300px" height="300px" alt={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)
Expand Down
22 changes: 11 additions & 11 deletions pod/live/templates/live/event-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% load static %}
{% load tagging_tags %}
{% load thumbnail %}
{% load event_tags %}

<div class="tab-content w-100" id="video-meta">
{% if event.description %}
Expand Down Expand Up @@ -58,7 +59,7 @@ <h3 class="meta-title">{% trans 'Type:' %}</h3>
</div>

{% if event.is_draft == False or event.owner == request.user or request.user in event.additional_owners.all or request.user.is_superuser %} <!-- Début modale -->
<div class="modal fade" id="share" tabindex="-1" aria-labelledby="shareLabel" aria-hidden="true" {% if event.is_draft %}style="border:1px solid red"{% endif %}>
<div class="modal fade" id="share" tabindex="-1" aria-labelledby="shareLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -70,7 +71,7 @@ <h2 class="modal-title h5" id="shareLabel">
<div class="modal-body">

{% if event.is_draft %}
<div class="card text-white bg-danger mb-3">
<div class="card text-white border-danger mb-3">
<div class="card-body">
{% blocktrans %}Please note that your event is in draft mode.<br>The following links contain a key allowing access. Anyone with this links can access it.{% endblocktrans %}
</div>
Expand Down Expand Up @@ -117,17 +118,16 @@ <h2 class="modal-title h5" id="shareLabel">
<fieldset class="pod-share-fieldset">
<legend><i class="bi bi-link-45deg" aria-hidden="true"></i>&nbsp;{% trans 'Share the link' %}</legend>
<div class="form-group">
<label for="txtpartage">{% trans 'Use this link to share the video:' %}</label>
<label for="txtpartage">{% trans 'Use this link to share the event:' %}</label>
<input class="form-control" type="text" name="txtpartage" id="txtpartage" value="{% if request.is_secure %}https{% else %}http{% endif %}://{{ request.META.HTTP_HOST }}{% url 'live:event' slug=event.slug %}{% if event.is_draft == True %}{{ event.get_hashkey }}/{% endif %}">
</div>
<div class="form-group">
<label>{% trans 'QR code for this link:' %}&nbsp;
<a href="#" class="btn pod-btn pod-btn-social m-1" title="{% trans 'Warning, it use google API' %}" role="button" data-bs-toggle="collapse" data-bs-target="#qrcode" aria-expanded="false" aria-controls="qrcode">
<i class="bi bi-eye" aria-hidden="true"></i>
</a>
</label>
<img src="//chart.apis.google.com/chart?cht=qr&amp;chs=200x200&amp;chl={% if request.is_secure %}https{% else %}http{% endif %}://{{ request.META.HTTP_HOST }}{% url 'live:event' slug=event.slug %}{% if event.is_draft == True %}{{ event.get_hashkey }}/{% endif %}" alt="qrcode" id="qrcode" loading="lazy">
</div>
<div class="form-group m-2">
{% get_event_qrcode event.id as qrcode %}
<label>{% trans 'QR code for this link:' %}&nbsp;</label><br>
{{ qrcode }}
<br>
<button id="btn-download-qr-code" type="submit" data-slug="{{ event.slug }}" class="btn btn-primary my-2" title="{% trans 'Download this QR code' %}">{% trans 'Download' %}</button>
</div>
Badatos marked this conversation as resolved.
Show resolved Hide resolved
</fieldset>
</div> <!-- End modal body-->
</div> <!-- End modal content-->
Expand Down
17 changes: 17 additions & 0 deletions pod/live/templatetags/event_tags.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.template.defaultfilters import register
from django.utils import timezone

from django.utils.translation import ugettext_lazy as _
from pod.live.models import Event
from pod.live.views import can_manage_event
from pod.main.utils import generate_qrcode


@register.simple_tag(takes_context=True)
Expand All @@ -23,3 +25,18 @@ def get_next_events(context, broadcaster_id=None, limit_nb=4):
@register.filter
def can_manage_event_filter(user):
return can_manage_event(user)


@register.simple_tag(name="get_event_qrcode")
def get_event_qrcode(event_id: int):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peux tu spécifier le type de retour aussi : def get_event_qrcode(event_id: int)->str:

"""Get the event generated QR code.

Args:
event_id (int): Identifier of event object

Returns:
string: HTML-formed generated qrcode

"""
alt = _("QR code event's link")
return generate_qrcode("live:event_immediate_edit", event_id, alt)
Binary file modified pod/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
40 changes: 24 additions & 16 deletions pod/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Pod\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-19 09:07+0100\n"
"POT-Creation-Date: 2024-01-24 12:51+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: obado <[email protected]>\n"
"Language-Team: Pod Team [email protected]\n"
Expand Down Expand Up @@ -3016,8 +3016,8 @@ msgid "QR code to record immediately an event"
msgstr "QR code pour la programmation d’un évènement immédiat"

#: pod/live/admin.py
msgid "QR Code"
msgstr "QR Code"
msgid "QR code"
msgstr "QR code"

#: pod/live/admin.py pod/live/models.py pod/recorder/models.py
#: pod/video/models.py
Expand Down Expand Up @@ -3642,9 +3642,8 @@ msgid "Share the link"
msgstr "Partager le lien"

#: pod/live/templates/live/event-info.html
#: pod/video/templates/videos/video-info.html
msgid "Use this link to share the video:"
msgstr "Utiliser ce lien pour partager la vidéo :"
msgid "Use this link to share the event:"
msgstr "Utiliser ce lien pour partager l'évènement :"

#: pod/live/templates/live/event-info.html
#: pod/video/templates/videos/video-info.html
Expand All @@ -3653,8 +3652,14 @@ msgstr "QR code pour le lien :"

#: pod/live/templates/live/event-info.html
#: pod/video/templates/videos/video-info.html
msgid "Warning, it use google API"
msgstr "Attention, utilise une API Google"
msgid "Download this QR code"
msgstr "Télécharger ce QR code"

#: pod/live/templates/live/event-info.html
#: pod/podfile/templates/podfile/list_folder_files.html
#: pod/video/templates/videos/video-info.html
msgid "Download"
msgstr "Télécharger"

#: pod/live/templates/live/event-script.html
msgid "Recording not done: "
Expand Down Expand Up @@ -3929,6 +3934,10 @@ msgstr "Évènements à venir"
msgid "Past events"
msgstr "Évènements passés"

#: pod/live/templatetags/event_tags.py
msgid "QR code event's link:"
msgstr "QR code pour le lien de l'évènement :"

#: pod/live/utils.py
#, python-format
msgid "Registration of event #%(content_id)s"
Expand Down Expand Up @@ -4804,7 +4813,7 @@ msgstr ""
"droite, mode sombre ou dyslexie etc.), gérer la session (authentification) "
"et analyser le trafic du site (pour certaines instances)."

#: pod/main/templates/base.html
#: pod/main/templates/base.html pod/video/templates/videos/add_video.html
msgid "Learn more"
msgstr "En savoir plus"

Expand Down Expand Up @@ -6549,10 +6558,6 @@ msgstr "Partager le dossier « %(folder_name)s » avec un autre utilisateur"
msgid "Upload Files"
msgstr "Téléverser des fichiers"

#: pod/podfile/templates/podfile/list_folder_files.html
msgid "Download"
msgstr "Télécharger"

#: pod/podfile/templates/podfile/list_folder_files.html
msgid "Delete file"
msgstr "Supprimer le fichier"
Expand Down Expand Up @@ -8387,8 +8392,8 @@ msgstr ""
"interactive H5P :"

#: pod/video/templates/videos/video-info.html
msgid "QR code"
msgstr "QR code"
msgid "Use this link to share the video:"
msgstr "Utiliser ce lien pour partager la vidéo :"

#: pod/video/templates/videos/video_collaborate.html
msgid "Collaborate"
Expand Down Expand Up @@ -8582,6 +8587,10 @@ msgstr "Afficher les statistiques de visualisation de toutes les vidéos"
msgid ": "
msgstr " : "

#: pod/video/templatetags/video_tags.py
msgid "QR code video's link:"
msgstr "QR code pour le lien de la vidéo :"

#: pod/video/templatetags/video_tags.py
msgid "This content is not password protected."
msgstr "Ce contenu n'est pas protégé par un mot de passe."
Expand Down Expand Up @@ -9064,4 +9073,3 @@ msgstr "Résultats de la recherche"
#: pod/xapi/apps.py
msgid "Esup-Pod xAPI"
msgstr "xAPI Esup-Pod"

2 changes: 1 addition & 1 deletion pod/locale/fr/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Esup-Pod\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-19 09:07+0100\n"
"POT-Creation-Date: 2024-01-24 12:51+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: obado <[email protected]>\n"
"Language-Team: \n"
Expand Down
50 changes: 39 additions & 11 deletions pod/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Pod\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-19 09:07+0100\n"
"POT-Creation-Date: 2024-01-24 12:51+0100\n"
"PO-Revision-Date: 2023-06-08 14:37+0200\n"
"Last-Translator: obado <[email protected]>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -2824,7 +2824,7 @@ msgid "QR code to record immediately an event"
msgstr ""

#: pod/live/admin.py
msgid "QR Code"
msgid "QR code"
msgstr ""

#: pod/live/admin.py pod/live/models.py pod/recorder/models.py
Expand Down Expand Up @@ -3409,8 +3409,7 @@ msgid "Share the link"
msgstr ""

#: pod/live/templates/live/event-info.html
#: pod/video/templates/videos/video-info.html
msgid "Use this link to share the video:"
msgid "Use this link to share the event:"
msgstr ""

#: pod/live/templates/live/event-info.html
Expand All @@ -3420,7 +3419,13 @@ msgstr ""

#: pod/live/templates/live/event-info.html
#: pod/video/templates/videos/video-info.html
msgid "Warning, it use google API"
msgid "Download this QR code"
msgstr ""

#: pod/live/templates/live/event-info.html
#: pod/podfile/templates/podfile/list_folder_files.html
#: pod/video/templates/videos/video-info.html
msgid "Download"
msgstr ""

#: pod/live/templates/live/event-script.html
Expand Down Expand Up @@ -3683,6 +3688,10 @@ msgstr ""
msgid "Past events"
msgstr ""

#: pod/live/templatetags/event_tags.py
msgid "QR code event's link"
msgstr ""

#: pod/live/utils.py
#, python-format
msgid "Registration of event #%(content_id)s"
Expand Down Expand Up @@ -4548,7 +4557,7 @@ msgid ""
"analyze site traffic."
msgstr ""

#: pod/main/templates/base.html
#: pod/main/templates/base.html pod/video/templates/videos/add_video.html
msgid "Learn more"
msgstr ""

Expand Down Expand Up @@ -6186,10 +6195,6 @@ msgstr ""
msgid "Upload Files"
msgstr ""

#: pod/podfile/templates/podfile/list_folder_files.html
msgid "Download"
msgstr ""

#: pod/podfile/templates/podfile/list_folder_files.html
msgid "Delete file"
msgstr ""
Expand Down Expand Up @@ -7873,7 +7878,7 @@ msgid ""
msgstr ""

#: pod/video/templates/videos/video-info.html
msgid "QR code"
msgid "Use this link to share the video:"
msgstr ""

#: pod/video/templates/videos/video_collaborate.html
Expand Down Expand Up @@ -7912,6 +7917,25 @@ msgstr ""
msgid "Add a new video"
msgstr ""

#: pod/video/templates/videos/video_edit.html
#, python-format
msgid ""
"\n"
" By default, the deletion date of your video is set to "
"%(counter)s year, in accordance with your profile. As a teacher, you can "
"modify this date. If you are a student and wish to extend this period, add a "
"teacher as an additional video owner\n"
" "
msgid_plural ""
"\n"
" By default, the deletion date of your video is set to "
"%(counter)s years, in accordance with your profile. As a teacher, you can "
"modify this date. If you are a student and wish to extend this period, add a "
"teacher as an additional video owner\n"
" "
msgstr[0] ""
msgstr[1] ""

#: pod/video/templates/videos/video_edit.html
#: pod/video/templates/videos/video_page_content.html
msgid "The video is currently waiting for encoding."
Expand Down Expand Up @@ -8062,6 +8086,10 @@ msgstr ""
msgid ": "
msgstr ""

#: pod/video/templatetags/video_tags.py
msgid "QR code video's link"
msgstr ""

#: pod/video/templatetags/video_tags.py
msgid "This content is not password protected."
msgstr ""
Expand Down
2 changes: 1 addition & 1 deletion pod/locale/nl/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Esup-Pod\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-01-19 09:07+0100\n"
"POT-Creation-Date: 2024-01-24 12:51+0100\n"
"PO-Revision-Date: 2023-02-08 15:22+0100\n"
"Last-Translator: obado <[email protected]>\n"
"Language-Team: \n"
Expand Down
Loading