|
@@ -9,6 +9,7 @@ from mptt.models import MPTTModel, TreeForeignKey
|
|
|
from taggit.managers import TaggableManager
|
|
from taggit.managers import TaggableManager
|
|
|
|
|
|
|
|
from extras.choices import ObjectChangeActionChoices
|
|
from extras.choices import ObjectChangeActionChoices
|
|
|
|
|
+from netbox.signals import post_clean
|
|
|
from utilities.mptt import TreeManager
|
|
from utilities.mptt import TreeManager
|
|
|
from utilities.utils import serialize_object
|
|
from utilities.utils import serialize_object
|
|
|
|
|
|
|
@@ -123,6 +124,20 @@ class CustomFieldsMixin(models.Model):
|
|
|
raise ValidationError(f"Missing required custom field '{cf.name}'.")
|
|
raise ValidationError(f"Missing required custom field '{cf.name}'.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+class CustomValidationMixin(models.Model):
|
|
|
|
|
+ """
|
|
|
|
|
+ Enables user-configured validation rules for built-in models by extending the clean() method.
|
|
|
|
|
+ """
|
|
|
|
|
+ class Meta:
|
|
|
|
|
+ abstract = True
|
|
|
|
|
+
|
|
|
|
|
+ def clean(self):
|
|
|
|
|
+ super().clean()
|
|
|
|
|
+
|
|
|
|
|
+ # Send the post_clean signal
|
|
|
|
|
+ post_clean.send(sender=self.__class__, instance=self)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
#
|
|
#
|
|
|
# Base model classes
|
|
# Base model classes
|
|
|
|
|
|
|
@@ -138,7 +153,7 @@ class BigIDModel(models.Model):
|
|
|
abstract = True
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
|
-class ChangeLoggedModel(ChangeLoggingMixin, BigIDModel):
|
|
|
|
|
|
|
+class ChangeLoggedModel(ChangeLoggingMixin, CustomValidationMixin, BigIDModel):
|
|
|
"""
|
|
"""
|
|
|
Base model for all objects which support change logging.
|
|
Base model for all objects which support change logging.
|
|
|
"""
|
|
"""
|
|
@@ -146,7 +161,7 @@ class ChangeLoggedModel(ChangeLoggingMixin, BigIDModel):
|
|
|
abstract = True
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
|
-class PrimaryModel(ChangeLoggingMixin, CustomFieldsMixin, BigIDModel):
|
|
|
|
|
|
|
+class PrimaryModel(ChangeLoggingMixin, CustomFieldsMixin, CustomValidationMixin, BigIDModel):
|
|
|
"""
|
|
"""
|
|
|
Primary models represent real objects within the infrastructure being modeled.
|
|
Primary models represent real objects within the infrastructure being modeled.
|
|
|
"""
|
|
"""
|
|
@@ -163,7 +178,7 @@ class PrimaryModel(ChangeLoggingMixin, CustomFieldsMixin, BigIDModel):
|
|
|
abstract = True
|
|
abstract = True
|
|
|
|
|
|
|
|
|
|
|
|
|
-class NestedGroupModel(ChangeLoggingMixin, CustomFieldsMixin, BigIDModel, MPTTModel):
|
|
|
|
|
|
|
+class NestedGroupModel(ChangeLoggingMixin, CustomFieldsMixin, CustomValidationMixin, BigIDModel, MPTTModel):
|
|
|
"""
|
|
"""
|
|
|
Base model for objects which are used to form a hierarchy (regions, locations, etc.). These models nest
|
|
Base model for objects which are used to form a hierarchy (regions, locations, etc.). These models nest
|
|
|
recursively using MPTT. Within each parent, each child instance must have a unique name.
|
|
recursively using MPTT. Within each parent, each child instance must have a unique name.
|
|
@@ -205,7 +220,7 @@ class NestedGroupModel(ChangeLoggingMixin, CustomFieldsMixin, BigIDModel, MPTTMo
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
-class OrganizationalModel(ChangeLoggingMixin, CustomFieldsMixin, BigIDModel):
|
|
|
|
|
|
|
+class OrganizationalModel(ChangeLoggingMixin, CustomFieldsMixin, CustomValidationMixin, BigIDModel):
|
|
|
"""
|
|
"""
|
|
|
Organizational models are those which are used solely to categorize and qualify other objects, and do not convey
|
|
Organizational models are those which are used solely to categorize and qualify other objects, and do not convey
|
|
|
any real information about the infrastructure being modeled (for example, functional device roles). Organizational
|
|
any real information about the infrastructure being modeled (for example, functional device roles). Organizational
|