TicketTag/Priority order field
This commit is contained in:
parent
62bd7de0be
commit
97141dec4d
@ -130,7 +130,7 @@ class TicketPrioritySerializer(DynamicModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = TicketPriority
|
model = TicketPriority
|
||||||
fields = [
|
fields = [
|
||||||
"uuid", "title", "colour", "backgroundcolour"
|
"uuid", "title", "colour", "backgroundcolour", "order"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ class TicketTagSerializer(DynamicModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = TicketTag
|
model = TicketTag
|
||||||
fields = [
|
fields = [
|
||||||
"uuid", "title", "colour", "backgroundcolour"
|
"uuid", "title", "colour", "backgroundcolour", "order"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -151,6 +151,6 @@ class TicketSerializer(DynamicModelSerializer):
|
|||||||
model = Ticket
|
model = Ticket
|
||||||
fields = (
|
fields = (
|
||||||
"uuid", "title", "description", "author", "create_timestamp",
|
"uuid", "title", "description", "author", "create_timestamp",
|
||||||
"edit_timestamp", "is_edited", "was_yesterday", "is_older_than_day",
|
"edit_timestamp", "is_edited", "timestamp", "priority", "tags",
|
||||||
"timestamp", "priority", "tags", "short_description", "string_datetime"
|
"short_description", "display_datetime"
|
||||||
)
|
)
|
||||||
|
23
apps/home/migrations/0003_auto_20240122_1323.py
Normal file
23
apps/home/migrations/0003_auto_20240122_1323.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 3.2.16 on 2024-01-22 13:23
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('home', '0002_auto_20240112_1604'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='ticketpriority',
|
||||||
|
name='order',
|
||||||
|
field=models.PositiveIntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='tickettag',
|
||||||
|
name='order',
|
||||||
|
field=models.PositiveIntegerField(default=0),
|
||||||
|
),
|
||||||
|
]
|
@ -19,6 +19,7 @@ class TicketPriority(models.Model):
|
|||||||
title = models.CharField(max_length=32)
|
title = models.CharField(max_length=32)
|
||||||
colour = models.CharField(max_length=7)
|
colour = models.CharField(max_length=7)
|
||||||
backgroundcolour = models.CharField(max_length=7)
|
backgroundcolour = models.CharField(max_length=7)
|
||||||
|
order = models.PositiveIntegerField(default=0, blank=False, null=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
@ -30,6 +31,7 @@ class TicketTag(models.Model):
|
|||||||
title = models.CharField(max_length=32)
|
title = models.CharField(max_length=32)
|
||||||
colour = models.CharField(max_length=7)
|
colour = models.CharField(max_length=7)
|
||||||
backgroundcolour = models.CharField(max_length=7)
|
backgroundcolour = models.CharField(max_length=7)
|
||||||
|
order = models.PositiveIntegerField(default=0, blank=False, null=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
@ -141,35 +143,7 @@ class Ticket(models.Model):
|
|||||||
return self.create_timestamp != self.edit_timestamp
|
return self.create_timestamp != self.edit_timestamp
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_older_than_day(self) -> bool:
|
def display_datetime(self) -> str:
|
||||||
"""Returns boolean dependent on if `self.timestamp` is older than 24 hours.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
bool
|
|
||||||
True if `self.timestamp` is older than 24 hours, False otherwise.
|
|
||||||
"""
|
|
||||||
|
|
||||||
dayago = timezone.now() - timedelta(hours=24)
|
|
||||||
return self.timestamp <= dayago
|
|
||||||
|
|
||||||
@property
|
|
||||||
def was_yesterday(self) -> bool:
|
|
||||||
"""Returns a boolean dependent on if `self.timestamp` is from before midnight yesterday.
|
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
bool
|
|
||||||
_description_
|
|
||||||
"""
|
|
||||||
|
|
||||||
now = timezone.now()
|
|
||||||
midnight_today = now - timedelta(hours=now.hour, minutes=now.minute, seconds=now.second, microseconds=now.microsecond)
|
|
||||||
|
|
||||||
return self.timestamp < midnight_today
|
|
||||||
|
|
||||||
@property
|
|
||||||
def string_datetime(self) -> str:
|
|
||||||
"""Provides a human readable string representation of `self.timestamp` that should be displayed
|
"""Provides a human readable string representation of `self.timestamp` that should be displayed
|
||||||
to represent the ticket's age.
|
to represent the ticket's age.
|
||||||
|
|
||||||
|
@ -29,15 +29,14 @@ class TicketView(TemplateView):
|
|||||||
|
|
||||||
@method_decorator(login_required)
|
@method_decorator(login_required)
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
priorities = TicketPriority.objects.all()
|
priorities = TicketPriority.objects.all().order_by("order")
|
||||||
tags = TicketTag.objects.all()
|
tags = TicketTag.objects.all().order_by("order")
|
||||||
departments = Department.objects.all()
|
departments = Department.objects.all()
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"priorities": priorities,
|
"priorities": priorities,
|
||||||
"tags": tags,
|
"tags": tags,
|
||||||
"departments": departments,
|
"departments": departments
|
||||||
"dayago": datetime.now() - timedelta(hours=24)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, "home/tickets.html", context)
|
return render(request, "home/tickets.html", context)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user