From 441af33ddd26b7487de078ede91693dc7eab2455 Mon Sep 17 00:00:00 2001 From: Karl Determe Date: Fri, 14 Aug 2026 22:08:13 +0200 Subject: [PATCH] feat: implement discussion list and notification inbox UI with mention handling tags --- streetup/notifications/models.py | 49 ++++++ .../notifications/discussion_list.html | 152 +++++++++++++----- .../templates/notifications/inbox.html | 146 ++++++++++++----- .../templatetags/mention_tags.py | 62 +++++++ 4 files changed, 331 insertions(+), 78 deletions(-) diff --git a/streetup/notifications/models.py b/streetup/notifications/models.py index 7aeda16..d7d43c3 100644 --- a/streetup/notifications/models.py +++ b/streetup/notifications/models.py @@ -376,6 +376,55 @@ class Discussion(models.Model): archived_at__isnull=True, ).count() + @property + def type_info(self): + """Retourne les classes de style, l'icône et le libellé du type d'objet lié.""" + model_name = self.content_type.model.lower() if self.content_type else '' + lbl = (self.object_label or '').lower() + title_low = (self.title or '').lower() + + if model_name == 'intervention' or lbl.startswith('intervention') or title_low.startswith('intervention'): + return { + 'icon': 'bi-tools', + 'bg_class': 'bg-primary-subtle', + 'text_class': 'text-primary', + 'border_class': 'border-primary-subtle', + 'label': _("Intervention"), + } + elif model_name == 'observation' or lbl.startswith('observation') or title_low.startswith('observation'): + return { + 'icon': 'bi-eye-fill', + 'bg_class': 'bg-warning-subtle', + 'text_class': 'text-warning-emphasis', + 'border_class': 'border-warning-subtle', + 'label': _("Observation"), + } + elif model_name == 'preparationorder' or 'préparation' in lbl or 'preparation' in lbl: + return { + 'icon': 'bi-box-seam-fill', + 'bg_class': 'bg-info-subtle', + 'text_class': 'text-info-emphasis', + 'border_class': 'border-info-subtle', + 'label': _("Ordre de préparation"), + } + elif model_name == 'project' or lbl.startswith('projet') or title_low.startswith('projet'): + return { + 'icon': 'bi-kanban-fill', + 'bg_class': 'bg-success-subtle', + 'text_class': 'text-success-emphasis', + 'border_class': 'border-success-subtle', + 'label': _("Projet"), + } + else: + return { + 'icon': 'bi-chat-dots-fill', + 'bg_class': 'bg-indigo-subtle', + 'text_class': 'text-primary', + 'border_class': 'border-primary-subtle', + 'label': _("Générale"), + } + + class Meta: verbose_name = _("Discussion") verbose_name_plural = _("Discussions") diff --git a/streetup/notifications/templates/notifications/discussion_list.html b/streetup/notifications/templates/notifications/discussion_list.html index 9371b0c..c46df05 100644 --- a/streetup/notifications/templates/notifications/discussion_list.html +++ b/streetup/notifications/templates/notifications/discussion_list.html @@ -1,30 +1,63 @@ {% extends "base.html" %} {% load i18n %} {% load static %} +{% load mention_tags %} {% block head %} {% endblock %} @@ -50,64 +83,95 @@ {% if not items %} -
+
- +

{% translate "Vous n'avez encore aucune discussion." %}

{% else %} -
+
{% for item in items %} + class="list-group-item list-group-item-action discussion-item px-3 px-md-4 py-3 {% if item.unread_count %}has-unread{% endif %}">
- -
- + + {% with type_info=item.discussion.type_info %} +
+
+ {% endwith %}
-
-
- {{ item.discussion.title|default:item.discussion }} - {% if item.discussion.object_label %} - - {{ item.discussion.object_label }} +
+
+ + {{ item.discussion.title|default:item.discussion }} + + {% if item.discussion.object_label and item.discussion.object_label != item.discussion.title %} + + {{ item.discussion.object_label }} + + {% endif %} + {% if item.discussion.is_closed %} + + {% translate "Clôturée" %} {% endif %}
- + + {{ item.discussion.updated_at|date:"d/m/Y H:i" }}
+ + {% if item.last_message %} -

- {{ item.last_message.author.get_full_name|default:item.last_message.author.username }} : - {{ item.last_message.content|truncatechars:120 }} +

+ {{ item.last_message.author.get_full_name|default:item.last_message.author.username }} : + {{ item.last_message.content|clean_mentions_preview|truncatechars:140 }}

{% else %} -

{% translate "Aucun message encore." %}

+

{% translate "Aucun message encore." %}

{% endif %} - -
- {% for p in item.discussion.participants.all|slice:":6" %} - - {{ p.get_full_name|default:p.username|truncatechars:12 }} + + +
+
+ + {% translate "Participants" %} : + +
+ {% for p in item.discussion.participants.all|slice:":6" %} +
+ {{ p|user_initials }} +
+ {% endfor %} + {% if item.discussion.participants.count > 6 %} +
+ +{{ item.discussion.participants.count|add:"-6" }} +
+ {% endif %} +
+
+ + + {% if item.unread_count %} + + {{ item.unread_count }} {% translate "non lu(s)" %} - {% endfor %} - {% if item.discussion.participants.count > 6 %} - +{{ item.discussion.participants.count|add:"-6" }} {% endif %}
- - - {% if item.unread_count %} - {{ item.unread_count }} - {% endif %}
{% endfor %} @@ -118,3 +182,13 @@
{% include "notifications/_new_discussion_modal.html" %} {% endblock content %} + +{% block script %} + +{% endblock script %} + diff --git a/streetup/notifications/templates/notifications/inbox.html b/streetup/notifications/templates/notifications/inbox.html index 9bbc415..3810cf9 100644 --- a/streetup/notifications/templates/notifications/inbox.html +++ b/streetup/notifications/templates/notifications/inbox.html @@ -2,6 +2,7 @@ {% load i18n %} {% load static %} {% load roles %} +{% load mention_tags %} {% block head %}