Skip to content

Commit

Permalink
Add PWA functionality to app and notifications capabilities
Browse files Browse the repository at this point in the history
Owners can set their notification preference.
Notifications are sent when video encoding is complete.

Co-authored-by: Éloi Rivard <[email protected]>
Co-authored-by: Loan Robert <[email protected]>
  • Loading branch information
azmeuk and LoanR committed Sep 20, 2023
1 parent bc57638 commit 6113409
Show file tree
Hide file tree
Showing 38 changed files with 540 additions and 5 deletions.
7 changes: 7 additions & 0 deletions dockerfile-dev-with-volumes/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ MIGRATION_MODULES = {'flatpages': 'pod.db_migrations'}
# pour avoir le maximum de log sur la console
LOGGING = {}
# PUSH NOTIFICATIONS
# Les clés VAPID peuvent être générées avec https://web-push-codelab.glitch.me/
WEBPUSH_SETTINGS = {
"VAPID_PUBLIC_KEY": "",
"VAPID_PRIVATE_KEY": "",
"VAPID_ADMIN_EMAIL": "[email protected]"
}
----

== Commandes
Expand Down
11 changes: 11 additions & 0 deletions pod/authentication/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ class Meta(object):
fields = []


class SetNotificationForm(forms.ModelForm):
"""Push notification preferences form."""

def __init__(self, *args, **kwargs):
super(SetNotificationForm, self).__init__(*args, **kwargs)

class Meta(object):
model = Owner
fields = ["accepts_notifications"]


User = get_user_model()


Expand Down
6 changes: 6 additions & 0 deletions pod/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ class Owner(models.Model):
)
accessgroups = models.ManyToManyField("authentication.AccessGroup", blank=True)
sites = models.ManyToManyField(Site)
accepts_notifications = models.BooleanField(
verbose_name=_("Accept notifications"),
default=None,
null=True,
help_text=_("Receive push notifications on your devices."),
)

class Meta:
verbose_name = _("Owner")
Expand Down
Binary file modified pod/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
43 changes: 43 additions & 0 deletions pod/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ msgstr "Commentaire"
msgid "Picture"
msgstr "Image"

#: pod/authentication/models.py
msgid "Accept notifications"
msgstr "Accepter les notifications"

#: pod/authentication/models.py
msgid "Receive push notifications on your devices."
msgstr "Recevez des notifications push sur vos appareils"

#: pod/authentication/models.py pod/live/models.py pod/meeting/models.py
#: pod/podfile/models.py pod/video/admin.py pod/video/models.py
#: pod/video_search/templates/search/search.html
Expand Down Expand Up @@ -4729,6 +4737,10 @@ msgstr "Mes fichiers"
msgid "Claim a record"
msgstr "Revendiquer un enregistrement"

#: pod/main/templates/navbar.html pod/progressive_web_app/templates/debug.html
msgid "Notifications settings"
msgstr "Paramètres de notifications"

#: pod/main/templates/navbar.html
msgid "Log out"
msgstr "Déconnexion"
Expand Down Expand Up @@ -6208,6 +6220,26 @@ msgstr "Vous ne pouvez pas voir ce dossier."
msgid "You cannot edit this file."
msgstr "Vous ne pouvez pas éditer ce fichier."

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Get application notifications"
msgstr "Recevez les notifications de l'application"

#: pod/progressive_web_app/templates/notification_toast.html
msgid ""
"Get notified for specific events (when one of your video encoding is "
"completed)."
msgstr ""
"Recevez des notifications pour des événements spécifiques (lorsque "
"l'encodage d'une de vos vidéos est terminé)"

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Allow"
msgstr "Autoriser"

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Deny on all devices"
msgstr "Refuser sur tous les appareils"

#: pod/recorder/admin.py
msgid "Delete selected Recording file treatments + source files"
msgstr ""
Expand Down Expand Up @@ -6588,6 +6620,17 @@ msgstr "L’enregistrement a été supprimé."
msgid "Recorder for Studio not found."
msgstr "Enregistreur studio non trouvé."

#: pod/settings.py
msgid ""
"Podeduc is aimed at users of our institutions, by allowing the publication "
"of videos in the fields of research (promotion of platforms, etc.), training "
"(tutorials, distance training, student reports, etc.), institutional life "
"(video of events), offering several days of content."
msgstr ""
"Podeduc a pour but de faciliter la mise à disposition de vidéo et de ce fait, "
"d’encourager l’utilisation de celles-ci dans le cadre de l’enseignement et "
"la recherche."

