mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Rename ContentType proxy model to ObjectType
This commit is contained in:
parent
c6a3fc2407
commit
0df68bf291
@ -68,7 +68,7 @@ class JobFilterForm(SavedFiltersMixin, FilterForm):
|
|||||||
)
|
)
|
||||||
object_type = ContentTypeChoiceField(
|
object_type = ContentTypeChoiceField(
|
||||||
label=_('Object Type'),
|
label=_('Object Type'),
|
||||||
queryset=ContentType.objects.with_feature('jobs'),
|
queryset=ObjectType.objects.with_feature('jobs'),
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
status = forms.MultipleChoiceField(
|
status = forms.MultipleChoiceField(
|
||||||
|
@ -8,7 +8,7 @@ from django.conf import settings
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
|
|
||||||
APPS = ('circuits', 'core', 'dcim', 'extras', 'ipam', 'tenancy', 'users', 'virtualization', 'vpn', 'wireless')
|
APPS = ('circuits', 'core', 'dcim', 'extras', 'ipam', 'tenancy', 'users', 'virtualization', 'vpn', 'wireless')
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ class Command(BaseCommand):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Additional objects to include
|
# Additional objects to include
|
||||||
namespace['ContentType'] = ContentType
|
namespace['ObjectType'] = ObjectType
|
||||||
namespace['User'] = get_user_model()
|
namespace['User'] = get_user_model()
|
||||||
|
|
||||||
# Load convenience commands
|
# Load convenience commands
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# Generated by Django 4.2.6 on 2023-10-31 19:38
|
|
||||||
|
|
||||||
import core.models.contenttypes
|
import core.models.contenttypes
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
@ -13,7 +11,7 @@ class Migration(migrations.Migration):
|
|||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.CreateModel(
|
migrations.CreateModel(
|
||||||
name='ContentType',
|
name='ObjectType',
|
||||||
fields=[
|
fields=[
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
@ -23,7 +21,7 @@ class Migration(migrations.Migration):
|
|||||||
},
|
},
|
||||||
bases=('contenttypes.contenttype',),
|
bases=('contenttypes.contenttype',),
|
||||||
managers=[
|
managers=[
|
||||||
('objects', core.models.contenttypes.ContentTypeManager()),
|
('objects', core.models.contenttypes.ObjectTypeManager()),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
from django.contrib.contenttypes.models import ContentType as ContentType_, ContentTypeManager as ContentTypeManager_
|
from django.contrib.contenttypes.models import ContentType, ContentTypeManager
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
from netbox.registry import registry
|
from netbox.registry import registry
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ContentType',
|
'ObjectType',
|
||||||
'ContentTypeManager',
|
'ObjectTypeManager',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ContentTypeManager(ContentTypeManager_):
|
class ObjectTypeManager(ContentTypeManager):
|
||||||
|
|
||||||
def public(self):
|
def public(self):
|
||||||
"""
|
"""
|
||||||
@ -40,11 +40,11 @@ class ContentTypeManager(ContentTypeManager_):
|
|||||||
return self.get_queryset().filter(q)
|
return self.get_queryset().filter(q)
|
||||||
|
|
||||||
|
|
||||||
class ContentType(ContentType_):
|
class ObjectType(ContentType):
|
||||||
"""
|
"""
|
||||||
Wrap Django's native ContentType model to use our custom manager.
|
Wrap Django's native ContentType model to use our custom manager.
|
||||||
"""
|
"""
|
||||||
objects = ContentTypeManager()
|
objects = ObjectTypeManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
|
@ -11,7 +11,7 @@ from django.utils import timezone
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from core.choices import JobStatusChoices
|
from core.choices import JobStatusChoices
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from core.signals import job_end, job_start
|
from core.signals import job_end, job_start
|
||||||
from extras.constants import EVENT_JOB_END, EVENT_JOB_START
|
from extras.constants import EVENT_JOB_END, EVENT_JOB_START
|
||||||
from netbox.config import get_config
|
from netbox.config import get_config
|
||||||
@ -130,7 +130,7 @@ class Job(models.Model):
|
|||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
# Validate the assigned object type
|
# Validate the assigned object type
|
||||||
if self.object_type not in ContentType.objects.with_feature('jobs'):
|
if self.object_type not in ObjectType.objects.with_feature('jobs'):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Jobs cannot be assigned to this object type ({type}).").format(type=self.object_type)
|
_("Jobs cannot be assigned to this object type ({type}).").format(type=self.object_type)
|
||||||
)
|
)
|
||||||
@ -210,7 +210,7 @@ class Job(models.Model):
|
|||||||
schedule_at: Schedule the job to be executed at the passed date and time
|
schedule_at: Schedule the job to be executed at the passed date and time
|
||||||
interval: Recurrence interval (in minutes)
|
interval: Recurrence interval (in minutes)
|
||||||
"""
|
"""
|
||||||
object_type = ContentType.objects.get_for_model(instance, for_concrete_model=False)
|
object_type = ObjectType.objects.get_for_model(instance, for_concrete_model=False)
|
||||||
rq_queue_name = get_queue_for_model(object_type.model)
|
rq_queue_name = get_queue_for_model(object_type.model)
|
||||||
queue = django_rq.get_queue(rq_queue_name)
|
queue = django_rq.get_queue(rq_queue_name)
|
||||||
status = JobStatusChoices.STATUS_SCHEDULED if schedule_at else JobStatusChoices.STATUS_PENDING
|
status = JobStatusChoices.STATUS_SCHEDULED if schedule_at else JobStatusChoices.STATUS_PENDING
|
||||||
|
@ -9,7 +9,7 @@ from django.dispatch import Signal
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.constants import *
|
from dcim.constants import *
|
||||||
from dcim.fields import PathField
|
from dcim.fields import PathField
|
||||||
@ -481,13 +481,13 @@ class CablePath(models.Model):
|
|||||||
def origin_type(self):
|
def origin_type(self):
|
||||||
if self.path:
|
if self.path:
|
||||||
ct_id, _ = decompile_path_node(self.path[0][0])
|
ct_id, _ = decompile_path_node(self.path[0][0])
|
||||||
return ContentType.objects.get_for_id(ct_id)
|
return ObjectType.objects.get_for_id(ct_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def destination_type(self):
|
def destination_type(self):
|
||||||
if self.is_complete:
|
if self.is_complete:
|
||||||
ct_id, _ = decompile_path_node(self.path[-1][0])
|
ct_id, _ = decompile_path_node(self.path[-1][0])
|
||||||
return ContentType.objects.get_for_id(ct_id)
|
return ObjectType.objects.get_for_id(ct_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path_objects(self):
|
def path_objects(self):
|
||||||
@ -594,7 +594,7 @@ class CablePath(models.Model):
|
|||||||
|
|
||||||
# Step 6: Determine the far-end terminations
|
# Step 6: Determine the far-end terminations
|
||||||
if isinstance(links[0], Cable):
|
if isinstance(links[0], Cable):
|
||||||
termination_type = ContentType.objects.get_for_model(terminations[0])
|
termination_type = ObjectType.objects.get_for_model(terminations[0])
|
||||||
local_cable_terminations = CableTermination.objects.filter(
|
local_cable_terminations = CableTermination.objects.filter(
|
||||||
termination_type=termination_type,
|
termination_type=termination_type,
|
||||||
termination_id__in=[t.pk for t in terminations]
|
termination_id__in=[t.pk for t in terminations]
|
||||||
@ -747,7 +747,7 @@ class CablePath(models.Model):
|
|||||||
# Prefetch path objects using one query per model type. Prefetch related devices where appropriate.
|
# Prefetch path objects using one query per model type. Prefetch related devices where appropriate.
|
||||||
prefetched = {}
|
prefetched = {}
|
||||||
for ct_id, object_ids in to_prefetch.items():
|
for ct_id, object_ids in to_prefetch.items():
|
||||||
model_class = ContentType.objects.get_for_id(ct_id).model_class()
|
model_class = ObjectType.objects.get_for_id(ct_id).model_class()
|
||||||
queryset = model_class.objects.filter(pk__in=object_ids)
|
queryset = model_class.objects.filter(pk__in=object_ids)
|
||||||
if hasattr(model_class, 'device'):
|
if hasattr(model_class, 'device'):
|
||||||
queryset = queryset.prefetch_related('device')
|
queryset = queryset.prefetch_related('device')
|
||||||
@ -774,7 +774,7 @@ class CablePath(models.Model):
|
|||||||
"""
|
"""
|
||||||
Return all Cable IDs within the path.
|
Return all Cable IDs within the path.
|
||||||
"""
|
"""
|
||||||
cable_ct = ContentType.objects.get_for_model(Cable).pk
|
cable_ct = ObjectType.objects.get_for_model(Cable).pk
|
||||||
cable_ids = []
|
cable_ids = []
|
||||||
|
|
||||||
for node in self._nodes:
|
for node in self._nodes:
|
||||||
|
@ -7,7 +7,7 @@ from rest_framework import serializers
|
|||||||
|
|
||||||
from core.api.nested_serializers import NestedDataSourceSerializer, NestedDataFileSerializer, NestedJobSerializer
|
from core.api.nested_serializers import NestedDataSourceSerializer, NestedDataFileSerializer, NestedJobSerializer
|
||||||
from core.api.serializers import JobSerializer
|
from core.api.serializers import JobSerializer
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from dcim.api.nested_serializers import (
|
from dcim.api.nested_serializers import (
|
||||||
NestedDeviceRoleSerializer, NestedDeviceTypeSerializer, NestedLocationSerializer, NestedPlatformSerializer,
|
NestedDeviceRoleSerializer, NestedDeviceTypeSerializer, NestedLocationSerializer, NestedPlatformSerializer,
|
||||||
NestedRegionSerializer, NestedSiteSerializer, NestedSiteGroupSerializer,
|
NestedRegionSerializer, NestedSiteSerializer, NestedSiteGroupSerializer,
|
||||||
@ -60,12 +60,12 @@ __all__ = (
|
|||||||
class EventRuleSerializer(NetBoxModelSerializer):
|
class EventRuleSerializer(NetBoxModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:eventrule-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:eventrule-detail')
|
||||||
content_types = ContentTypeField(
|
content_types = ContentTypeField(
|
||||||
queryset=ContentType.objects.with_feature('event_rules'),
|
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||||
many=True
|
many=True
|
||||||
)
|
)
|
||||||
action_type = ChoiceField(choices=EventRuleActionChoices)
|
action_type = ChoiceField(choices=EventRuleActionChoices)
|
||||||
action_object_type = ContentTypeField(
|
action_object_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.with_feature('event_rules'),
|
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||||
)
|
)
|
||||||
action_object = serializers.SerializerMethodField(read_only=True)
|
action_object = serializers.SerializerMethodField(read_only=True)
|
||||||
|
|
||||||
@ -118,12 +118,12 @@ class WebhookSerializer(NetBoxModelSerializer):
|
|||||||
class CustomFieldSerializer(ValidatedModelSerializer):
|
class CustomFieldSerializer(ValidatedModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:customfield-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:customfield-detail')
|
||||||
content_types = ContentTypeField(
|
content_types = ContentTypeField(
|
||||||
queryset=ContentType.objects.with_feature('custom_fields'),
|
queryset=ObjectType.objects.with_feature('custom_fields'),
|
||||||
many=True
|
many=True
|
||||||
)
|
)
|
||||||
type = ChoiceField(choices=CustomFieldTypeChoices)
|
type = ChoiceField(choices=CustomFieldTypeChoices)
|
||||||
object_type = ContentTypeField(
|
object_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.all(),
|
queryset=ObjectType.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
allow_null=True
|
allow_null=True
|
||||||
)
|
)
|
||||||
@ -197,7 +197,7 @@ class CustomFieldChoiceSetSerializer(ValidatedModelSerializer):
|
|||||||
class CustomLinkSerializer(ValidatedModelSerializer):
|
class CustomLinkSerializer(ValidatedModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:customlink-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:customlink-detail')
|
||||||
content_types = ContentTypeField(
|
content_types = ContentTypeField(
|
||||||
queryset=ContentType.objects.with_feature('custom_links'),
|
queryset=ObjectType.objects.with_feature('custom_links'),
|
||||||
many=True
|
many=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ class CustomLinkSerializer(ValidatedModelSerializer):
|
|||||||
class ExportTemplateSerializer(ValidatedModelSerializer):
|
class ExportTemplateSerializer(ValidatedModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:exporttemplate-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:exporttemplate-detail')
|
||||||
content_types = ContentTypeField(
|
content_types = ContentTypeField(
|
||||||
queryset=ContentType.objects.with_feature('export_templates'),
|
queryset=ObjectType.objects.with_feature('export_templates'),
|
||||||
many=True
|
many=True
|
||||||
)
|
)
|
||||||
data_source = NestedDataSourceSerializer(
|
data_source = NestedDataSourceSerializer(
|
||||||
@ -244,7 +244,7 @@ class ExportTemplateSerializer(ValidatedModelSerializer):
|
|||||||
class SavedFilterSerializer(ValidatedModelSerializer):
|
class SavedFilterSerializer(ValidatedModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:savedfilter-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:savedfilter-detail')
|
||||||
content_types = ContentTypeField(
|
content_types = ContentTypeField(
|
||||||
queryset=ContentType.objects.all(),
|
queryset=ObjectType.objects.all(),
|
||||||
many=True
|
many=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ class SavedFilterSerializer(ValidatedModelSerializer):
|
|||||||
class BookmarkSerializer(ValidatedModelSerializer):
|
class BookmarkSerializer(ValidatedModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:bookmark-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:bookmark-detail')
|
||||||
object_type = ContentTypeField(
|
object_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.with_feature('bookmarks'),
|
queryset=ObjectType.objects.with_feature('bookmarks'),
|
||||||
)
|
)
|
||||||
object = serializers.SerializerMethodField(read_only=True)
|
object = serializers.SerializerMethodField(read_only=True)
|
||||||
user = NestedUserSerializer()
|
user = NestedUserSerializer()
|
||||||
@ -289,7 +289,7 @@ class BookmarkSerializer(ValidatedModelSerializer):
|
|||||||
class TagSerializer(ValidatedModelSerializer):
|
class TagSerializer(ValidatedModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:tag-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:tag-detail')
|
||||||
object_types = ContentTypeField(
|
object_types = ContentTypeField(
|
||||||
queryset=ContentType.objects.with_feature('tags'),
|
queryset=ObjectType.objects.with_feature('tags'),
|
||||||
many=True,
|
many=True,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
@ -313,7 +313,7 @@ class TagSerializer(ValidatedModelSerializer):
|
|||||||
class ImageAttachmentSerializer(ValidatedModelSerializer):
|
class ImageAttachmentSerializer(ValidatedModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:imageattachment-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:imageattachment-detail')
|
||||||
content_type = ContentTypeField(
|
content_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.all()
|
queryset=ObjectType.objects.all()
|
||||||
)
|
)
|
||||||
parent = serializers.SerializerMethodField(read_only=True)
|
parent = serializers.SerializerMethodField(read_only=True)
|
||||||
|
|
||||||
@ -353,7 +353,7 @@ class ImageAttachmentSerializer(ValidatedModelSerializer):
|
|||||||
class JournalEntrySerializer(NetBoxModelSerializer):
|
class JournalEntrySerializer(NetBoxModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:journalentry-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:journalentry-detail')
|
||||||
assigned_object_type = ContentTypeField(
|
assigned_object_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.all()
|
queryset=ObjectType.objects.all()
|
||||||
)
|
)
|
||||||
assigned_object = serializers.SerializerMethodField(read_only=True)
|
assigned_object = serializers.SerializerMethodField(read_only=True)
|
||||||
created_by = serializers.PrimaryKeyRelatedField(
|
created_by = serializers.PrimaryKeyRelatedField(
|
||||||
@ -645,7 +645,7 @@ class ContentTypeSerializer(BaseModelSerializer):
|
|||||||
url = serializers.HyperlinkedIdentityField(view_name='extras-api:contenttype-detail')
|
url = serializers.HyperlinkedIdentityField(view_name='extras-api:contenttype-detail')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ContentType
|
model = ObjectType
|
||||||
fields = ['id', 'url', 'display', 'app_label', 'model']
|
fields = ['id', 'url', 'display', 'app_label', 'model']
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ from django.template.loader import render_to_string
|
|||||||
from django.urls import NoReverseMatch, resolve, reverse
|
from django.urls import NoReverseMatch, resolve, reverse
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from extras.choices import BookmarkOrderingChoices
|
from extras.choices import BookmarkOrderingChoices
|
||||||
from utilities.choices import ButtonColorChoices
|
from utilities.choices import ButtonColorChoices
|
||||||
from utilities.permissions import get_permission_for_model
|
from utilities.permissions import get_permission_for_model
|
||||||
@ -34,14 +34,14 @@ __all__ = (
|
|||||||
def get_object_type_choices():
|
def get_object_type_choices():
|
||||||
return [
|
return [
|
||||||
(content_type_identifier(ct), content_type_name(ct))
|
(content_type_identifier(ct), content_type_name(ct))
|
||||||
for ct in ContentType.objects.public().order_by('app_label', 'model')
|
for ct in ObjectType.objects.public().order_by('app_label', 'model')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_bookmarks_object_type_choices():
|
def get_bookmarks_object_type_choices():
|
||||||
return [
|
return [
|
||||||
(content_type_identifier(ct), content_type_name(ct))
|
(content_type_identifier(ct), content_type_name(ct))
|
||||||
for ct in ContentType.objects.with_feature('bookmarks').order_by('app_label', 'model')
|
for ct in ObjectType.objects.with_feature('bookmarks').order_by('app_label', 'model')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ def get_models_from_content_types(content_types):
|
|||||||
models = []
|
models = []
|
||||||
for content_type_id in content_types:
|
for content_type_id in content_types:
|
||||||
app_label, model_name = content_type_id.split('.')
|
app_label, model_name = content_type_id.split('.')
|
||||||
content_type = ContentType.objects.get_by_natural_key(app_label, model_name)
|
content_type = ObjectType.objects.get_by_natural_key(app_label, model_name)
|
||||||
models.append(content_type.model_class())
|
models.append(content_type.model_class())
|
||||||
return models
|
return models
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ class ObjectListWidget(DashboardWidget):
|
|||||||
|
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
app_label, model_name = self.config['model'].split('.')
|
app_label, model_name = self.config['model'].split('.')
|
||||||
model = ContentType.objects.get_by_natural_key(app_label, model_name).model_class()
|
model = ObjectType.objects.get_by_natural_key(app_label, model_name).model_class()
|
||||||
viewname = get_viewname(model, action='list')
|
viewname = get_viewname(model, action='list')
|
||||||
|
|
||||||
# Evaluate user's permission. Note that this controls only whether the HTMX element is
|
# Evaluate user's permission. Note that this controls only whether the HTMX element is
|
||||||
@ -371,7 +371,7 @@ class BookmarksWidget(DashboardWidget):
|
|||||||
bookmarks = Bookmark.objects.filter(user=request.user).order_by(self.config['order_by'])
|
bookmarks = Bookmark.objects.filter(user=request.user).order_by(self.config['order_by'])
|
||||||
if object_types := self.config.get('object_types'):
|
if object_types := self.config.get('object_types'):
|
||||||
models = get_models_from_content_types(object_types)
|
models = get_models_from_content_types(object_types)
|
||||||
conent_types = ContentType.objects.get_for_models(*models).values()
|
conent_types = ObjectType.objects.get_for_models(*models).values()
|
||||||
bookmarks = bookmarks.filter(object_type__in=conent_types)
|
bookmarks = bookmarks.filter(object_type__in=conent_types)
|
||||||
if max_items := self.config.get('max_items'):
|
if max_items := self.config.get('max_items'):
|
||||||
bookmarks = bookmarks[:max_items]
|
bookmarks = bookmarks[:max_items]
|
||||||
|
@ -6,7 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist
|
|||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.models import *
|
from extras.models import *
|
||||||
from netbox.forms import NetBoxModelImportForm
|
from netbox.forms import NetBoxModelImportForm
|
||||||
@ -32,7 +32,7 @@ __all__ = (
|
|||||||
class CustomFieldImportForm(CSVModelForm):
|
class CustomFieldImportForm(CSVModelForm):
|
||||||
content_types = CSVMultipleContentTypeField(
|
content_types = CSVMultipleContentTypeField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('custom_fields'),
|
queryset=ObjectType.objects.with_feature('custom_fields'),
|
||||||
help_text=_("One or more assigned object types")
|
help_text=_("One or more assigned object types")
|
||||||
)
|
)
|
||||||
type = CSVChoiceField(
|
type = CSVChoiceField(
|
||||||
@ -42,7 +42,7 @@ class CustomFieldImportForm(CSVModelForm):
|
|||||||
)
|
)
|
||||||
object_type = CSVContentTypeField(
|
object_type = CSVContentTypeField(
|
||||||
label=_('Object type'),
|
label=_('Object type'),
|
||||||
queryset=ContentType.objects.public(),
|
queryset=ObjectType.objects.public(),
|
||||||
required=False,
|
required=False,
|
||||||
help_text=_("Object type (for object or multi-object fields)")
|
help_text=_("Object type (for object or multi-object fields)")
|
||||||
)
|
)
|
||||||
@ -113,7 +113,7 @@ class CustomFieldChoiceSetImportForm(CSVModelForm):
|
|||||||
class CustomLinkImportForm(CSVModelForm):
|
class CustomLinkImportForm(CSVModelForm):
|
||||||
content_types = CSVMultipleContentTypeField(
|
content_types = CSVMultipleContentTypeField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('custom_links'),
|
queryset=ObjectType.objects.with_feature('custom_links'),
|
||||||
help_text=_("One or more assigned object types")
|
help_text=_("One or more assigned object types")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ class CustomLinkImportForm(CSVModelForm):
|
|||||||
class ExportTemplateImportForm(CSVModelForm):
|
class ExportTemplateImportForm(CSVModelForm):
|
||||||
content_types = CSVMultipleContentTypeField(
|
content_types = CSVMultipleContentTypeField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('export_templates'),
|
queryset=ObjectType.objects.with_feature('export_templates'),
|
||||||
help_text=_("One or more assigned object types")
|
help_text=_("One or more assigned object types")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ class ConfigTemplateImportForm(CSVModelForm):
|
|||||||
class SavedFilterImportForm(CSVModelForm):
|
class SavedFilterImportForm(CSVModelForm):
|
||||||
content_types = CSVMultipleContentTypeField(
|
content_types = CSVMultipleContentTypeField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.all(),
|
queryset=ObjectType.objects.all(),
|
||||||
help_text=_("One or more assigned object types")
|
help_text=_("One or more assigned object types")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ class WebhookImportForm(NetBoxModelImportForm):
|
|||||||
class EventRuleImportForm(NetBoxModelImportForm):
|
class EventRuleImportForm(NetBoxModelImportForm):
|
||||||
content_types = CSVMultipleContentTypeField(
|
content_types = CSVMultipleContentTypeField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('event_rules'),
|
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||||
help_text=_("One or more assigned object types")
|
help_text=_("One or more assigned object types")
|
||||||
)
|
)
|
||||||
action_object = forms.CharField(
|
action_object = forms.CharField(
|
||||||
@ -213,7 +213,7 @@ class EventRuleImportForm(NetBoxModelImportForm):
|
|||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
raise forms.ValidationError(_("Script {name} not found").format(name=action_object))
|
raise forms.ValidationError(_("Script {name} not found").format(name=action_object))
|
||||||
self.instance.action_object = script
|
self.instance.action_object = script
|
||||||
self.instance.action_object_type = ContentType.objects.get_for_model(script, for_concrete_model=False)
|
self.instance.action_object_type = ObjectType.objects.get_for_model(script, for_concrete_model=False)
|
||||||
|
|
||||||
|
|
||||||
class TagImportForm(CSVModelForm):
|
class TagImportForm(CSVModelForm):
|
||||||
@ -229,7 +229,7 @@ class TagImportForm(CSVModelForm):
|
|||||||
|
|
||||||
class JournalEntryImportForm(NetBoxModelImportForm):
|
class JournalEntryImportForm(NetBoxModelImportForm):
|
||||||
assigned_object_type = CSVContentTypeField(
|
assigned_object_type = CSVContentTypeField(
|
||||||
queryset=ContentType.objects.all(),
|
queryset=ObjectType.objects.all(),
|
||||||
label=_('Assigned object type'),
|
label=_('Assigned object type'),
|
||||||
)
|
)
|
||||||
kind = CSVChoiceField(
|
kind = CSVChoiceField(
|
||||||
|
@ -2,7 +2,7 @@ from django import forms
|
|||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType, DataFile, DataSource
|
from core.models import ObjectType, DataFile, DataSource
|
||||||
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.models import *
|
from extras.models import *
|
||||||
@ -43,7 +43,7 @@ class CustomFieldFilterForm(SavedFiltersMixin, FilterForm):
|
|||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
content_type_id = ContentTypeMultipleChoiceField(
|
content_type_id = ContentTypeMultipleChoiceField(
|
||||||
queryset=ContentType.objects.with_feature('custom_fields'),
|
queryset=ObjectType.objects.with_feature('custom_fields'),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Object type')
|
label=_('Object type')
|
||||||
)
|
)
|
||||||
@ -112,7 +112,7 @@ class CustomLinkFilterForm(SavedFiltersMixin, FilterForm):
|
|||||||
)
|
)
|
||||||
content_types = ContentTypeMultipleChoiceField(
|
content_types = ContentTypeMultipleChoiceField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('custom_links'),
|
queryset=ObjectType.objects.with_feature('custom_links'),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
enabled = forms.NullBooleanField(
|
enabled = forms.NullBooleanField(
|
||||||
@ -155,7 +155,7 @@ class ExportTemplateFilterForm(SavedFiltersMixin, FilterForm):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
content_type_id = ContentTypeMultipleChoiceField(
|
content_type_id = ContentTypeMultipleChoiceField(
|
||||||
queryset=ContentType.objects.with_feature('export_templates'),
|
queryset=ObjectType.objects.with_feature('export_templates'),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Content types')
|
label=_('Content types')
|
||||||
)
|
)
|
||||||
@ -183,7 +183,7 @@ class ImageAttachmentFilterForm(SavedFiltersMixin, FilterForm):
|
|||||||
)
|
)
|
||||||
content_type_id = ContentTypeChoiceField(
|
content_type_id = ContentTypeChoiceField(
|
||||||
label=_('Content type'),
|
label=_('Content type'),
|
||||||
queryset=ContentType.objects.with_feature('image_attachments'),
|
queryset=ObjectType.objects.with_feature('image_attachments'),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
name = forms.CharField(
|
name = forms.CharField(
|
||||||
@ -199,7 +199,7 @@ class SavedFilterFilterForm(SavedFiltersMixin, FilterForm):
|
|||||||
)
|
)
|
||||||
content_types = ContentTypeMultipleChoiceField(
|
content_types = ContentTypeMultipleChoiceField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.public(),
|
queryset=ObjectType.objects.public(),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
enabled = forms.NullBooleanField(
|
enabled = forms.NullBooleanField(
|
||||||
@ -254,7 +254,7 @@ class EventRuleFilterForm(NetBoxModelFilterSetForm):
|
|||||||
(_('Events'), ('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end')),
|
(_('Events'), ('type_create', 'type_update', 'type_delete', 'type_job_start', 'type_job_end')),
|
||||||
)
|
)
|
||||||
content_type_id = ContentTypeMultipleChoiceField(
|
content_type_id = ContentTypeMultipleChoiceField(
|
||||||
queryset=ContentType.objects.with_feature('event_rules'),
|
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Object type')
|
label=_('Object type')
|
||||||
)
|
)
|
||||||
@ -310,12 +310,12 @@ class EventRuleFilterForm(NetBoxModelFilterSetForm):
|
|||||||
class TagFilterForm(SavedFiltersMixin, FilterForm):
|
class TagFilterForm(SavedFiltersMixin, FilterForm):
|
||||||
model = Tag
|
model = Tag
|
||||||
content_type_id = ContentTypeMultipleChoiceField(
|
content_type_id = ContentTypeMultipleChoiceField(
|
||||||
queryset=ContentType.objects.with_feature('tags'),
|
queryset=ObjectType.objects.with_feature('tags'),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Tagged object type')
|
label=_('Tagged object type')
|
||||||
)
|
)
|
||||||
for_object_type_id = ContentTypeChoiceField(
|
for_object_type_id = ContentTypeChoiceField(
|
||||||
queryset=ContentType.objects.with_feature('tags'),
|
queryset=ObjectType.objects.with_feature('tags'),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Allowed object type')
|
label=_('Allowed object type')
|
||||||
)
|
)
|
||||||
@ -464,7 +464,7 @@ class JournalEntryFilterForm(NetBoxModelFilterSetForm):
|
|||||||
label=_('User')
|
label=_('User')
|
||||||
)
|
)
|
||||||
assigned_object_type_id = DynamicModelMultipleChoiceField(
|
assigned_object_type_id = DynamicModelMultipleChoiceField(
|
||||||
queryset=ContentType.objects.all(),
|
queryset=ObjectType.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Object Type'),
|
label=_('Object Type'),
|
||||||
widget=APISelectMultiple(
|
widget=APISelectMultiple(
|
||||||
@ -507,7 +507,7 @@ class ObjectChangeFilterForm(SavedFiltersMixin, FilterForm):
|
|||||||
label=_('User')
|
label=_('User')
|
||||||
)
|
)
|
||||||
changed_object_type_id = DynamicModelMultipleChoiceField(
|
changed_object_type_id = DynamicModelMultipleChoiceField(
|
||||||
queryset=ContentType.objects.all(),
|
queryset=ObjectType.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Object Type'),
|
label=_('Object Type'),
|
||||||
widget=APISelectMultiple(
|
widget=APISelectMultiple(
|
||||||
|
@ -7,7 +7,7 @@ from django.utils.safestring import mark_safe
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.forms.mixins import SyncedDataMixin
|
from core.forms.mixins import SyncedDataMixin
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.models import *
|
from extras.models import *
|
||||||
@ -41,11 +41,11 @@ __all__ = (
|
|||||||
class CustomFieldForm(forms.ModelForm):
|
class CustomFieldForm(forms.ModelForm):
|
||||||
content_types = ContentTypeMultipleChoiceField(
|
content_types = ContentTypeMultipleChoiceField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('custom_fields')
|
queryset=ObjectType.objects.with_feature('custom_fields')
|
||||||
)
|
)
|
||||||
object_type = ContentTypeChoiceField(
|
object_type = ContentTypeChoiceField(
|
||||||
label=_('Object type'),
|
label=_('Object type'),
|
||||||
queryset=ContentType.objects.public(),
|
queryset=ObjectType.objects.public(),
|
||||||
required=False,
|
required=False,
|
||||||
help_text=_("Type of the related object (for object/multi-object fields only)")
|
help_text=_("Type of the related object (for object/multi-object fields only)")
|
||||||
)
|
)
|
||||||
@ -125,7 +125,7 @@ class CustomFieldChoiceSetForm(forms.ModelForm):
|
|||||||
class CustomLinkForm(forms.ModelForm):
|
class CustomLinkForm(forms.ModelForm):
|
||||||
content_types = ContentTypeMultipleChoiceField(
|
content_types = ContentTypeMultipleChoiceField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('custom_links')
|
queryset=ObjectType.objects.with_feature('custom_links')
|
||||||
)
|
)
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
@ -154,7 +154,7 @@ class CustomLinkForm(forms.ModelForm):
|
|||||||
class ExportTemplateForm(SyncedDataMixin, forms.ModelForm):
|
class ExportTemplateForm(SyncedDataMixin, forms.ModelForm):
|
||||||
content_types = ContentTypeMultipleChoiceField(
|
content_types = ContentTypeMultipleChoiceField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('export_templates')
|
queryset=ObjectType.objects.with_feature('export_templates')
|
||||||
)
|
)
|
||||||
template_code = forms.CharField(
|
template_code = forms.CharField(
|
||||||
label=_('Template code'),
|
label=_('Template code'),
|
||||||
@ -195,7 +195,7 @@ class SavedFilterForm(forms.ModelForm):
|
|||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
content_types = ContentTypeMultipleChoiceField(
|
content_types = ContentTypeMultipleChoiceField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.all()
|
queryset=ObjectType.objects.all()
|
||||||
)
|
)
|
||||||
parameters = JSONField()
|
parameters = JSONField()
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ class SavedFilterForm(forms.ModelForm):
|
|||||||
class BookmarkForm(forms.ModelForm):
|
class BookmarkForm(forms.ModelForm):
|
||||||
object_type = ContentTypeChoiceField(
|
object_type = ContentTypeChoiceField(
|
||||||
label=_('Object type'),
|
label=_('Object type'),
|
||||||
queryset=ContentType.objects.with_feature('bookmarks')
|
queryset=ObjectType.objects.with_feature('bookmarks')
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -251,7 +251,7 @@ class WebhookForm(NetBoxModelForm):
|
|||||||
class EventRuleForm(NetBoxModelForm):
|
class EventRuleForm(NetBoxModelForm):
|
||||||
content_types = ContentTypeMultipleChoiceField(
|
content_types = ContentTypeMultipleChoiceField(
|
||||||
label=_('Content types'),
|
label=_('Content types'),
|
||||||
queryset=ContentType.objects.with_feature('event_rules'),
|
queryset=ObjectType.objects.with_feature('event_rules'),
|
||||||
)
|
)
|
||||||
action_choice = forms.ChoiceField(
|
action_choice = forms.ChoiceField(
|
||||||
label=_('Action choice'),
|
label=_('Action choice'),
|
||||||
@ -339,11 +339,11 @@ class EventRuleForm(NetBoxModelForm):
|
|||||||
action_choice = self.cleaned_data.get('action_choice')
|
action_choice = self.cleaned_data.get('action_choice')
|
||||||
# Webhook
|
# Webhook
|
||||||
if self.cleaned_data.get('action_type') == EventRuleActionChoices.WEBHOOK:
|
if self.cleaned_data.get('action_type') == EventRuleActionChoices.WEBHOOK:
|
||||||
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(action_choice)
|
self.cleaned_data['action_object_type'] = ObjectType.objects.get_for_model(action_choice)
|
||||||
self.cleaned_data['action_object_id'] = action_choice.id
|
self.cleaned_data['action_object_id'] = action_choice.id
|
||||||
# Script
|
# Script
|
||||||
elif self.cleaned_data.get('action_type') == EventRuleActionChoices.SCRIPT:
|
elif self.cleaned_data.get('action_type') == EventRuleActionChoices.SCRIPT:
|
||||||
self.cleaned_data['action_object_type'] = ContentType.objects.get_for_model(
|
self.cleaned_data['action_object_type'] = ObjectType.objects.get_for_model(
|
||||||
Script,
|
Script,
|
||||||
for_concrete_model=False
|
for_concrete_model=False
|
||||||
)
|
)
|
||||||
@ -356,7 +356,7 @@ class TagForm(forms.ModelForm):
|
|||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
object_types = ContentTypeMultipleChoiceField(
|
object_types = ContentTypeMultipleChoiceField(
|
||||||
label=_('Object types'),
|
label=_('Object types'),
|
||||||
queryset=ContentType.objects.with_feature('tags'),
|
queryset=ObjectType.objects.with_feature('tags'),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from django.db import models
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from ..querysets import ObjectChangeQuerySet
|
from ..querysets import ObjectChangeQuerySet
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ class ObjectChange(models.Model):
|
|||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
# Validate the assigned object type
|
# Validate the assigned object type
|
||||||
if self.changed_object_type not in ContentType.objects.with_feature('change_logging'):
|
if self.changed_object_type not in ObjectType.objects.with_feature('change_logging'):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Change logging is not supported for this object type ({type}).").format(
|
_("Change logging is not supported for this object type ({type}).").format(
|
||||||
type=self.changed_object_type
|
type=self.changed_object_type
|
||||||
|
@ -12,7 +12,7 @@ from django.urls import reverse
|
|||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.data import CHOICE_SETS
|
from extras.data import CHOICE_SETS
|
||||||
from netbox.models import ChangeLoggedModel
|
from netbox.models import ChangeLoggedModel
|
||||||
@ -52,7 +52,7 @@ class CustomFieldManager(models.Manager.from_queryset(RestrictedQuerySet)):
|
|||||||
"""
|
"""
|
||||||
Return all CustomFields assigned to the given model.
|
Return all CustomFields assigned to the given model.
|
||||||
"""
|
"""
|
||||||
content_type = ContentType.objects.get_for_model(model._meta.concrete_model)
|
content_type = ObjectType.objects.get_for_model(model._meta.concrete_model)
|
||||||
return self.get_queryset().filter(content_types=content_type)
|
return self.get_queryset().filter(content_types=content_type)
|
||||||
|
|
||||||
def get_defaults_for_model(self, model):
|
def get_defaults_for_model(self, model):
|
||||||
|
@ -12,7 +12,7 @@ from django.utils.formats import date_format
|
|||||||
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 ContentType
|
from core.models import ObjectType
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.conditions import ConditionSet
|
from extras.conditions import ConditionSet
|
||||||
from extras.constants import *
|
from extras.constants import *
|
||||||
@ -646,7 +646,7 @@ class ImageAttachment(ChangeLoggedModel):
|
|||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
# Validate the assigned object type
|
# Validate the assigned object type
|
||||||
if self.content_type not in ContentType.objects.with_feature('image_attachments'):
|
if self.content_type not in ObjectType.objects.with_feature('image_attachments'):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Image attachments cannot be assigned to this object type ({type}).").format(type=self.content_type)
|
_("Image attachments cannot be assigned to this object type ({type}).").format(type=self.content_type)
|
||||||
)
|
)
|
||||||
@ -739,7 +739,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 ContentType.objects.with_feature('journaling'):
|
if self.assigned_object_type not in ObjectType.objects.with_feature('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)
|
||||||
)
|
)
|
||||||
@ -795,7 +795,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 ContentType.objects.with_feature('bookmarks'):
|
if self.object_type not in ObjectType.objects.with_feature('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)
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,7 @@ from django.urls import reverse
|
|||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from ipam.choices import *
|
from ipam.choices import *
|
||||||
from ipam.constants import *
|
from ipam.constants import *
|
||||||
from ipam.fields import IPNetworkField, IPAddressField
|
from ipam.fields import IPNetworkField, IPAddressField
|
||||||
@ -861,7 +861,7 @@ class IPAddress(PrimaryModel):
|
|||||||
|
|
||||||
if self._original_assigned_object_id and self._original_assigned_object_type_id:
|
if self._original_assigned_object_id and self._original_assigned_object_type_id:
|
||||||
parent = getattr(self.assigned_object, 'parent_object', None)
|
parent = getattr(self.assigned_object, 'parent_object', None)
|
||||||
ct = ContentType.objects.get_for_id(self._original_assigned_object_type_id)
|
ct = ObjectType.objects.get_for_id(self._original_assigned_object_type_id)
|
||||||
original_assigned_object = ct.get_object_for_this_type(pk=self._original_assigned_object_id)
|
original_assigned_object = ct.get_object_for_this_type(pk=self._original_assigned_object_id)
|
||||||
original_parent = getattr(original_assigned_object, 'parent_object', None)
|
original_parent = getattr(original_assigned_object, 'parent_object', None)
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from taggit.managers import TaggableManager
|
from taggit.managers import TaggableManager
|
||||||
|
|
||||||
from core.choices import JobStatusChoices
|
from core.choices import JobStatusChoices
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.utils import is_taggable
|
from extras.utils import is_taggable
|
||||||
from netbox.config import get_config
|
from netbox.config import get_config
|
||||||
@ -490,7 +490,7 @@ class SyncedDataMixin(models.Model):
|
|||||||
ret = super().save(*args, **kwargs)
|
ret = super().save(*args, **kwargs)
|
||||||
|
|
||||||
# Create/delete AutoSyncRecord as needed
|
# Create/delete AutoSyncRecord as needed
|
||||||
content_type = ContentType.objects.get_for_model(self)
|
content_type = ObjectType.objects.get_for_model(self)
|
||||||
if self.auto_sync_enabled:
|
if self.auto_sync_enabled:
|
||||||
AutoSyncRecord.objects.update_or_create(
|
AutoSyncRecord.objects.update_or_create(
|
||||||
object_type=content_type,
|
object_type=content_type,
|
||||||
@ -510,7 +510,7 @@ class SyncedDataMixin(models.Model):
|
|||||||
from core.models import AutoSyncRecord
|
from core.models import AutoSyncRecord
|
||||||
|
|
||||||
# Delete AutoSyncRecord
|
# Delete AutoSyncRecord
|
||||||
content_type = ContentType.objects.get_for_model(self)
|
content_type = ObjectType.objects.get_for_model(self)
|
||||||
AutoSyncRecord.objects.filter(
|
AutoSyncRecord.objects.filter(
|
||||||
datafile=self.data_file,
|
datafile=self.data_file,
|
||||||
object_type=content_type,
|
object_type=content_type,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from netbox.forms import NetBoxModelFilterSetForm
|
from netbox.forms import NetBoxModelFilterSetForm
|
||||||
from tenancy.choices import *
|
from tenancy.choices import *
|
||||||
from tenancy.models import *
|
from tenancy.models import *
|
||||||
@ -86,7 +86,7 @@ class ContactAssignmentFilterForm(NetBoxModelFilterSetForm):
|
|||||||
(_('Assignment'), ('content_type_id', 'group_id', 'contact_id', 'role_id', 'priority')),
|
(_('Assignment'), ('content_type_id', 'group_id', 'contact_id', 'role_id', 'priority')),
|
||||||
)
|
)
|
||||||
content_type_id = ContentTypeMultipleChoiceField(
|
content_type_id = ContentTypeMultipleChoiceField(
|
||||||
queryset=ContentType.objects.with_feature('contacts'),
|
queryset=ObjectType.objects.with_feature('contacts'),
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Object type')
|
label=_('Object type')
|
||||||
)
|
)
|
||||||
|
@ -4,7 +4,7 @@ from django.db import models
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel
|
from netbox.models import ChangeLoggedModel, NestedGroupModel, OrganizationalModel, PrimaryModel
|
||||||
from netbox.models.features import CustomFieldsMixin, ExportTemplatesMixin, TagsMixin
|
from netbox.models.features import CustomFieldsMixin, ExportTemplatesMixin, TagsMixin
|
||||||
from tenancy.choices import *
|
from tenancy.choices import *
|
||||||
@ -165,7 +165,7 @@ class ContactAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, Chan
|
|||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
# Validate the assigned object type
|
# Validate the assigned object type
|
||||||
if self.content_type not in ContentType.objects.with_feature('contacts'):
|
if self.content_type not in ObjectType.objects.with_feature('contacts'):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Contacts cannot be assigned to this object type ({type}).").format(type=self.content_type)
|
_("Contacts cannot be assigned to this object type ({type}).").format(type=self.content_type)
|
||||||
)
|
)
|
||||||
|
@ -22,7 +22,7 @@ from django.utils import timezone
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from ipam.fields import IPNetworkField
|
from ipam.fields import IPNetworkField
|
||||||
from netbox.config import get_config
|
from netbox.config import get_config
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
|
@ -5,7 +5,7 @@ from django.urls import reverse
|
|||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from core.models import ContentType
|
from core.models import ObjectType
|
||||||
from netbox.models import NetBoxModel, PrimaryModel
|
from netbox.models import NetBoxModel, PrimaryModel
|
||||||
from netbox.models.features import ContactsMixin
|
from netbox.models.features import ContactsMixin
|
||||||
from vpn.choices import L2VPNTypeChoices
|
from vpn.choices import L2VPNTypeChoices
|
||||||
@ -128,7 +128,7 @@ class L2VPNTermination(NetBoxModel):
|
|||||||
# Only check is assigned_object is set. Required otherwise we have an Integrity Error thrown.
|
# Only check is assigned_object is set. Required otherwise we have an Integrity Error thrown.
|
||||||
if self.assigned_object:
|
if self.assigned_object:
|
||||||
obj_id = self.assigned_object.pk
|
obj_id = self.assigned_object.pk
|
||||||
obj_type = ContentType.objects.get_for_model(self.assigned_object)
|
obj_type = ObjectType.objects.get_for_model(self.assigned_object)
|
||||||
if L2VPNTermination.objects.filter(assigned_object_id=obj_id, assigned_object_type=obj_type).\
|
if L2VPNTermination.objects.filter(assigned_object_id=obj_id, assigned_object_type=obj_type).\
|
||||||
exclude(pk=self.pk).count() > 0:
|
exclude(pk=self.pk).count() > 0:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
@ -150,7 +150,7 @@ class L2VPNTermination(NetBoxModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def assigned_object_parent(self):
|
def assigned_object_parent(self):
|
||||||
obj_type = ContentType.objects.get_for_model(self.assigned_object)
|
obj_type = ObjectType.objects.get_for_model(self.assigned_object)
|
||||||
if obj_type.model == 'vminterface':
|
if obj_type.model == 'vminterface':
|
||||||
return self.assigned_object.virtual_machine
|
return self.assigned_object.virtual_machine
|
||||||
elif obj_type.model == 'interface':
|
elif obj_type.model == 'interface':
|
||||||
|
Loading…
Reference in New Issue
Block a user