From a1c1a206612a39aae861217bae05327bde1819ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bonavent?= <56730254+LoicBonavent@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:39:04 +0100 Subject: [PATCH] [DONE] Correctly counts the number of sub-theme videos in a theme (#1068) * Correctly counts the number of sub-theme videos in a theme * Displays different messages according to channel / theme / sub-theme level * Translations added * Add type hint, refactor some source code and manage theme as serializable (in the new function) so that tests pass --- pod/locale/fr/LC_MESSAGES/django.po | 89 +++++++++++++----------- pod/locale/fr/LC_MESSAGES/djangojs.po | 2 +- pod/locale/nl/LC_MESSAGES/django.po | 41 ++++++----- pod/locale/nl/LC_MESSAGES/djangojs.po | 2 +- pod/video/templates/channel/channel.html | 14 ++-- pod/video/views.py | 44 ++++++++++-- 6 files changed, 121 insertions(+), 71 deletions(-) diff --git a/pod/locale/fr/LC_MESSAGES/django.po b/pod/locale/fr/LC_MESSAGES/django.po index a4e9c88e11..43cc5e54d4 100644 --- a/pod/locale/fr/LC_MESSAGES/django.po +++ b/pod/locale/fr/LC_MESSAGES/django.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Pod\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-03-01 13:49+0100\n" +"POT-Creation-Date: 2024-03-06 12:13+0100\n" "PO-Revision-Date: \n" "Last-Translator: obado \n" "Language-Team: Pod Team cotech-esup-pod@esup-portail.org\n" @@ -2579,8 +2579,8 @@ msgid "" "a>." msgstr "" "L’accès à l’ajout d’enregistrements externes a été limité. Si vous souhaitez " -"ajouter des enregistrements externes sur la plateforme, veuillez nous contacter." +"ajouter des enregistrements externes sur la plateforme, veuillez nous contacter." #: pod/import_video/templates/import_video/add_or_edit.html msgid "" @@ -2970,8 +2970,8 @@ msgstr "" #: pod/import_video/views.py #, python-format msgid "" -"This video “%(name)s” was uploaded to Pod; its origin is %(type)s: %(url)s

%(desc)s" +"This video “%(name)s” was uploaded to Pod; its origin is %(type)s: %(url)s

%(desc)s" msgstr "" "Cette vidéo « %(name)s » a été téléversée sur Pod ; son origine est " "%(type)s : %(url)s

%(desc)s" @@ -2979,8 +2979,8 @@ msgstr "" #: pod/import_video/views.py #, python-format msgid "" -"This video “%(name)s” was uploaded to Pod; its origin is Youtube: %(url)s" +"This video “%(name)s” was uploaded to Pod; its origin is Youtube: %(url)s" msgstr "" "Cette vidéo « %(name)s » a été téléversée sur Pod ; son origine est " "Youtube : %(url)s" @@ -4822,17 +4822,6 @@ msgstr "Onglet additionnel de chaînes" msgid "Additional channel Tabs" msgstr "Onglets additionnels de chaînes" -#: pod/main/settings.py -msgid "" -"Pod 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 a pour but de faciliter la mise à disposition de vidéos et de ce fait, " -"d’encourager l’utilisation de celles-ci dans le cadre de l’enseignement et " -"la recherche." - #: pod/main/templates/403.html msgid "Permission denied" msgstr "Accès refusé" @@ -5956,16 +5945,16 @@ msgid "" msgstr "" "\n" "

Bonjour,\n" -"

%(owner)s vous invite à une réunion récurrente " -"%(meeting_title)s.

\n" +"

%(owner)s vous invite à une réunion récurrente " +"%(meeting_title)s.

\n" "

Date de début : %(start_date_time)s

\n" "

Récurrent jusqu’à la date : %(end_date)s

\n" "

La réunion se tiendra tou(te)s les %(frequency)s %(recurrence)s \n" "

Voici le lien pour rejoindre la réunion :\n" " %(join_link)s

\n" -"

Vous avez besoin de ce mot de passe pour entrer : " -"%(password)s

\n" +"

Vous avez besoin de ce mot de passe pour entrer : " +"%(password)s

\n" "

Cordialement

\n" " " @@ -5991,8 +5980,8 @@ msgstr "" "

Date de fin : %(end_date)s

\n" "

Voici le lien pour rejoindre la réunion :\n" " %(join_link)s

\n" -"

Vous avez besoin de ce mot de passe pour entrer : " -"%(password)s

\n" +"

Vous avez besoin de ce mot de passe pour entrer : " +"%(password)s

\n" "

Cordialement

\n" " " @@ -7045,8 +7034,8 @@ msgstr "Prévisualisation d’enregistrement" #: pod/video/templates/videos/video-element.html msgid "" "To view this video please enable JavaScript, and consider upgrading to a web " -"browser that supports HTML5 video" +"browser that supports HTML5 video" msgstr "" "Pour visionner cette vidéo, veuillez activer JavaScript et envisager de " "passer à un navigateur Web qui Bonjour,
un nouvel enregistrement a été ajouté sur la plateforme " "%(title_site)s à partir de l’enregistreur « %(recorder)s ».
Pour " -"l’ajouter, cliquez sur le lien ci-dessous.

%(link_url)s
Si le lien n’est pas actif, il " -"faut le copier-coller dans la barre d’adresse de votre navigateur.

Cordialement.

" +"l’ajouter, cliquez sur le lien ci-dessous.

" +"%(link_url)s
Si le lien n’est pas actif, il faut le copier-coller " +"dans la barre d’adresse de votre navigateur.

Cordialement.

" #: pod/recorder/views.py msgid "New recording added." @@ -7475,8 +7463,8 @@ msgid "" "%(url)s

\n" msgstr "" "vous pouvez changer la date de suppression en éditant votre vidéo :

\n" -"

%(scheme)s:%(url)s

\n" +"

" +"%(scheme)s:%(url)s

\n" "\n" #: pod/video/management/commands/check_obsolete_videos.py @@ -7896,12 +7884,16 @@ msgstr[0] "%(counter)s thème trouvé dans cette chaine" msgstr[1] "%(counter)s thèmes trouvés dans cette chaine" #: pod/video/templates/channel/channel.html -#: pod/video/templates/videos/dashboard.html -#, python-format -msgid "%(counter)s video" -msgid_plural "%(counter)s videos" -msgstr[0] "%(counter)s vidéo" -msgstr[1] "%(counter)s vidéos" +msgid "%(counter)s video for this channel" +msgid_plural "%(counter)s videos for this channel" +msgstr[0] "%(counter)s vidéo trouvée dans cette chaine" +msgstr[1] "%(counter)s vidéos trouvées dans cette chaine" + +#: pod/video/templates/channel/channel.html +msgid "%(counter)s subtheme found for this theme" +msgid_plural "%(counter)s subthemes found for this theme" +msgstr[0] "%(counter)s sous-thème trouvé dans ce thème" +msgstr[1] "%(counter)s sous-thèmes trouvés dans ce thème" # python-format #: pod/video/templates/channel/channel.html @@ -8196,6 +8188,13 @@ msgstr "Nouvelle valeur pour le champ %(field_label)s" msgid "No video found" msgstr "Aucune vidéo trouvée." +#: pod/video/templates/videos/dashboard.html +#, python-format +msgid "%(counter)s video" +msgid_plural "%(counter)s videos" +msgstr[0] "%(counter)s vidéo" +msgstr[1] "%(counter)s vidéos" + #: pod/video/templates/videos/dashboard.html msgid "Clear selection" msgstr "Effacer la sélection" @@ -8320,8 +8319,8 @@ msgid "" "This video is chaptered. Click the chapter button on the video player to view them." msgstr "" -"Cette vidéo est chapitrée. Cliquez sur le bouton de chapitre sur le lecteur vidéo pour les voir." +"Cette vidéo est chapitrée. Cliquez sur le bouton de chapitre sur le lecteur vidéo pour les voir." #: pod/video/templates/videos/video-all-info.html msgid "Other versions" @@ -9278,6 +9277,16 @@ msgstr "Résultats de la recherche" msgid "Esup-Pod xAPI" msgstr "xAPI Esup-Pod" +#~ msgid "" +#~ "Pod 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 a pour but de faciliter la mise à disposition de vidéos et de ce " +#~ "fait, d’encourager l’utilisation de celles-ci dans le cadre de " +#~ "l’enseignement et la recherche." + #~ msgid "The HTML file for this recording was not found on the server." #~ msgstr "" #~ "Le fichier HTML de cet enregistrement est introuvable sur le serveur." diff --git a/pod/locale/fr/LC_MESSAGES/djangojs.po b/pod/locale/fr/LC_MESSAGES/djangojs.po index 11a9ebb8a1..3eea069894 100644 --- a/pod/locale/fr/LC_MESSAGES/djangojs.po +++ b/pod/locale/fr/LC_MESSAGES/djangojs.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Esup-Pod\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-03-01 13:49+0100\n" +"POT-Creation-Date: 2024-03-06 12:13+0100\n" "PO-Revision-Date: \n" "Last-Translator: obado \n" "Language-Team: \n" diff --git a/pod/locale/nl/LC_MESSAGES/django.po b/pod/locale/nl/LC_MESSAGES/django.po index a2d63bde3c..6b75e5fb3c 100644 --- a/pod/locale/nl/LC_MESSAGES/django.po +++ b/pod/locale/nl/LC_MESSAGES/django.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Pod\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-03-01 13:49+0100\n" +"POT-Creation-Date: 2024-03-06 12:13+0100\n" "PO-Revision-Date: 2023-06-08 14:37+0200\n" "Last-Translator: obado \n" "Language-Team: \n" @@ -2787,15 +2787,15 @@ msgstr "" #: pod/import_video/views.py #, python-format msgid "" -"This video “%(name)s” was uploaded to Pod; its origin is %(type)s: %(url)s

%(desc)s" +"This video “%(name)s” was uploaded to Pod; its origin is %(type)s: %(url)s

%(desc)s" msgstr "" #: pod/import_video/views.py #, python-format msgid "" -"This video “%(name)s” was uploaded to Pod; its origin is Youtube: %(url)s" +"This video “%(name)s” was uploaded to Pod; its origin is Youtube: %(url)s" msgstr "" #: pod/import_video/views.py @@ -4563,14 +4563,6 @@ msgstr "" msgid "Additional channel Tabs" msgstr "" -#: pod/main/settings.py -msgid "" -"Pod 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/main/templates/403.html msgid "Permission denied" msgstr "" @@ -6637,8 +6629,8 @@ msgstr "" #: pod/video/templates/videos/video-element.html msgid "" "To view this video please enable JavaScript, and consider upgrading to a web " -"browser that supports HTML5 video" +"browser that supports HTML5 video" msgstr "" #: pod/recorder/templates/recorder/link_record.html @@ -7394,10 +7386,16 @@ msgstr[0] "" msgstr[1] "" #: pod/video/templates/channel/channel.html -#: pod/video/templates/videos/dashboard.html #, python-format -msgid "%(counter)s video" -msgid_plural "%(counter)s videos" +msgid "%(counter)s video for this channel" +msgid_plural "%(counter)s videos for this channel" +msgstr[0] "" +msgstr[1] "" + +#: pod/video/templates/channel/channel.html +#, python-format +msgid "%(counter)s subtheme found for this theme" +msgid_plural "%(counter)s subthemes found for this theme" msgstr[0] "" msgstr[1] "" @@ -7676,6 +7674,13 @@ msgstr "" msgid "No video found" msgstr "" +#: pod/video/templates/videos/dashboard.html +#, python-format +msgid "%(counter)s video" +msgid_plural "%(counter)s videos" +msgstr[0] "" +msgstr[1] "" + #: pod/video/templates/videos/dashboard.html msgid "Clear selection" msgstr "" diff --git a/pod/locale/nl/LC_MESSAGES/djangojs.po b/pod/locale/nl/LC_MESSAGES/djangojs.po index af89d1a839..f9778905ef 100644 --- a/pod/locale/nl/LC_MESSAGES/djangojs.po +++ b/pod/locale/nl/LC_MESSAGES/djangojs.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Esup-Pod\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-03-01 13:49+0100\n" +"POT-Creation-Date: 2024-03-06 12:13+0100\n" "PO-Revision-Date: 2023-02-08 15:22+0100\n" "Last-Translator: obado \n" "Language-Team: \n" diff --git a/pod/video/templates/channel/channel.html b/pod/video/templates/channel/channel.html index bc15471e49..6621ffecbe 100644 --- a/pod/video/templates/channel/channel.html +++ b/pod/video/templates/channel/channel.html @@ -110,11 +110,17 @@

{{title}}

- {% if count_themes > 0 %} - {% blocktrans count counter=count_themes %}{{ counter }} theme found for this channel{% plural %}{{ counter }} themes found for this channel{% endblocktrans %} - - + {% if not parent_title %} + {% if count_themes > 0 %} + {% blocktrans count counter=count_themes %}{{ counter }} theme found for this channel{% plural %}{{ counter }} themes found for this channel{% endblocktrans %} + - + {% endif %} + {% blocktrans count counter=channel.video_count %}{{counter}} video for this channel{% plural %}{{counter}} videos for this channel{% endblocktrans %} + {% else %} + {% if count_themes > 0 %} + {% blocktrans count counter=count_themes %}{{ counter }} subtheme found for this theme{% plural %}{{ counter }} subthemes found for this theme{% endblocktrans %} + {% endif %} {% endif %} - {% blocktrans count counter=channel.video_count %}{{counter}} video{% plural %}{{counter}} videos{% endblocktrans %}

{% if theme_children|length %}
diff --git a/pod/video/views.py b/pod/video/views.py index 0748b1721b..3b404d3499 100644 --- a/pod/video/views.py +++ b/pod/video/views.py @@ -85,8 +85,9 @@ from chunked_upload.models import ChunkedUpload from chunked_upload.views import ChunkedUploadView, ChunkedUploadCompleteView -from django.db import transaction from django.db import IntegrityError +from django.db.models import QuerySet +from django.db import transaction RESTRICT_EDIT_VIDEO_ACCESS_TO_STAFF_ONLY = getattr( settings, "RESTRICT_EDIT_VIDEO_ACCESS_TO_STAFF_ONLY", False @@ -190,6 +191,36 @@ # ############################################################################ +def get_theme_children_as_list(channel: Channel, theme_children: QuerySet) -> list: + """Get theme children as a list, and not a Queryset. + + Args: + channel (Channel): current channel + theme_children (QuerySet): QuerySet of children in the theme + Returns: + list: list of children in the theme, with the right number of videos + """ + # List of children in the theme + children = list() + for child in theme_children: + if child is not None: + # Get a flat list of all theme children. + list_theme = child.get_all_children_flat() + # Videos for each child theme + videos_list = get_available_videos().filter( + channel=channel, + theme__in=list_theme + ) + child.video_count = videos_list.count() + child_serializable = { + "slug": child.slug, + "title": child.title, + "video_count": child.video_count + } + children.append(child_serializable) + return children + + def _regroup_videos_by_theme(request, videos, channel, theme=None): """Regroup videos by theme. @@ -234,12 +265,12 @@ def _regroup_videos_by_theme(request, videos, channel, theme=None): if theme_children is not None: count_themes = theme_children.count() has_more_themes = (offset + limit) < count_themes + # Default value for each child theme theme_children = theme_children.annotate( - video_count=Count("video", filter=Q(video__is_draft=False), distinct=True) + video_count=Value(0) ) - theme_children = theme_children.values("slug", "title", "video_count")[ - offset : limit + offset - ] + # List of children in the theme + children = get_theme_children_as_list(channel, theme_children) next_url, previous_url, theme_pages_info = pagination_data( request.path, offset, limit, count_themes ) @@ -249,7 +280,7 @@ def _regroup_videos_by_theme(request, videos, channel, theme=None): "previous": previous_url, "has_more_themes": has_more_themes, "count_themes": count_themes, - "theme_children": list(theme_children), + "theme_children": children, "pages_info": theme_pages_info, } title = channel.title if theme is None else theme.title @@ -302,7 +333,6 @@ def paginator(videos_list, page): def channel(request, slug_c, slug_t=None): channel = get_object_or_404(Channel, slug=slug_c, site=get_current_site(request)) - videos_list = get_available_videos().filter(channel=channel) channel.video_count = videos_list.count()