#: pod/urls.py
msgid "Pod Administration"
msgstr "Administration de Pod"
Expand Down
Binary file modified pod/locale/fr/LC_MESSAGES/djangojs.mo
Binary file not shown.
20 changes: 20 additions & 0 deletions pod/locale/fr/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,22 @@ msgstr "Voir plus"
msgid "This folder is empty"
msgstr "Ce dossier est vide"

#: pod/progressive_web_app/static/js/notification-toast.js
msgid "Error"
msgstr "Erreur"

#: pod/progressive_web_app/static/js/notification-toast.js
msgid ""
"Don't forget to allow notifications from this website in your browser's "
"settings!"
msgstr ""
"N'oubliez pas d'autoriser les notifications provenant de ce site web dans "
"votre navigateur !"

#: pod/progressive_web_app/static/js/notification-toast.js
msgid "Error during unsubscription..."
msgstr "Erreur durant la désinscription..."

#: pod/video/static/js/ajax-display-channels.js
msgid "Channel"
msgstr "Chaîne"
Expand Down Expand Up @@ -757,6 +773,10 @@ msgstr "Créer catégorie"
msgid "Select the general type of the video."
msgstr "Sélectionnez le type général de vidéo."

#: pod/video/static/js/video_edit.js
msgid "Get notified when the video encoding is finished."
msgstr "Recevez une notification lorsque l'encodage de la vidéo est terminé."

#: pod/video/static/js/video_stats_view.js
msgid "Title"
msgstr "Titre"
Expand Down
38 changes: 38 additions & 0 deletions pod/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ msgstr ""
msgid "Picture"
msgstr ""

#: pod/authentication/models.py
msgid "Accept notifications"
msgstr ""

#: pod/authentication/models.py
msgid "Receive push notifications on your devices."
msgstr ""

#: pod/authentication/models.py pod/live/models.py pod/meeting/models.py
#: pod/podfile/models.py pod/video/admin.py pod/video/models.py
#: pod/video_search/templates/search/search.html
Expand Down Expand Up @@ -4486,6 +4494,10 @@ msgstr ""
msgid "Claim a record"
msgstr ""

#: pod/main/templates/navbar.html pod/progressive_web_app/templates/debug.html
msgid "Notifications settings"
msgstr ""

#: pod/main/templates/navbar.html
msgid "Log out"
msgstr "Uitloggen"
Expand Down Expand Up @@ -5873,6 +5885,24 @@ msgstr ""
msgid "You cannot edit this file."
msgstr ""

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Get application notifications"
msgstr ""

#: pod/progressive_web_app/templates/notification_toast.html
msgid ""
"Get notified for specific events (when one of your video encoding is "
"completed)."
msgstr ""

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Allow"
msgstr ""

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Deny on all devices"
msgstr ""

#: pod/recorder/admin.py
msgid "Delete selected Recording file treatments + source files"
msgstr ""
Expand Down Expand Up @@ -6220,6 +6250,14 @@ msgstr ""
msgid "Recorder for Studio not found."
msgstr ""

#: pod/settings.py
msgid ""
"Podeduc is aimed at users of our institutions, by allowing the publication "
"of videos in the fields of research (promotion of platforms, etc.), training "
"(tutorials, distance training, student reports, etc.), institutional life "
"(video of events), offering several days of content."
msgstr ""

#: pod/urls.py
msgid "Pod Administration"
msgstr ""
Expand Down
18 changes: 18 additions & 0 deletions pod/locale/nl/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,20 @@ msgstr ""
msgid "This folder is empty"
msgstr ""

#: pod/progressive_web_app/static/js/notification-toast.js
msgid "Error"
msgstr ""

#: pod/progressive_web_app/static/js/notification-toast.js
msgid ""
"Don't forget to allow notifications from this website in your browser's "
"settings!"
msgstr ""

#: pod/progressive_web_app/static/js/notification-toast.js
msgid "Error during unsubscription..."
msgstr ""

#: pod/video/static/js/ajax-display-channels.js
msgid "Channel"
msgstr ""
Expand Down Expand Up @@ -731,6 +745,10 @@ msgstr ""
msgid "Select the general type of the video."
msgstr ""

#: pod/video/static/js/video_edit.js
msgid "Get notified when the video encoding is finished."
msgstr ""

