From 4c0a5922c4fdef07c8d72622466cd4f3c0139125 Mon Sep 17 00:00:00 2001 From: korenstin Date: Mon, 15 Jul 2024 22:06:11 +0200 Subject: [PATCH] Allow to order the 2 tables and to fix the bug of several activities --- .../templates/activity/activity_list.html | 2 +- apps/activity/views.py | 34 +++++++++++++------ locale/fr/LC_MESSAGES/django.po | 16 ++++----- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/apps/activity/templates/activity/activity_list.html b/apps/activity/templates/activity/activity_list.html index 3316d698..bf5ba70f 100644 --- a/apps/activity/templates/activity/activity_list.html +++ b/apps/activity/templates/activity/activity_list.html @@ -46,4 +46,4 @@ SPDX-License-Identifier: GPL-3.0-or-later {% render_table table %} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/apps/activity/views.py b/apps/activity/views.py index f3cc79ad..74e39fb0 100644 --- a/apps/activity/views.py +++ b/apps/activity/views.py @@ -17,7 +17,8 @@ from django.utils.translation import gettext_lazy as _ from django.views import View from django.views.decorators.cache import cache_page from django.views.generic import DetailView, TemplateView, UpdateView -from django_tables2.views import SingleTableView +from django.views.generic.list import ListView +from django_tables2.views import MultiTableMixin from note.models import Alias, NoteSpecial, NoteUser from permission.backends import PermissionBackend from permission.views import ProtectQuerysetMixin, ProtectedCreateView @@ -57,27 +58,40 @@ class ActivityCreateView(ProtectQuerysetMixin, ProtectedCreateView): return reverse_lazy('activity:activity_detail', kwargs={"pk": self.object.pk}) -class ActivityListView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView): +class ActivityListView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, ListView): """ Displays all Activities, and classify if they are on-going or upcoming ones. """ model = Activity - table_class = ActivityTable - ordering = ('-date_start',) + tables = [ActivityTable, ActivityTable] extra_context = {"title": _("Activities")} def get_queryset(self, **kwargs): return super().get_queryset(**kwargs).distinct() + def get_tables(self): + tables = super().get_tables() + + tables[0].prefix = "all-" + tables[1].prefix = "upcoming-" + return tables + + def get_tables_data(self): + # first table = all activities, second table = upcoming + return [ + self.get_queryset().order_by("-date_start"), + Activity.objects.filter(date_end__gt=timezone.now()) + .filter(PermissionBackend.filter_queryset(self.request, Activity, "view")) + .distinct() + .order_by("date_start") + ] + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - upcoming_activities = Activity.objects.filter(date_end__gt=timezone.now()) - context['upcoming'] = ActivityTable( - data=upcoming_activities.filter(PermissionBackend.filter_queryset(self.request, Activity, "view")), - prefix='upcoming-', - order_by='date_start', - ) + tables = context["tables"] + for name, table in zip(["table", "upcoming"], tables): + context[name] = table started_activities = self.get_queryset().filter(open=True, valid=True).distinct().all() context["started_activities"] = started_activities diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index c6ca48b0..85ef76da 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -400,37 +400,37 @@ msgstr "Inviter" msgid "Create new activity" msgstr "Créer une nouvelle activité" -#: apps/activity/views.py:67 note_kfet/templates/base.html:90 +#: apps/activity/views.py:68 note_kfet/templates/base.html:90 msgid "Activities" msgstr "Activités" -#: apps/activity/views.py:93 +#: apps/activity/views.py:108 msgid "Activity detail" msgstr "Détails de l'activité" -#: apps/activity/views.py:113 +#: apps/activity/views.py:128 msgid "Update activity" msgstr "Modifier l'activité" -#: apps/activity/views.py:140 +#: apps/activity/views.py:155 msgid "Invite guest to the activity \"{}\"" msgstr "Invitation pour l'activité « {} »" -#: apps/activity/views.py:178 +#: apps/activity/views.py:193 msgid "You are not allowed to display the entry interface for this activity." msgstr "" "Vous n'êtes pas autorisé·e à afficher l'interface des entrées pour cette " "activité." -#: apps/activity/views.py:181 +#: apps/activity/views.py:196 msgid "This activity does not support activity entries." msgstr "Cette activité ne requiert pas d'entrées." -#: apps/activity/views.py:184 +#: apps/activity/views.py:199 msgid "This activity is closed." msgstr "Cette activité est fermée." -#: apps/activity/views.py:280 +#: apps/activity/views.py:295 msgid "Entry for activity \"{}\"" msgstr "Entrées pour l'activité « {} »"