|
@@ -12,17 +12,16 @@ from django.utils import timezone
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
from rest_framework.utils.encoders import JSONEncoder
|
|
from rest_framework.utils.encoders import JSONEncoder
|
|
|
|
|
|
|
|
-from core.models import ObjectType
|
|
|
|
|
from extras.choices import *
|
|
from extras.choices import *
|
|
|
from extras.conditions import ConditionSet, InvalidCondition
|
|
from extras.conditions import ConditionSet, InvalidCondition
|
|
|
from extras.constants import *
|
|
from extras.constants import *
|
|
|
-from extras.utils import image_upload
|
|
|
|
|
from extras.models.mixins import RenderTemplateMixin
|
|
from extras.models.mixins import RenderTemplateMixin
|
|
|
|
|
+from extras.utils import image_upload
|
|
|
from netbox.config import get_config
|
|
from netbox.config import get_config
|
|
|
from netbox.events import get_event_type_choices
|
|
from netbox.events import get_event_type_choices
|
|
|
from netbox.models import ChangeLoggedModel
|
|
from netbox.models import ChangeLoggedModel
|
|
|
from netbox.models.features import (
|
|
from netbox.models.features import (
|
|
|
- CloningMixin, CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, SyncedDataMixin, TagsMixin
|
|
|
|
|
|
|
+ CloningMixin, CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, SyncedDataMixin, TagsMixin, has_feature
|
|
|
)
|
|
)
|
|
|
from utilities.html import clean_html
|
|
from utilities.html import clean_html
|
|
|
from utilities.jinja2 import render_jinja2
|
|
from utilities.jinja2 import render_jinja2
|
|
@@ -50,7 +49,7 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
|
|
|
webhook or executing a custom script.
|
|
webhook or executing a custom script.
|
|
|
"""
|
|
"""
|
|
|
object_types = models.ManyToManyField(
|
|
object_types = models.ManyToManyField(
|
|
|
- to='core.ObjectType',
|
|
|
|
|
|
|
+ to='contenttypes.ContentType',
|
|
|
related_name='event_rules',
|
|
related_name='event_rules',
|
|
|
verbose_name=_('object types'),
|
|
verbose_name=_('object types'),
|
|
|
help_text=_("The object(s) to which this rule applies.")
|
|
help_text=_("The object(s) to which this rule applies.")
|
|
@@ -299,7 +298,7 @@ class CustomLink(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|
|
code to be rendered with an object as context.
|
|
code to be rendered with an object as context.
|
|
|
"""
|
|
"""
|
|
|
object_types = models.ManyToManyField(
|
|
object_types = models.ManyToManyField(
|
|
|
- to='core.ObjectType',
|
|
|
|
|
|
|
+ to='contenttypes.ContentType',
|
|
|
related_name='custom_links',
|
|
related_name='custom_links',
|
|
|
help_text=_('The object type(s) to which this link applies.')
|
|
help_text=_('The object type(s) to which this link applies.')
|
|
|
)
|
|
)
|
|
@@ -395,7 +394,7 @@ class CustomLink(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|
|
|
|
|
|
|
class ExportTemplate(SyncedDataMixin, CloningMixin, ExportTemplatesMixin, ChangeLoggedModel, RenderTemplateMixin):
|
|
class ExportTemplate(SyncedDataMixin, CloningMixin, ExportTemplatesMixin, ChangeLoggedModel, RenderTemplateMixin):
|
|
|
object_types = models.ManyToManyField(
|
|
object_types = models.ManyToManyField(
|
|
|
- to='core.ObjectType',
|
|
|
|
|
|
|
+ to='contenttypes.ContentType',
|
|
|
related_name='export_templates',
|
|
related_name='export_templates',
|
|
|
help_text=_('The object type(s) to which this template applies.')
|
|
help_text=_('The object type(s) to which this template applies.')
|
|
|
)
|
|
)
|
|
@@ -460,7 +459,7 @@ class SavedFilter(CloningMixin, ExportTemplatesMixin, ChangeLoggedModel):
|
|
|
A set of predefined keyword parameters that can be reused to filter for specific objects.
|
|
A set of predefined keyword parameters that can be reused to filter for specific objects.
|
|
|
"""
|
|
"""
|
|
|
object_types = models.ManyToManyField(
|
|
object_types = models.ManyToManyField(
|
|
|
- to='core.ObjectType',
|
|
|
|
|
|
|
+ to='contenttypes.ContentType',
|
|
|
related_name='saved_filters',
|
|
related_name='saved_filters',
|
|
|
help_text=_('The object type(s) to which this filter applies.')
|
|
help_text=_('The object type(s) to which this filter applies.')
|
|
|
)
|
|
)
|
|
@@ -540,7 +539,7 @@ class TableConfig(CloningMixin, ChangeLoggedModel):
|
|
|
A saved configuration of columns and ordering which applies to a specific table.
|
|
A saved configuration of columns and ordering which applies to a specific table.
|
|
|
"""
|
|
"""
|
|
|
object_type = models.ForeignKey(
|
|
object_type = models.ForeignKey(
|
|
|
- to='core.ObjectType',
|
|
|
|
|
|
|
+ to='contenttypes.ContentType',
|
|
|
on_delete=models.CASCADE,
|
|
on_delete=models.CASCADE,
|
|
|
related_name='table_configs',
|
|
related_name='table_configs',
|
|
|
help_text=_("The table's object type"),
|
|
help_text=_("The table's object type"),
|
|
@@ -707,7 +706,7 @@ class ImageAttachment(ChangeLoggedModel):
|
|
|
super().clean()
|
|
super().clean()
|
|
|
|
|
|
|
|
# Validate the assigned object type
|
|
# Validate the assigned object type
|
|
|
- if self.object_type not in ObjectType.objects.with_feature('image_attachments'):
|
|
|
|
|
|
|
+ if not has_feature(self.object_type, 'image_attachments'):
|
|
|
raise ValidationError(
|
|
raise ValidationError(
|
|
|
_("Image attachments cannot be assigned to this object type ({type}).").format(type=self.object_type)
|
|
_("Image attachments cannot be assigned to this object type ({type}).").format(type=self.object_type)
|
|
|
)
|
|
)
|
|
@@ -807,7 +806,7 @@ class JournalEntry(CustomFieldsMixin, CustomLinksMixin, TagsMixin, ExportTemplat
|
|
|
super().clean()
|
|
super().clean()
|
|
|
|
|
|
|
|
# Validate the assigned object type
|
|
# Validate the assigned object type
|
|
|
- if self.assigned_object_type not in ObjectType.objects.with_feature('journaling'):
|
|
|
|
|
|
|
+ if not has_feature(self.assigned_object_type, 'journaling'):
|
|
|
raise ValidationError(
|
|
raise ValidationError(
|
|
|
_("Journaling is not supported for this object type ({type}).").format(type=self.assigned_object_type)
|
|
_("Journaling is not supported for this object type ({type}).").format(type=self.assigned_object_type)
|
|
|
)
|
|
)
|
|
@@ -863,7 +862,7 @@ class Bookmark(models.Model):
|
|
|
super().clean()
|
|
super().clean()
|
|
|
|
|
|
|
|
# Validate the assigned object type
|
|
# Validate the assigned object type
|
|
|
- if self.object_type not in ObjectType.objects.with_feature('bookmarks'):
|
|
|
|
|
|
|
+ if not has_feature(self.object_type, 'bookmarks'):
|
|
|
raise ValidationError(
|
|
raise ValidationError(
|
|
|
_("Bookmarks cannot be assigned to this object type ({type}).").format(type=self.object_type)
|
|
_("Bookmarks cannot be assigned to this object type ({type}).").format(type=self.object_type)
|
|
|
)
|
|
)
|