#: pod/video/static/js/video_stats_view.js
msgid "Title"
msgstr "Titel"
Expand Down
24 changes: 23 additions & 1 deletion pod/main/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,28 @@
"fr": "Configuration application podfile"
}
},
"progressive_web_app": {
"description": {},
"settings": {
"WEBPUSH_SETTINGS": {
"default_value": "```python\n{\n 'VAPID_PUBLIC_KEY': '',\n 'VAPID_PRIVATE_KEY': '',\n 'VAPID_ADMIN_EMAIL': '[email protected]'\n}\n```",
"description": {
"en": [
""
],
"fr": [
"Les clés VAPID sont nécessaires à la lib [django-webpush](https://github.com/safwanrahman/django-webpush). Elles peuvent être générées avec [https://web-push-codelab.glitch.me/]()"
]
},
"pod_version_end": "",
"pod_version_init": ""
}
},
"title": {
"en": "",
"fr": "Configuration application progressive_web_app"
}
},
"recorder": {
"description": {},
"settings": {
Expand Down Expand Up @@ -4965,4 +4987,4 @@
}
}
}
]
]
6 changes: 5 additions & 1 deletion pod/main/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% load static i18n custom_tags %}
{% load pwa %}
{% load webpush_notifications %}
{% get_current_language as LANGUAGE_CODE %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">
Expand Down Expand Up @@ -46,8 +48,9 @@
{% if request.GET.is_iframe %}
<link rel="stylesheet" href="{% static 'css/iframe.css' %}?ver={{VERSION}}" media="screen">
{% endif %}
{% progressive_web_app_meta %}
{% endspaceless %}

{% webpush_header %}
</head>

<body>
Expand Down Expand Up @@ -116,6 +119,7 @@ <h1 class="page_title">{{page_title|capfirst}}</h1>
{% endif %}
</div> <!-- fin div pod-grid-content -->
</main>
{% include "notification_toast.html" %}
</div> <!-- fin container -->
{% endblock content %}
{% if not request.GET.is_iframe %}
Expand Down
5 changes: 5 additions & 0 deletions pod/main/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ <h5 id="pod-navbar__menuuserLabel">{% if user.get_full_name != '' %}{{ user.get_
<a class="nav-item nav-link" href="{% url 'bbb:live_list_meeting' %}"><i class="bi bi-lightning-charge pod-nav-link-icon mx-1" aria-hidden="true"></i>{% trans 'Perform a BigBlueButton live' %}</a>
{% endif %}
{% endif %}
<div class="nav-item">
<button class="nav-link" onclick="new bootstrap.Toast(document.querySelector('#notification-toast')).show()">
<i class="bi bi-bell pod-nav-link-icon mx-1" aria-hidden="true"></i>{% trans 'Notifications settings' %}
</button>
</div>
{% comment %}
<a class="nav-item nav-link" href="#">Gestion de mon compte</a> {% endcomment %}
<hr class="dropdown-divider">
Expand Down
23 changes: 22 additions & 1 deletion pod/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from wsgiref.util import FileWrapper
from django.db.models import Q, Count
from pod.video.models import Video, remove_accents
from pod.authentication.forms import FrontOwnerForm
from pod.authentication.forms import FrontOwnerForm, SetNotificationForm
from django.db.models import Sum
import os
import mimetypes
Expand Down Expand Up @@ -395,3 +395,24 @@ def userpicture(request):
"userpicture/userpicture.html",
{"frontOwnerForm": frontOwnerForm},
)


@csrf_protect
@login_required(redirect_field_name="referrer")
def set_notifications(request):
"""Sets 'accepts_notifications' attribute on owner instance."""
setNotificationForm = SetNotificationForm(instance=request.user.owner)

if request.method == "POST":
setNotificationForm = SetNotificationForm(request.POST, instance=request.user.owner)
if setNotificationForm.is_valid():
setNotificationForm.save()
return JsonResponse({"success": True, "user_accepts_notifications": request.user.owner.accepts_notifications})
else:
messages.add_message(
request,
messages.ERROR,
_("One or more errors have been found in the form."),
)

return JsonResponse({"success": False})
Empty file.
8 changes: 8 additions & 0 deletions pod/progressive_web_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig


class ProgressiveWebAppConfig(AppConfig):
"""Push notification preferences."""

default_auto_field = "django.db.models.BigAutoField"
name = "pod.progressive_web_app"
Binary file added pod/progressive_web_app/static/img/icon_x1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x384.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6113409

Please sign in to comment.