mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Introduce ColorField for consistent represention of color choice fields in forms
This commit is contained in:
@ -23,7 +23,7 @@ from tenancy.forms import TenancyFilterForm, TenancyForm
|
|||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.forms import (
|
from utilities.forms import (
|
||||||
APISelect, APISelectMultiple, add_blank_choice, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect,
|
APISelect, APISelectMultiple, add_blank_choice, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect,
|
||||||
ColorSelect, CommentField, CSVChoiceField, CSVContentTypeField, CSVModelChoiceField, CSVTypedChoiceField,
|
ColorField, CommentField, CSVChoiceField, CSVContentTypeField, CSVModelChoiceField, CSVTypedChoiceField,
|
||||||
DynamicModelChoiceField, DynamicModelMultipleChoiceField, ExpandableNameField, form_from_model, JSONField,
|
DynamicModelChoiceField, DynamicModelMultipleChoiceField, ExpandableNameField, form_from_model, JSONField,
|
||||||
NumericArrayField, SelectWithPK, SmallTextarea, SlugField, StaticSelect2, StaticSelect2Multiple, TagFilterField,
|
NumericArrayField, SelectWithPK, SmallTextarea, SlugField, StaticSelect2, StaticSelect2Multiple, TagFilterField,
|
||||||
BOOLEAN_WITH_BLANK_CHOICES,
|
BOOLEAN_WITH_BLANK_CHOICES,
|
||||||
@ -610,10 +610,8 @@ class RackRoleBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|||||||
queryset=RackRole.objects.all(),
|
queryset=RackRole.objects.all(),
|
||||||
widget=forms.MultipleHiddenInput
|
widget=forms.MultipleHiddenInput
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
description = forms.CharField(
|
||||||
max_length=200,
|
max_length=200,
|
||||||
@ -1703,10 +1701,8 @@ class FrontPortTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
description = forms.CharField(
|
||||||
required=False
|
required=False
|
||||||
@ -1734,10 +1730,8 @@ class RearPortTemplateCreateForm(ComponentTemplateCreateForm):
|
|||||||
choices=PortTypeChoices,
|
choices=PortTypeChoices,
|
||||||
widget=StaticSelect2(),
|
widget=StaticSelect2(),
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
positions = forms.IntegerField(
|
positions = forms.IntegerField(
|
||||||
min_value=REARPORT_POSITIONS_MIN,
|
min_value=REARPORT_POSITIONS_MIN,
|
||||||
@ -1764,10 +1758,8 @@ class RearPortTemplateBulkEditForm(BootstrapMixin, BulkEditForm):
|
|||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
description = forms.CharField(
|
||||||
required=False
|
required=False
|
||||||
@ -1958,10 +1950,8 @@ class DeviceRoleBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
|
|||||||
queryset=DeviceRole.objects.all(),
|
queryset=DeviceRole.objects.all(),
|
||||||
widget=forms.MultipleHiddenInput
|
widget=forms.MultipleHiddenInput
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
vm_role = forms.NullBooleanField(
|
vm_role = forms.NullBooleanField(
|
||||||
required=False,
|
required=False,
|
||||||
@ -3454,10 +3444,8 @@ class FrontPortFilterForm(DeviceComponentFilterForm):
|
|||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect2Multiple()
|
widget=StaticSelect2Multiple()
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
@ -3497,10 +3485,8 @@ class FrontPortCreateForm(ComponentCreateForm):
|
|||||||
choices=PortTypeChoices,
|
choices=PortTypeChoices,
|
||||||
widget=StaticSelect2(),
|
widget=StaticSelect2(),
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
rear_port_set = forms.MultipleChoiceField(
|
rear_port_set = forms.MultipleChoiceField(
|
||||||
choices=[],
|
choices=[],
|
||||||
@ -3646,10 +3632,8 @@ class RearPortFilterForm(DeviceComponentFilterForm):
|
|||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect2Multiple()
|
widget=StaticSelect2Multiple()
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
@ -3677,10 +3661,8 @@ class RearPortCreateForm(ComponentCreateForm):
|
|||||||
choices=PortTypeChoices,
|
choices=PortTypeChoices,
|
||||||
widget=StaticSelect2(),
|
widget=StaticSelect2(),
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
positions = forms.IntegerField(
|
positions = forms.IntegerField(
|
||||||
min_value=REARPORT_POSITIONS_MIN,
|
min_value=REARPORT_POSITIONS_MIN,
|
||||||
@ -4411,10 +4393,8 @@ class CableBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditFo
|
|||||||
max_length=100,
|
max_length=100,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
length = forms.IntegerField(
|
length = forms.IntegerField(
|
||||||
min_value=1,
|
min_value=1,
|
||||||
@ -4489,10 +4469,8 @@ class CableFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
|||||||
choices=add_blank_choice(CableStatusChoices),
|
choices=add_blank_choice(CableStatusChoices),
|
||||||
widget=StaticSelect2()
|
widget=StaticSelect2()
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6, # RGB color code
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
device_id = DynamicModelMultipleChoiceField(
|
device_id = DynamicModelMultipleChoiceField(
|
||||||
queryset=Device.objects.all(),
|
queryset=Device.objects.all(),
|
||||||
|
@ -7,7 +7,7 @@ from django.utils.translation import gettext as _
|
|||||||
from dcim.models import DeviceRole, DeviceType, Platform, Region, Site, SiteGroup
|
from dcim.models import DeviceRole, DeviceType, Platform, Region, Site, SiteGroup
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from utilities.forms import (
|
from utilities.forms import (
|
||||||
add_blank_choice, APISelectMultiple, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect, ColorSelect,
|
add_blank_choice, APISelectMultiple, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect, ColorField,
|
||||||
CommentField, ContentTypeMultipleChoiceField, CSVModelForm, DateTimePicker, DynamicModelMultipleChoiceField,
|
CommentField, ContentTypeMultipleChoiceField, CSVModelForm, DateTimePicker, DynamicModelMultipleChoiceField,
|
||||||
JSONField, SlugField, StaticSelect2, BOOLEAN_WITH_BLANK_CHOICES,
|
JSONField, SlugField, StaticSelect2, BOOLEAN_WITH_BLANK_CHOICES,
|
||||||
)
|
)
|
||||||
@ -194,10 +194,8 @@ class TagBulkEditForm(BootstrapMixin, BulkEditForm):
|
|||||||
queryset=Tag.objects.all(),
|
queryset=Tag.objects.all(),
|
||||||
widget=forms.MultipleHiddenInput
|
widget=forms.MultipleHiddenInput
|
||||||
)
|
)
|
||||||
color = forms.CharField(
|
color = ColorField(
|
||||||
max_length=6,
|
required=False
|
||||||
required=False,
|
|
||||||
widget=ColorSelect()
|
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
description = forms.CharField(
|
||||||
max_length=200,
|
max_length=200,
|
||||||
|
@ -20,6 +20,7 @@ from .constants import *
|
|||||||
from .utils import expand_alphanumeric_pattern, expand_ipaddress_pattern
|
from .utils import expand_alphanumeric_pattern, expand_ipaddress_pattern
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
'ColorField',
|
||||||
'CommentField',
|
'CommentField',
|
||||||
'ContentTypeChoiceField',
|
'ContentTypeChoiceField',
|
||||||
'ContentTypeMultipleChoiceField',
|
'ContentTypeMultipleChoiceField',
|
||||||
@ -69,6 +70,13 @@ class SlugField(forms.SlugField):
|
|||||||
self.widget.attrs['slug-source'] = slug_source
|
self.widget.attrs['slug-source'] = slug_source
|
||||||
|
|
||||||
|
|
||||||
|
class ColorField(forms.CharField):
|
||||||
|
"""
|
||||||
|
A field which represents a color in hexadecimal RRGGBB format.
|
||||||
|
"""
|
||||||
|
widget = widgets.ColorSelect
|
||||||
|
|
||||||
|
|
||||||
class TagFilterField(forms.MultipleChoiceField):
|
class TagFilterField(forms.MultipleChoiceField):
|
||||||
"""
|
"""
|
||||||
A filter field for the tags of a model. Only the tags used by a model are displayed.
|
A filter field for the tags of a model. Only the tags used by a model are displayed.
|
||||||
|
Reference in New Issue
Block a user