From c0c7cdcf831963297ea7394aa5d8e6f3907ba027 Mon Sep 17 00:00:00 2001 From: Jon Date: Sat, 12 Oct 2024 22:12:23 +0930 Subject: [PATCH] feat(core): Add attribute `staatus_badge` to ticket model ref: #345 #346 --- app/core/models/ticket/ticket.py | 37 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/app/core/models/ticket/ticket.py b/app/core/models/ticket/ticket.py index a3e532695..314aa0925 100644 --- a/app/core/models/ticket/ticket.py +++ b/app/core/models/ticket/ticket.py @@ -690,15 +690,17 @@ def linked_items(self) -> list(dict()): linked_items: list = [] - from core.models.ticket.ticket_linked_items import TicketLinkedItem + if self.pk: - items = TicketLinkedItem.objects.filter( - ticket = self - ) + from core.models.ticket.ticket_linked_items import TicketLinkedItem + + items = TicketLinkedItem.objects.filter( + ticket = self + ) - if len(items) > 0: + if len(items) > 0: - linked_items = items + linked_items = items return linked_items @@ -871,6 +873,29 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields signals.m2m_changed.connect(self.action_comment_ticket_teams, Ticket.subscribed_teams.through) + + @property + def status_badge(self): + + from core.classes.badge import Badge + + text:str = 'Add' + + if self.status: + + text:str = str(self.get_status_display()) + style:str = text.replace('(', '') + style = style.replace(')', '') + style = style.replace(' ', '_') + + return Badge( + icon_name = f'ticket_status_{style.lower()}', + icon_style = f'ticket-status-icon ticket-status-icon-{style.lower()}', + text = text, + text_style = f'ticket-status-text badge-text-ticket_status-{style.lower()}', + ) + + def ticketassigned(self, instance) -> bool: """ Check if the ticket has any assigned user(s)/team(s)"""