refactor(core): Switch to inherit from Centurion model for model TicketBase
ref: #870 #861
This commit is contained in:
@ -0,0 +1,41 @@
|
|||||||
|
# Generated by Django 5.1.10 on 2025-07-13 13:22
|
||||||
|
|
||||||
|
import access.models.tenancy_abstract
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("access", "0021_roleaudithistory_rolecenturionmodelnote"),
|
||||||
|
("core", "0033_alter_ticketcommentcategory_parent_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="ticketbase",
|
||||||
|
name="id",
|
||||||
|
field=models.AutoField(
|
||||||
|
help_text="ID of the item",
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
unique=True,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="ticketbase",
|
||||||
|
name="organization",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
help_text="Tenant this belongs to",
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
related_name="+",
|
||||||
|
to="access.tenant",
|
||||||
|
validators=[
|
||||||
|
access.models.tenancy_abstract.TenancyAbstractModel.validatate_organization_exists
|
||||||
|
],
|
||||||
|
verbose_name="Tenant",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -8,15 +8,15 @@ from django.db import models
|
|||||||
|
|
||||||
from rest_framework.reverse import reverse
|
from rest_framework.reverse import reverse
|
||||||
|
|
||||||
from access.fields import AutoCreatedField, AutoLastModifiedField
|
from access.fields import AutoLastModifiedField
|
||||||
from access.models.entity import Entity
|
from access.models.entity import Entity
|
||||||
from access.models.tenancy import TenancyObject
|
|
||||||
|
|
||||||
from core import exceptions as centurion_exceptions
|
from core import exceptions as centurion_exceptions
|
||||||
from core.classes.badge import Badge
|
from core.classes.badge import Badge
|
||||||
from core.lib.feature_not_used import FeatureNotUsed
|
from core.lib.feature_not_used import FeatureNotUsed
|
||||||
from core.lib.slash_commands import SlashCommands
|
from core.lib.slash_commands import SlashCommands
|
||||||
from core.middleware.get_request import get_request
|
from core.middleware.get_request import get_request
|
||||||
|
from core.models.centurion import CenturionModel
|
||||||
from core.models.ticket.ticket_category import TicketCategory
|
from core.models.ticket.ticket_category import TicketCategory
|
||||||
from core.models.ticket.ticket_enum_values import TicketValues
|
from core.models.ticket.ticket_enum_values import TicketValues
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ User = django.contrib.auth.get_user_model()
|
|||||||
|
|
||||||
class TicketBase(
|
class TicketBase(
|
||||||
SlashCommands,
|
SlashCommands,
|
||||||
TenancyObject,
|
CenturionModel,
|
||||||
):
|
):
|
||||||
|
|
||||||
_after: dict
|
_after: dict
|
||||||
@ -36,11 +36,17 @@ class TicketBase(
|
|||||||
Data after save was called
|
Data after save was called
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_audit_enabled = False
|
||||||
|
|
||||||
_before: dict
|
_before: dict
|
||||||
"""History Before
|
"""History Before
|
||||||
Data before save was called
|
Data before save was called
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_notes_enabled = False
|
||||||
|
|
||||||
|
model_notes = None
|
||||||
|
|
||||||
save_model_history: bool = False
|
save_model_history: bool = False
|
||||||
|
|
||||||
class Ticket_ExternalSystem(models.IntegerChoices): # <null|github|gitlab>
|
class Ticket_ExternalSystem(models.IntegerChoices): # <null|github|gitlab>
|
||||||
@ -141,15 +147,6 @@ class TicketBase(
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
id = models.AutoField(
|
|
||||||
blank = False,
|
|
||||||
help_text = 'Ticket ID Number',
|
|
||||||
primary_key = True,
|
|
||||||
unique = True,
|
|
||||||
verbose_name = 'Number',
|
|
||||||
)
|
|
||||||
|
|
||||||
external_system = models.IntegerField(
|
external_system = models.IntegerField(
|
||||||
blank = True,
|
blank = True,
|
||||||
choices = Ticket_ExternalSystem,
|
choices = Ticket_ExternalSystem,
|
||||||
@ -176,10 +173,6 @@ class TicketBase(
|
|||||||
verbose_name = 'Parent Ticket'
|
verbose_name = 'Parent Ticket'
|
||||||
)
|
)
|
||||||
|
|
||||||
model_notes = None
|
|
||||||
|
|
||||||
is_global = None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def get_ticket_type(self):
|
def get_ticket_type(self):
|
||||||
"""Fetch the Ticket Type
|
"""Fetch the Ticket Type
|
||||||
@ -542,10 +535,6 @@ class TicketBase(
|
|||||||
verbose_name = 'Closed Date',
|
verbose_name = 'Closed Date',
|
||||||
)
|
)
|
||||||
|
|
||||||
created = AutoCreatedField(
|
|
||||||
editable = True,
|
|
||||||
)
|
|
||||||
|
|
||||||
modified = AutoLastModifiedField()
|
modified = AutoLastModifiedField()
|
||||||
|
|
||||||
|
|
||||||
@ -670,11 +659,36 @@ class TicketBase(
|
|||||||
|
|
||||||
self.date_closed = datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0).isoformat()
|
self.date_closed = datetime.datetime.now(tz=datetime.timezone.utc).replace(microsecond=0).isoformat()
|
||||||
|
|
||||||
|
|
||||||
if self.date_closed is not None and not self.is_closed:
|
if self.date_closed is not None and not self.is_closed:
|
||||||
|
|
||||||
self.date_closed = None
|
self.date_closed = None
|
||||||
|
|
||||||
|
|
||||||
|
self._before = {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
self._before = self.__class__.objects.get(pk=self.pk).__dict__.copy()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def clean_fields(self, exclude = None):
|
||||||
|
|
||||||
|
if(
|
||||||
|
self.description != ''
|
||||||
|
and self.description is not None
|
||||||
|
):
|
||||||
|
|
||||||
|
description = self.slash_command(self.description)
|
||||||
|
|
||||||
|
if description != self.description:
|
||||||
|
|
||||||
|
self.description = description
|
||||||
|
|
||||||
|
|
||||||
|
return super().clean_fields(exclude = exclude)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -761,7 +775,6 @@ class TicketBase(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_related_field_name(self) -> str:
|
def get_related_field_name(self) -> str:
|
||||||
|
|
||||||
meta = getattr(self, '_meta')
|
meta = getattr(self, '_meta')
|
||||||
@ -836,9 +849,9 @@ class TicketBase(
|
|||||||
|
|
||||||
if request:
|
if request:
|
||||||
|
|
||||||
return reverse(f"v2:_api_v2_ticket_sub-detail", request=request, kwargs = kwargs )
|
return reverse(f"v2:_api_ticket_sub-detail", request=request, kwargs = kwargs )
|
||||||
|
|
||||||
return reverse(f"v2:_api_v2_ticket_sub-detail", kwargs = kwargs )
|
return reverse(f"v2:_api_ticket_sub-detail", kwargs = kwargs )
|
||||||
|
|
||||||
|
|
||||||
def get_url_kwargs(self) -> dict:
|
def get_url_kwargs(self) -> dict:
|
||||||
@ -1122,26 +1135,6 @@ class TicketBase(
|
|||||||
|
|
||||||
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
|
||||||
|
|
||||||
|
|
||||||
if(
|
|
||||||
self.description != ''
|
|
||||||
and self.description is not None
|
|
||||||
):
|
|
||||||
|
|
||||||
description = self.slash_command(self.description)
|
|
||||||
|
|
||||||
if description != self.description:
|
|
||||||
|
|
||||||
self.description = description
|
|
||||||
|
|
||||||
|
|
||||||
self._before = {}
|
|
||||||
|
|
||||||
try:
|
|
||||||
self._before = self.__class__.objects.get(pk=self.pk).__dict__.copy()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
super().save(force_insert=force_insert, force_update=force_update, using=using, update_fields=update_fields)
|
super().save(force_insert=force_insert, force_update=force_update, using=using, update_fields=update_fields)
|
||||||
|
|
||||||
self._after = self.__dict__.copy()
|
self._after = self.__dict__.copy()
|
||||||
@ -1149,4 +1142,3 @@ class TicketBase(
|
|||||||
if self._before:
|
if self._before:
|
||||||
|
|
||||||
self.create_action_comment()
|
self.create_action_comment()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user