Ticket Item Changes & Ticket.string_datetime

Added string datetime and indicators for priority and departments.

Also added a toggle for the indicators/departments to be shown.
This commit is contained in:
2024-01-22 01:05:31 +00:00
parent 4344dfb271
commit 90abffac05
5 changed files with 123 additions and 74 deletions

View File

@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*-
import logging
import bleach
from uuid import uuid4
from datetime import timedelta, datetime
@ -9,6 +10,8 @@ from django.conf import settings
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
log = logging.getLogger(__name__)
class TicketPriority(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)
@ -152,7 +155,7 @@ class Ticket(models.Model):
@property
def was_yesterday(self) -> bool:
"""_summary_
"""Returns a boolean dependent on if `self.timestamp` is from before midnight yesterday.
Returns
-------
@ -165,6 +168,45 @@ class Ticket(models.Model):
return self.timestamp < midnight_today
@property
def string_datetime(self) -> str:
"""Provides a human readable string representation of `self.timestamp` that should be displayed
to represent the ticket's age.
Returns
-------
str
The string representation of `self.timestamp`.
"""
difference = timezone.now() - self.timestamp
days = difference.days
hours = difference.total_seconds() // 3600
minutes = difference.total_seconds() // 60
seconds = difference.total_seconds()
hours, minutes, seconds = map(int, (hours, minutes, seconds))
if seconds < 60:
value, unit = seconds, "second"
elif minutes < 60:
value, unit = minutes, "minute"
elif hours < 24:
value, unit = hours, "hour"
elif days < 7:
value, unit = days, "day"
else:
return self.timestamp.strftime("%Y-%m-%d")
if value > 1:
unit += "s"
return f"{value} {unit} ago"
@property
def timestamp(self) -> datetime: