Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADMIN] Affichage des conversations d'une structure #863

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lemarche/conversations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ def sender_email_siae_encoded(self):
def sender_email_siae(self):
return self.siae.contact_email

@property
def nb_messages(self):
"""Number of messages is the len of data item + the initial message

Returns:
int: Number of all messages
"""
return len(self.data) + 1

@staticmethod
def get_email_info_from_address(address_mail: str) -> list:
"""Extract info from address mail managed by this class
Expand Down
27 changes: 26 additions & 1 deletion lemarche/siaes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.utils.html import format_html, mark_safe
from fieldsets_with_inlines import FieldsetsInlineMixin

from lemarche.conversations.models import Conversation
from lemarche.labels.models import Label
from lemarche.notes.models import Note
from lemarche.siaes.models import (
Expand Down Expand Up @@ -103,6 +104,29 @@ def user_with_link(self, siae_user):
user_with_link.short_description = User._meta.verbose_name


class ConversationsInline(admin.TabularInline):
madjid-asa marked this conversation as resolved.
Show resolved Hide resolved
model = Conversation
can_delete = False

fields = ["id", "title_with_link", "nb_message_with_link", "kind", "created_at"]

# autocomplete_fields = ["user"]
readonly_fields = ["id", "title_with_link", "nb_message_with_link", "kind", "created_at"]
extra = 0

def title_with_link(self, conversation: Conversation):
url = reverse("admin:conversations_conversation_change", args=[conversation.id])
return format_html(f'<a href="{url}">{conversation.title}</a>')

title_with_link.short_description = "Titre"

def nb_message_with_link(self, conversation: Conversation):
url = reverse("admin:conversations_conversation_change", args=[conversation.id])
return format_html(f'<a href="{url}">{conversation.nb_messages}</a>')

nb_message_with_link.short_description = "Nombre de messages"


@admin.register(Siae, site=admin_site)
class SiaeAdmin(FieldsetsInlineMixin, gis_admin.OSMGeoAdmin):
actions = [export_as_xls]
Expand Down Expand Up @@ -255,6 +279,7 @@ class SiaeAdmin(FieldsetsInlineMixin, gis_admin.OSMGeoAdmin):
},
),
SiaeNoteInline,
ConversationsInline,
SiaeUserInline,
(
"Logo",
Expand Down Expand Up @@ -419,7 +444,7 @@ def save_formset(self, request, form, formset, change):
Set Note author on create
"""
for form in formset:
if type(form.instance) == Note:
if type(form.instance) is Note:
if not form.instance.id and form.instance.text and change:
form.instance.author = request.user
super().save_formset(request, form, formset, change)
Expand Down