Преглед на файлове

Move choice sets from utilities.choices to netbox.choices

Jeremy Stretch преди 1 година
родител
ревизия
a9bb4c5c3e

+ 1 - 1
docs/plugins/development/navigation.md

@@ -49,8 +49,8 @@ menu_items = (item1, item2, item3)
 Each menu item represents a link and (optionally) a set of buttons comprising one entry in NetBox's navigation menu. Menu items are defined as PluginMenuItem instances. An example is shown below.
 
 ```python title="navigation.py"
+from netbox.choices import ButtonColorChoices
 from netbox.plugins import PluginMenuButton, PluginMenuItem
-from utilities.choices import ButtonColorChoices
 
 item1 = PluginMenuItem(
     link='plugins:myplugin:myview',

+ 1 - 1
netbox/dcim/filtersets.py

@@ -10,12 +10,12 @@ from extras.filtersets import LocalConfigContextFilterSet
 from extras.models import ConfigTemplate
 from ipam.filtersets import PrimaryIPFilterSet
 from ipam.models import ASN, IPAddress, VRF
+from netbox.choices import ColorChoices
 from netbox.filtersets import (
     BaseFilterSet, ChangeLoggedModelFilterSet, OrganizationalModelFilterSet, NetBoxModelFilterSet,
 )
 from tenancy.filtersets import TenancyFilterSet, ContactModelFilterSet
 from tenancy.models import *
-from utilities.choices import ColorChoices
 from utilities.filters import (
     ContentTypeFilter, MultiValueCharFilter, MultiValueMACAddressFilter, MultiValueNumberFilter, MultiValueWWNFilter,
     NumericArrayFilter, TreeNodeMultipleChoiceFilter,

+ 1 - 1
netbox/dcim/models/device_components.py

@@ -12,8 +12,8 @@ from mptt.models import MPTTModel, TreeForeignKey
 from dcim.choices import *
 from dcim.constants import *
 from dcim.fields import MACAddressField, WWNField
+from netbox.choices import ColorChoices
 from netbox.models import OrganizationalModel, NetBoxModel
-from utilities.choices import ColorChoices
 from utilities.fields import ColorField, NaturalOrderingField
 from utilities.mptt import TreeManager
 from utilities.ordering import naturalize_interface

+ 1 - 1
netbox/dcim/models/devices.py

@@ -18,10 +18,10 @@ from dcim.choices import *
 from dcim.constants import *
 from extras.models import ConfigContextModel, CustomField
 from extras.querysets import ConfigContextModelQuerySet
+from netbox.choices import ColorChoices
 from netbox.config import ConfigItem
 from netbox.models import OrganizationalModel, PrimaryModel
 from netbox.models.features import ContactsMixin, ImageAttachmentsMixin
-from utilities.choices import ColorChoices
 from utilities.fields import ColorField, CounterCacheField, NaturalOrderingField
 from utilities.tracking import TrackingModelMixin
 from .device_components import *

+ 1 - 1
netbox/dcim/models/racks.py

@@ -14,9 +14,9 @@ from django.utils.translation import gettext_lazy as _
 from dcim.choices import *
 from dcim.constants import *
 from dcim.svg import RackElevationSVG
+from netbox.choices import ColorChoices
 from netbox.models import OrganizationalModel, PrimaryModel
 from netbox.models.features import ContactsMixin, ImageAttachmentsMixin
-from utilities.choices import ColorChoices
 from utilities.fields import ColorField, NaturalOrderingField
 from utilities.utils import array_to_string, drange, to_grams
 from .device_components import PowerPort

+ 1 - 2
netbox/dcim/tests/test_filtersets.py

@@ -6,13 +6,12 @@ from dcim.choices import *
 from dcim.filtersets import *
 from dcim.models import *
 from ipam.models import ASN, IPAddress, RIR, VRF
+from netbox.choices import ColorChoices
 from tenancy.models import Tenant, TenantGroup
-from utilities.choices import ColorChoices
 from utilities.testing import ChangeLoggedFilterSetTests, create_test_device
 from virtualization.models import Cluster, ClusterType
 from wireless.choices import WirelessChannelChoices, WirelessRoleChoices
 
-
 User = get_user_model()
 
 

+ 1 - 2
netbox/dcim/tests/test_views.py

@@ -11,12 +11,11 @@ from dcim.choices import *
 from dcim.constants import *
 from dcim.models import *
 from ipam.models import ASN, RIR, VLAN, VRF
+from netbox.choices import CSVDelimiterChoices, ImportFormatChoices
 from tenancy.models import Tenant
-from utilities.choices import CSVDelimiterChoices, ImportFormatChoices
 from utilities.testing import ViewTestCases, create_tags, create_test_device, post_data
 from wireless.models import WirelessLAN
 
-
 User = get_user_model()
 
 

+ 2 - 1
netbox/extras/choices.py

@@ -2,7 +2,8 @@ import logging
 
 from django.utils.translation import gettext_lazy as _
 
-from utilities.choices import ButtonColorChoices, ChoiceSet
+from netbox.choices import ButtonColorChoices
+from utilities.choices import ChoiceSet
 
 
 #

+ 1 - 1
netbox/extras/dashboard/widgets.py

@@ -14,7 +14,7 @@ from django.utils.translation import gettext as _
 
 from core.models import ObjectType
 from extras.choices import BookmarkOrderingChoices
-from utilities.choices import ButtonColorChoices
+from netbox.choices import ButtonColorChoices
 from utilities.permissions import get_permission_for_model
 from utilities.templatetags.builtins.filters import render_markdown
 from utilities.utils import content_type_identifier, content_type_name, dict_to_querydict, get_viewname

+ 1 - 1
netbox/extras/models/tags.py

@@ -5,9 +5,9 @@ from django.utils.text import slugify
 from django.utils.translation import gettext_lazy as _
 from taggit.models import TagBase, GenericTaggedItemBase
 
+from netbox.choices import ColorChoices
 from netbox.models import ChangeLoggedModel
 from netbox.models.features import CloningMixin, ExportTemplatesMixin
-from utilities.choices import ColorChoices
 from utilities.fields import ColorField
 
 __all__ = (

+ 1 - 1
netbox/extras/tests/test_custom_validation.py

@@ -5,7 +5,7 @@ from circuits.api.serializers import ProviderSerializer
 from circuits.forms import ProviderForm
 from circuits.models import Provider
 from ipam.models import ASN, RIR
-from utilities.choices import CSVDelimiterChoices, ImportFormatChoices
+from netbox.choices import CSVDelimiterChoices, ImportFormatChoices
 from utilities.testing import APITestCase, ModelViewTestCase, create_tags, post_data
 
 

+ 1 - 1
netbox/extras/tests/test_customfields.py

@@ -12,7 +12,7 @@ from dcim.models import Manufacturer, Rack, Site
 from extras.choices import *
 from extras.models import CustomField, CustomFieldChoiceSet
 from ipam.models import VLAN
-from utilities.choices import CSVDelimiterChoices, ImportFormatChoices
+from netbox.choices import CSVDelimiterChoices, ImportFormatChoices
 from utilities.testing import APITestCase, TestCase
 from virtualization.models import VirtualMachine
 

+ 162 - 0
netbox/netbox/choices.py

@@ -0,0 +1,162 @@
+from django.utils.translation import gettext_lazy as _
+
+from utilities.choices import ChoiceSet
+from utilities.constants import CSV_DELIMITERS
+
+__all__ = (
+    'ButtonColorChoices',
+    'ColorChoices',
+    'CSVDelimiterChoices',
+    'ImportFormatChoices',
+    'ImportMethodChoices',
+)
+
+
+#
+# Generic color choices
+#
+
+class ColorChoices(ChoiceSet):
+    COLOR_DARK_RED = 'aa1409'
+    COLOR_RED = 'f44336'
+    COLOR_PINK = 'e91e63'
+    COLOR_ROSE = 'ffe4e1'
+    COLOR_FUCHSIA = 'ff66ff'
+    COLOR_PURPLE = '9c27b0'
+    COLOR_DARK_PURPLE = '673ab7'
+    COLOR_INDIGO = '3f51b5'
+    COLOR_BLUE = '2196f3'
+    COLOR_LIGHT_BLUE = '03a9f4'
+    COLOR_CYAN = '00bcd4'
+    COLOR_TEAL = '009688'
+    COLOR_AQUA = '00ffff'
+    COLOR_DARK_GREEN = '2f6a31'
+    COLOR_GREEN = '4caf50'
+    COLOR_LIGHT_GREEN = '8bc34a'
+    COLOR_LIME = 'cddc39'
+    COLOR_YELLOW = 'ffeb3b'
+    COLOR_AMBER = 'ffc107'
+    COLOR_ORANGE = 'ff9800'
+    COLOR_DARK_ORANGE = 'ff5722'
+    COLOR_BROWN = '795548'
+    COLOR_LIGHT_GREY = 'c0c0c0'
+    COLOR_GREY = '9e9e9e'
+    COLOR_DARK_GREY = '607d8b'
+    COLOR_BLACK = '111111'
+    COLOR_WHITE = 'ffffff'
+
+    CHOICES = (
+        (COLOR_DARK_RED, _('Dark Red')),
+        (COLOR_RED, _('Red')),
+        (COLOR_PINK, _('Pink')),
+        (COLOR_ROSE, _('Rose')),
+        (COLOR_FUCHSIA, _('Fuchsia')),
+        (COLOR_PURPLE, _('Purple')),
+        (COLOR_DARK_PURPLE, _('Dark Purple')),
+        (COLOR_INDIGO, _('Indigo')),
+        (COLOR_BLUE, _('Blue')),
+        (COLOR_LIGHT_BLUE, _('Light Blue')),
+        (COLOR_CYAN, _('Cyan')),
+        (COLOR_TEAL, _('Teal')),
+        (COLOR_AQUA, _('Aqua')),
+        (COLOR_DARK_GREEN, _('Dark Green')),
+        (COLOR_GREEN, _('Green')),
+        (COLOR_LIGHT_GREEN, _('Light Green')),
+        (COLOR_LIME, _('Lime')),
+        (COLOR_YELLOW, _('Yellow')),
+        (COLOR_AMBER, _('Amber')),
+        (COLOR_ORANGE, _('Orange')),
+        (COLOR_DARK_ORANGE, _('Dark Orange')),
+        (COLOR_BROWN, _('Brown')),
+        (COLOR_LIGHT_GREY, _('Light Grey')),
+        (COLOR_GREY, _('Grey')),
+        (COLOR_DARK_GREY, _('Dark Grey')),
+        (COLOR_BLACK, _('Black')),
+        (COLOR_WHITE, _('White')),
+    )
+
+
+#
+# Button color choices
+#
+
+class ButtonColorChoices(ChoiceSet):
+    """
+    Map standard button color choices to Bootstrap 3 button classes
+    """
+    DEFAULT = 'outline-dark'
+    BLUE = 'blue'
+    INDIGO = 'indigo'
+    PURPLE = 'purple'
+    PINK = 'pink'
+    RED = 'red'
+    ORANGE = 'orange'
+    YELLOW = 'yellow'
+    GREEN = 'green'
+    TEAL = 'teal'
+    CYAN = 'cyan'
+    GRAY = 'gray'
+    GREY = 'gray'  # Backward compatability for <3.2
+    BLACK = 'black'
+    WHITE = 'white'
+
+    CHOICES = (
+        (DEFAULT, _('Default')),
+        (BLUE, _('Blue')),
+        (INDIGO, _('Indigo')),
+        (PURPLE, _('Purple')),
+        (PINK, _('Pink')),
+        (RED, _('Red')),
+        (ORANGE, _('Orange')),
+        (YELLOW, _('Yellow')),
+        (GREEN, _('Green')),
+        (TEAL, _('Teal')),
+        (CYAN, _('Cyan')),
+        (GRAY, _('Gray')),
+        (BLACK, _('Black')),
+        (WHITE, _('White')),
+    )
+
+
+#
+# Import Choices
+#
+
+class ImportMethodChoices(ChoiceSet):
+    DIRECT = 'direct'
+    UPLOAD = 'upload'
+    DATA_FILE = 'datafile'
+
+    CHOICES = [
+        (DIRECT, _('Direct')),
+        (UPLOAD, _('Upload')),
+        (DATA_FILE, _('Data file')),
+    ]
+
+
+class ImportFormatChoices(ChoiceSet):
+    AUTO = 'auto'
+    CSV = 'csv'
+    JSON = 'json'
+    YAML = 'yaml'
+
+    CHOICES = [
+        (AUTO, _('Auto-detect')),
+        (CSV, 'CSV'),
+        (JSON, 'JSON'),
+        (YAML, 'YAML'),
+    ]
+
+
+class CSVDelimiterChoices(ChoiceSet):
+    AUTO = 'auto'
+    COMMA = CSV_DELIMITERS['comma']
+    SEMICOLON = CSV_DELIMITERS['semicolon']
+    TAB = CSV_DELIMITERS['tab']
+
+    CHOICES = [
+        (AUTO, _('Auto-detect')),
+        (COMMA, _('Comma')),
+        (SEMICOLON, _('Semicolon')),
+        (TAB, _('Tab')),
+    ]

+ 0 - 2
netbox/netbox/navigation/__init__.py

@@ -1,8 +1,6 @@
 from dataclasses import dataclass
 from typing import Sequence, Optional
 
-from utilities.choices import ButtonColorChoices
-
 
 __all__ = (
     'get_model_item',

+ 0 - 1
netbox/netbox/navigation/menu.py

@@ -1,7 +1,6 @@
 from django.utils.translation import gettext_lazy as _
 
 from netbox.registry import registry
-from utilities.choices import ButtonColorChoices
 from . import *
 
 #

+ 3 - 2
netbox/netbox/plugins/navigation.py

@@ -1,8 +1,9 @@
-from netbox.navigation import MenuGroup
-from utilities.choices import ButtonColorChoices
 from django.utils.text import slugify
 from django.utils.translation import gettext as _
 
+from netbox.choices import ButtonColorChoices
+from netbox.navigation import MenuGroup
+
 __all__ = (
     'PluginMenu',
     'PluginMenuButton',

+ 1 - 1
netbox/netbox/tests/test_import.py

@@ -2,8 +2,8 @@ from django.test import override_settings
 
 from core.models import ObjectType
 from dcim.models import *
+from netbox.choices import CSVDelimiterChoices, ImportFormatChoices
 from users.models import ObjectPermission
-from utilities.choices import CSVDelimiterChoices, ImportFormatChoices
 from utilities.testing import ModelViewTestCase, create_tags
 
 

+ 4 - 151
netbox/utilities/choices.py

@@ -1,7 +1,10 @@
 from django.conf import settings
 from django.utils.translation import gettext_lazy as _
 
-from .constants import CSV_DELIMITERS
+__all__ = (
+    'ChoiceSet',
+    'unpack_grouped_choices',
+)
 
 
 class ChoiceSetMeta(type):
@@ -96,153 +99,3 @@ def unpack_grouped_choices(choices):
         else:
             unpacked_choices.append((key, value))
     return unpacked_choices
-
-
-#
-# Generic color choices
-#
-
-class ColorChoices(ChoiceSet):
-    COLOR_DARK_RED = 'aa1409'
-    COLOR_RED = 'f44336'
-    COLOR_PINK = 'e91e63'
-    COLOR_ROSE = 'ffe4e1'
-    COLOR_FUCHSIA = 'ff66ff'
-    COLOR_PURPLE = '9c27b0'
-    COLOR_DARK_PURPLE = '673ab7'
-    COLOR_INDIGO = '3f51b5'
-    COLOR_BLUE = '2196f3'
-    COLOR_LIGHT_BLUE = '03a9f4'
-    COLOR_CYAN = '00bcd4'
-    COLOR_TEAL = '009688'
-    COLOR_AQUA = '00ffff'
-    COLOR_DARK_GREEN = '2f6a31'
-    COLOR_GREEN = '4caf50'
-    COLOR_LIGHT_GREEN = '8bc34a'
-    COLOR_LIME = 'cddc39'
-    COLOR_YELLOW = 'ffeb3b'
-    COLOR_AMBER = 'ffc107'
-    COLOR_ORANGE = 'ff9800'
-    COLOR_DARK_ORANGE = 'ff5722'
-    COLOR_BROWN = '795548'
-    COLOR_LIGHT_GREY = 'c0c0c0'
-    COLOR_GREY = '9e9e9e'
-    COLOR_DARK_GREY = '607d8b'
-    COLOR_BLACK = '111111'
-    COLOR_WHITE = 'ffffff'
-
-    CHOICES = (
-        (COLOR_DARK_RED, _('Dark Red')),
-        (COLOR_RED, _('Red')),
-        (COLOR_PINK, _('Pink')),
-        (COLOR_ROSE, _('Rose')),
-        (COLOR_FUCHSIA, _('Fuchsia')),
-        (COLOR_PURPLE, _('Purple')),
-        (COLOR_DARK_PURPLE, _('Dark Purple')),
-        (COLOR_INDIGO, _('Indigo')),
-        (COLOR_BLUE, _('Blue')),
-        (COLOR_LIGHT_BLUE, _('Light Blue')),
-        (COLOR_CYAN, _('Cyan')),
-        (COLOR_TEAL, _('Teal')),
-        (COLOR_AQUA, _('Aqua')),
-        (COLOR_DARK_GREEN, _('Dark Green')),
-        (COLOR_GREEN, _('Green')),
-        (COLOR_LIGHT_GREEN, _('Light Green')),
-        (COLOR_LIME, _('Lime')),
-        (COLOR_YELLOW, _('Yellow')),
-        (COLOR_AMBER, _('Amber')),
-        (COLOR_ORANGE, _('Orange')),
-        (COLOR_DARK_ORANGE, _('Dark Orange')),
-        (COLOR_BROWN, _('Brown')),
-        (COLOR_LIGHT_GREY, _('Light Grey')),
-        (COLOR_GREY, _('Grey')),
-        (COLOR_DARK_GREY, _('Dark Grey')),
-        (COLOR_BLACK, _('Black')),
-        (COLOR_WHITE, _('White')),
-    )
-
-
-#
-# Button color choices
-#
-
-class ButtonColorChoices(ChoiceSet):
-    """
-    Map standard button color choices to Bootstrap 3 button classes
-    """
-    DEFAULT = 'outline-dark'
-    BLUE = 'blue'
-    INDIGO = 'indigo'
-    PURPLE = 'purple'
-    PINK = 'pink'
-    RED = 'red'
-    ORANGE = 'orange'
-    YELLOW = 'yellow'
-    GREEN = 'green'
-    TEAL = 'teal'
-    CYAN = 'cyan'
-    GRAY = 'gray'
-    GREY = 'gray'  # Backward compatability for <3.2
-    BLACK = 'black'
-    WHITE = 'white'
-
-    CHOICES = (
-        (DEFAULT, _('Default')),
-        (BLUE, _('Blue')),
-        (INDIGO, _('Indigo')),
-        (PURPLE, _('Purple')),
-        (PINK, _('Pink')),
-        (RED, _('Red')),
-        (ORANGE, _('Orange')),
-        (YELLOW, _('Yellow')),
-        (GREEN, _('Green')),
-        (TEAL, _('Teal')),
-        (CYAN, _('Cyan')),
-        (GRAY, _('Gray')),
-        (BLACK, _('Black')),
-        (WHITE, _('White')),
-    )
-
-
-#
-# Import Choices
-#
-
-class ImportMethodChoices(ChoiceSet):
-    DIRECT = 'direct'
-    UPLOAD = 'upload'
-    DATA_FILE = 'datafile'
-
-    CHOICES = [
-        (DIRECT, _('Direct')),
-        (UPLOAD, _('Upload')),
-        (DATA_FILE, _('Data file')),
-    ]
-
-
-class ImportFormatChoices(ChoiceSet):
-    AUTO = 'auto'
-    CSV = 'csv'
-    JSON = 'json'
-    YAML = 'yaml'
-
-    CHOICES = [
-        (AUTO, _('Auto-detect')),
-        (CSV, 'CSV'),
-        (JSON, 'JSON'),
-        (YAML, 'YAML'),
-    ]
-
-
-class CSVDelimiterChoices(ChoiceSet):
-    AUTO = 'auto'
-    COMMA = CSV_DELIMITERS['comma']
-    SEMICOLON = CSV_DELIMITERS['semicolon']
-    TAB = CSV_DELIMITERS['tab']
-
-    CHOICES = [
-        (AUTO, _('Auto-detect')),
-        (COMMA, _('Comma')),
-        (SEMICOLON, _('Semicolon')),
-        (TAB, _('Tab')),
-    ]

+ 1 - 1
netbox/utilities/forms/bulk_import.py

@@ -7,7 +7,7 @@ from django import forms
 from django.utils.translation import gettext as _
 
 from core.forms.mixins import SyncedDataMixin
-from utilities.choices import CSVDelimiterChoices, ImportFormatChoices, ImportMethodChoices
+from netbox.choices import CSVDelimiterChoices, ImportFormatChoices, ImportMethodChoices
 from utilities.constants import CSV_DELIMITERS
 from utilities.forms.utils import parse_csv
 

+ 1 - 1
netbox/utilities/forms/widgets/select.py

@@ -1,6 +1,6 @@
 from django import forms
 
-from utilities.choices import ColorChoices
+from netbox.choices import ColorChoices
 from ..utils import add_blank_choice
 
 __all__ = (

+ 1 - 1
netbox/utilities/testing/views.py

@@ -11,9 +11,9 @@ from django.utils.translation import gettext as _
 from core.models import ObjectType
 from extras.choices import ObjectChangeActionChoices
 from extras.models import ObjectChange
+from netbox.choices import CSVDelimiterChoices, ImportFormatChoices
 from netbox.models.features import ChangeLoggingMixin
 from users.models import ObjectPermission
-from utilities.choices import CSVDelimiterChoices, ImportFormatChoices
 from .base import ModelTestCase
 from .utils import disable_warnings, post_data
 

+ 1 - 1
netbox/utilities/tests/test_forms.py

@@ -1,7 +1,7 @@
 from django import forms
 from django.test import TestCase
 
-from utilities.choices import ImportFormatChoices
+from netbox.choices import ImportFormatChoices
 from utilities.forms.bulk_import import BulkImportForm
 from utilities.forms.forms import BulkRenameForm
 from utilities.forms.utils import expand_alphanumeric_pattern, expand_ipaddress_pattern