Skip to content

Commit 0c2b6b6

Browse files
authored
Merge branch 'main' into docs
2 parents 1e3cc2f + 86f3ed6 commit 0c2b6b6

File tree

7 files changed

+52
-239
lines changed

7 files changed

+52
-239
lines changed

netbox_custom_objects/LICENSE.md

Lines changed: 0 additions & 164 deletions
This file was deleted.

netbox_custom_objects/__init__.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,42 @@
11
from netbox.plugins import PluginConfig
2-
from django.apps import apps
2+
33

44
# Plugin Configuration
55
class CustomObjectsPluginConfig(PluginConfig):
66
name = "netbox_custom_objects"
77
verbose_name = "Custom Objects"
88
description = "A plugin to manage custom objects in NetBox"
9-
version = "0.1"
9+
version = "0.1.0"
1010
base_url = "custom-objects"
1111
min_version = "4.2.0"
12-
# max_version = "3.5.0"
1312
default_settings = {}
1413
required_settings = []
1514
template_extensions = "template_content.template_extensions"
1615

17-
'''
18-
def get_model(self, model_name, require_ready=True):
19-
if require_ready:
20-
self.apps.check_models_ready()
21-
else:
22-
self.apps.check_apps_ready()
23-
24-
if model_name.lower() in self.models:
25-
return self.models[model_name.lower()]
26-
27-
from .models import CustomObjectType
28-
if "table" not in model_name.lower() or "model" not in model_name.lower():
29-
raise LookupError(
30-
"App '%s' doesn't have a '%s' model." % (self.label, model_name)
31-
)
32-
33-
custom_object_type_id = int(model_name.replace("table", "").replace("model", ""))
34-
35-
try:
36-
obj = CustomObjectType.objects.get(pk=custom_object_type_id)
37-
except CustomObjectType.DoesNotExist:
38-
raise LookupError(
39-
"App '%s' doesn't have a '%s' model." % (self.label, model_name)
40-
)
41-
return obj.get_model()
42-
43-
def ready(self):
44-
super().ready()
45-
'''
16+
# def get_model(self, model_name, require_ready=True):
17+
# if require_ready:
18+
# self.apps.check_models_ready()
19+
# else:
20+
# self.apps.check_apps_ready()
21+
#
22+
# if model_name.lower() in self.models:
23+
# return self.models[model_name.lower()]
24+
#
25+
# from .models import CustomObjectType
26+
# if "table" not in model_name.lower() or "model" not in model_name.lower():
27+
# raise LookupError(
28+
# "App '%s' doesn't have a '%s' model." % (self.label, model_name)
29+
# )
30+
#
31+
# custom_object_type_id = int(model_name.replace("table", "").replace("model", ""))
32+
#
33+
# try:
34+
# obj = CustomObjectType.objects.get(pk=custom_object_type_id)
35+
# except CustomObjectType.DoesNotExist:
36+
# raise LookupError(
37+
# "App '%s' doesn't have a '%s' model." % (self.label, model_name)
38+
# )
39+
# return obj.get_model()
4640

4741

4842
config = CustomObjectsPluginConfig

netbox_custom_objects/forms.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
import json
2-
31
from django import forms
42
from django.utils.translation import gettext_lazy as _
5-
from extras.choices import CustomFieldTypeChoices, CustomFieldUIEditableChoices
3+
from extras.choices import CustomFieldTypeChoices
64
from extras.forms import CustomFieldForm
75
from netbox.forms import NetBoxModelForm
8-
from utilities.forms.fields import (CommentField, ContentTypeChoiceField,
9-
DynamicModelChoiceField)
6+
from utilities.forms.fields import CommentField, ContentTypeChoiceField, DynamicModelChoiceField
107
from utilities.forms.rendering import FieldSet
118
from utilities.object_types import object_type_name
129

1310
from netbox_custom_objects.constants import APP_LABEL
14-
from netbox_custom_objects.models import (CustomObjectObjectType,
15-
CustomObjectType,
16-
CustomObjectTypeField)
11+
from netbox_custom_objects.models import CustomObjectObjectType, CustomObjectType, CustomObjectTypeField
1712

