From e255b7bdb684777b613da385489088cfc9b85a57 Mon Sep 17 00:00:00 2001 From: Lucas Brandstaetter <lucas@brandstaetter.tech> Date: Sun, 1 Dec 2024 16:15:27 +0000 Subject: [PATCH] Use activity log date in assembly list - Use the latest activity log entry date for the update display in the assembly list - Split the update display into two columns, one for staff and one for assembly updates - Color the date based on the latest update - Add a generic relation to the assembly model for the activity log entries Fixes #621 --- src/backoffice/locale/de/LC_MESSAGES/django.po | 10 +++++----- src/backoffice/locale/en/LC_MESSAGES/django.po | 10 +++++----- .../templates/backoffice/assembly_list.html | 14 ++++++++------ src/backoffice/views/assemblyteam.py | 15 ++++++++++++++- src/core/models/assemblies.py | 5 +++++ 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/backoffice/locale/de/LC_MESSAGES/django.po b/src/backoffice/locale/de/LC_MESSAGES/django.po index 7ca671949..db9214119 100644 --- a/src/backoffice/locale/de/LC_MESSAGES/django.po +++ b/src/backoffice/locale/de/LC_MESSAGES/django.po @@ -603,15 +603,12 @@ msgstr "" msgid "Assembly__is_official__short" msgstr "offiziell" -msgid "Assembly__last_update" -msgstr "letzte Änderung" - # use translation from core -msgid "Assembly__last_update_assembly" +msgid "Assembly__last_update_staff" msgstr "" # use translation from core -msgid "Assembly__last_update_staff" +msgid "Assembly__last_update_assembly" msgstr "" msgid "list" @@ -1117,6 +1114,9 @@ msgstr "nicht veröffentlicht" msgid "moderation__assembly__cannotunhide" msgstr "Eine versteckte Assembly muss vom Assembly-Team wieder in den passenden Status zurückversetzt werden (multiple Optionen)." +msgid "Assembly__last_update" +msgstr "letzte Änderung" + # use translation from core msgid "Badge__name" msgstr "" diff --git a/src/backoffice/locale/en/LC_MESSAGES/django.po b/src/backoffice/locale/en/LC_MESSAGES/django.po index 992168f95..2bdcdcd71 100644 --- a/src/backoffice/locale/en/LC_MESSAGES/django.po +++ b/src/backoffice/locale/en/LC_MESSAGES/django.po @@ -601,15 +601,12 @@ msgstr "" msgid "Assembly__is_official__short" msgstr "official" -msgid "Assembly__last_update" -msgstr "last update" - # use translation from core -msgid "Assembly__last_update_assembly" +msgid "Assembly__last_update_staff" msgstr "" # use translation from core -msgid "Assembly__last_update_staff" +msgid "Assembly__last_update_assembly" msgstr "" msgid "list" @@ -1116,6 +1113,9 @@ msgstr "not public" msgid "moderation__assembly__cannotunhide" msgstr "A hidden assembly can only be reversed by the assembly team as there are multiple valid states/types." +msgid "Assembly__last_update" +msgstr "last update" + # use translation from core msgid "Badge__name" msgstr "" diff --git a/src/backoffice/templates/backoffice/assembly_list.html b/src/backoffice/templates/backoffice/assembly_list.html index 6afad8c85..00232d8b7 100644 --- a/src/backoffice/templates/backoffice/assembly_list.html +++ b/src/backoffice/templates/backoffice/assembly_list.html @@ -69,7 +69,8 @@ {% if conference.support_channels %} <th>{% trans "Assembly__state_channel" %}</th> {% endif %} - <th>{% trans "Assembly__last_update" %}</th> + <th>{% trans "Assembly__last_update_staff" %}</th> + <th>{% trans "Assembly__last_update_assembly" %}</th> </tr> </thead> <tbody> @@ -102,11 +103,12 @@ </td> {% endif %} <td> - {% if assembly.last_update_assembly > assembly.last_update_staff %} - <span title="{% trans "Assembly__last_update_assembly" %}">{{ assembly.last_update_assembly|naturaltime }}</span> - {% else %} - <span class="text-muted" title="{% trans "Assembly__last_update_staff" %}">{{ assembly.last_update_staff|naturaltime }}</span> - {% endif %} + <span class="{% if assembly.last_activity_log_staff > assembly.last_activity_log_assembly %}text-success{% endif %}" + title="{% trans "Assembly__last_update_staff" %}">{{ assembly.last_activity_log_staff|naturaltime }}</span> + </td> + <td> + <span class="{% if assembly.last_activity_log_assembly > assembly.last_activity_log_staff %}text-success{% endif %}" + title="{% trans "Assembly__last_update_assembly" %}">{{ assembly.last_activity_log_assembly|naturaltime }}</span> </td> </tr> {% endfor %} diff --git a/src/backoffice/views/assemblyteam.py b/src/backoffice/views/assemblyteam.py index c26d5a62a..3e519b5fc 100644 --- a/src/backoffice/views/assemblyteam.py +++ b/src/backoffice/views/assemblyteam.py @@ -7,7 +7,7 @@ from pandas import DataFrame, ExcelWriter from django.contrib import messages from django.contrib.postgres.aggregates import StringAgg -from django.db.models import OuterRef, Q, Subquery +from django.db.models import Max, OuterRef, Q, Subquery from django.http import Http404, HttpResponse from django.shortcuts import redirect, render from django.urls import reverse @@ -212,6 +212,19 @@ class AssemblyView(SingleAssemblyTeamMixin, DetailView): class AssembliesView(AssembliesListMixin, AlphabeticalPaginatorView): template_name = 'backoffice/assembly_list.html' + def get_queryset(self, **kwargs): + qs = ( + super() + .get_queryset(**kwargs) + .annotate( + last_activity_log_staff=Max( + 'activity_log_entries__timestamp', filter=Q(activity_log_entries__kind__in=[ActivityLogEntry.Kind.STAFF, ActivityLogEntry.Kind.MESSAGE]) + ), + last_activity_log_assembly=Max('activity_log_entries__timestamp', filter=Q(activity_log_entries__kind=ActivityLogEntry.Kind.ENTITY)), + ) + ) + return qs + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) diff --git a/src/core/models/assemblies.py b/src/core/models/assemblies.py index 7bb008b67..eee23e2b6 100644 --- a/src/core/models/assemblies.py +++ b/src/core/models/assemblies.py @@ -264,6 +264,11 @@ class Assembly(TaggedItemMixin, ActivityLogMixin, RulesModel): help_text=_('Assembly__last_update_staff__help'), verbose_name=_('Assembly__last_update_staff'), ) + activity_log_entries = GenericRelation( + ActivityLogEntry, + object_id_field='entity_object_id', + content_type_field='entity_content_type', + ) favorite_of = models.ManyToManyField( PlatformUser, related_name='favorite_assemblies', help_text=_('Assembly__favorite_of__help'), verbose_name=_('Assembly__favorite_of') -- GitLab