1813
__all__ = (
1914
"CustomObjectTypeForm",

netbox_custom_objects/models.py

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,36 @@
11
import decimal
2-
import json
32
import re
43
import uuid
54
from datetime import date, datetime
65

76
import django_filters
87
from core.models.contenttypes import ObjectTypeManager
9-
from django import forms
108
from django.apps import apps
119
from django.conf import settings
1210
from django.contrib.contenttypes.management import create_contenttypes
1311
from django.contrib.contenttypes.models import ContentType
1412
from django.core.validators import RegexValidator, ValidationError
1513
from django.db import connection, models
16-
from django.db.models import F, Func, Q, Value
17-
from django.db.models.expressions import RawSQL
14+
from django.db.models import Q
1815
from django.db.models.functions import Lower
1916
from django.urls import reverse
20-
from django.utils.html import escape
21-
from django.utils.safestring import mark_safe
2217
from django.utils.translation import gettext_lazy as _
23-
from extras.choices import (CustomFieldFilterLogicChoices,
24-
CustomFieldTypeChoices,
25-
CustomFieldUIEditableChoices,
26-
CustomFieldUIVisibleChoices)
27-
from extras.constants import CUSTOMFIELD_EMPTY_VALUES
28-
# from .choices import MappingFieldTypeChoices
18+
from extras.choices import (
19+
CustomFieldFilterLogicChoices, CustomFieldTypeChoices, CustomFieldUIEditableChoices, CustomFieldUIVisibleChoices,
20+
)
2921
from extras.models.customfields import SEARCH_TYPES
3022
from netbox.models import ChangeLoggedModel, NetBoxModel
31-
from netbox.models.features import (BookmarksMixin, ChangeLoggingMixin,
32-
CloningMixin,
33-
CustomLinksMixin, CustomValidationMixin,
34-
EventRulesMixin, ExportTemplatesMixin,
35-
JournalingMixin, NotificationsMixin,
36-
TagsMixin)
23+
# from netbox.models.features import (
24+
# BookmarksMixin, ChangeLoggingMixin, CloningMixin, CustomLinksMixin, CustomValidationMixin, EventRulesMixin,
25+
# ExportTemplatesMixin, JournalingMixin, NotificationsMixin, TagsMixin,
26+
# )
27+
from netbox.models.features import CloningMixin, ExportTemplatesMixin, TagsMixin
3728
from netbox.registry import registry
3829
from utilities import filters
3930
from utilities.datetime import datetime_from_timestamp
40-
from utilities.forms.fields import (CSVChoiceField, CSVModelChoiceField,
41-
CSVModelMultipleChoiceField,
42-
CSVMultipleChoiceField, DynamicChoiceField,
43-
DynamicModelChoiceField,
44-
DynamicModelMultipleChoiceField,
45-
DynamicMultipleChoiceField, JSONField,
46-
LaxURLField)
47-
from utilities.forms.utils import add_blank_choice
48-
from utilities.forms.widgets import (APISelect, APISelectMultiple, DatePicker,
49-
DateTimePicker)
5031
from utilities.object_types import object_type_name
5132
from utilities.querysets import RestrictedQuerySet
5233
from utilities.string import title
53-
from utilities.templatetags.builtins.filters import render_markdown
5434
from utilities.validators import validate_regex
5535

5636
from netbox_custom_objects.constants import APP_LABEL
@@ -59,6 +39,7 @@
5939

6040
USER_TABLE_DATABASE_NAME_PREFIX = "custom_objects_"
6141

42+
6243
class CustomObject(
6344
# BookmarksMixin,
6445
# ChangeLoggingMixin,

netbox_custom_objects/navigation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_menu():
5555
(_("Object Types"), (custom_object_type_plugin_menu_item,)),
5656
(_("Objects"), tuple(menu_items)),
5757
),
58-
icon_class="mdi mdi-source-branch",
58+
icon_class="mdi mdi-toy-brick-outline",
5959
)
6060

6161

@@ -64,7 +64,7 @@ def get_menu():
6464
menu = PluginMenu(
6565
label="Custom Objects",
6666
groups=((_("Object Types"), (custom_object_type_plugin_menu_item,)),),
67-
icon_class="mdi mdi-source-branch",
67+
icon_class="mdi mdi-toy-brick-outline",
6868
)
6969
else:
7070
menu = get_menu

netbox_custom_objects/views.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ def get(self, request, *args, **kwargs):
170170
**self.get_extra_context(request, obj),
171171
})
172172

173-
174173
def _get_dependent_objects(self, obj):
175174
dependent_objects = super()._get_dependent_objects(obj)
176175
model = obj.custom_object_type.get_model()
@@ -347,13 +346,11 @@ def get_form(self, model):
347346
print(f"get_form: {field.name} field is not supported")
348347

349348
# Add an __init__ method to handle the tags field widget override
350-
from django.forms.widgets import HiddenInput
351-
352349
def __init__(self, *args, **kwargs):
353350
forms.NetBoxModelForm.__init__(self, *args, **kwargs)
354351
if 'tags' in self.fields:
355352
del self.fields["tags"]
356-
353+
357354
attrs['__init__'] = __init__
358355

359356
form = type(

ruff.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
line-length = 120
2+
target-version = "py310"
3+
4+
[lint]
5+
extend-select = ["E1", "E2", "E3", "E501", "W"]
6+
ignore = ["F403", "F405"]
7+
preview = true
8+
9+
[format]
10+
quote-style = "single"

0 commit comments

Comments
 (0)