Skip to content

Commit

Permalink
Closes #14740: Remove BootstrapMixin (#14841)
Browse files Browse the repository at this point in the history
* Introduce custom form widget templates to apply CSS classes

* Apply both mandatory and optional CSS classes to form widgets

* Omit required & placeholder attrs

* Move annotation of field validation failures to CSS

* Remove BootstrapMixin class

* Remove obsolete ComponentTemplateImportForm class

* Remove obsolete custom forms for login & password change

* Clean up obsolete accommodations for 'required' widget attr
  • Loading branch information
jeremystretch authored Jan 19, 2024
1 parent 874685f commit da085e6
Show file tree
Hide file tree
Showing 33 changed files with 102 additions and 180 deletions.
12 changes: 6 additions & 6 deletions netbox/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import login as auth_login, logout as auth_logout
from django.contrib.auth import update_session_auth_hash
from django.contrib.auth import login as auth_login, logout as auth_logout, update_session_auth_hash
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import update_last_login
from django.contrib.auth.signals import user_logged_in
Expand Down Expand Up @@ -72,7 +72,7 @@ def get_auth_backends(self, request):
return auth_backends

def get(self, request):
form = forms.LoginForm(request)
form = AuthenticationForm(request)

if request.user.is_authenticated:
logger = logging.getLogger('netbox.auth.login')
Expand All @@ -85,7 +85,7 @@ def get(self, request):

def post(self, request):
logger = logging.getLogger('netbox.auth.login')
form = forms.LoginForm(request, data=request.POST)
form = AuthenticationForm(request, data=request.POST)

if form.is_valid():
logger.debug("Login form validation was successful")
Expand Down Expand Up @@ -220,15 +220,15 @@ def get(self, request):
messages.warning(request, "LDAP-authenticated user credentials cannot be changed within NetBox.")
return redirect('account:profile')

form = forms.PasswordChangeForm(user=request.user)
form = PasswordChangeForm(user=request.user)

return render(request, self.template_name, {
'form': form,
'active_tab': 'password',
})

def post(self, request):
form = forms.PasswordChangeForm(user=request.user, data=request.POST)
form = PasswordChangeForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
update_session_auth_hash(request, form.user)
Expand Down
3 changes: 1 addition & 2 deletions netbox/circuits/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from django.utils.translation import gettext_lazy as _
from netbox.forms import NetBoxModelImportForm
from tenancy.models import Tenant
from utilities.forms import BootstrapMixin
from utilities.forms.fields import CSVChoiceField, CSVModelChoiceField, SlugField

__all__ = (
Expand Down Expand Up @@ -112,7 +111,7 @@ class Meta:
]


class CircuitTerminationImportForm(BootstrapMixin, forms.ModelForm):
class CircuitTerminationImportForm(forms.ModelForm):
site = CSVModelChoiceField(
label=_('Site'),
queryset=Site.objects.all(),
Expand Down
4 changes: 2 additions & 2 deletions netbox/core/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from netbox.forms import NetBoxModelForm
from netbox.registry import registry
from netbox.utils import get_data_backend_choices
from utilities.forms import BootstrapMixin, get_field_value
from utilities.forms import get_field_value
from utilities.forms.fields import CommentField
from utilities.forms.widgets import HTMXSelect

Expand Down Expand Up @@ -138,7 +138,7 @@ def __new__(mcs, name, bases, attrs):
return super().__new__(mcs, name, bases, attrs)


class ConfigRevisionForm(BootstrapMixin, forms.ModelForm, metaclass=ConfigFormMetaclass):
class ConfigRevisionForm(forms.ModelForm, metaclass=ConfigFormMetaclass):
"""
Form for creating a new ConfigRevision.
"""
Expand Down
4 changes: 2 additions & 2 deletions netbox/dcim/forms/bulk_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dcim.models import *
from extras.models import Tag
from netbox.forms.mixins import CustomFieldsMixin
from utilities.forms import BootstrapMixin, form_from_model
from utilities.forms import form_from_model
from utilities.forms.fields import DynamicModelMultipleChoiceField, ExpandableNameField
from .object_create import ComponentCreateForm

Expand All @@ -26,7 +26,7 @@
# Device components
#

class DeviceBulkAddComponentForm(BootstrapMixin, CustomFieldsMixin, ComponentCreateForm):
class DeviceBulkAddComponentForm(CustomFieldsMixin, ComponentCreateForm):
pk = forms.ModelMultipleChoiceField(
queryset=Device.objects.all(),
widget=forms.MultipleHiddenInput()
Expand Down
8 changes: 4 additions & 4 deletions netbox/dcim/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ipam.models import ASN, IPAddress, VLAN, VLANGroup, VRF
from netbox.forms import NetBoxModelForm
from tenancy.forms import TenancyForm
from utilities.forms import BootstrapMixin, add_blank_choice
from utilities.forms import add_blank_choice
from utilities.forms.fields import (
CommentField, ContentTypeChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, JSONField,
NumericArrayField, SlugField,
Expand Down Expand Up @@ -748,7 +748,7 @@ def clean_vc_position(self):
return vc_position


class VCMemberSelectForm(BootstrapMixin, forms.Form):
class VCMemberSelectForm(forms.Form):
device = DynamicModelChoiceField(
label=_('Device'),
queryset=Device.objects.all(),
Expand All @@ -771,7 +771,7 @@ def clean_device(self):
# Device component templates
#

class ComponentTemplateForm(BootstrapMixin, forms.ModelForm):
class ComponentTemplateForm(forms.ModelForm):
device_type = DynamicModelChoiceField(
label=_('Device type'),
queryset=DeviceType.objects.all()
Expand Down Expand Up @@ -1272,7 +1272,7 @@ class Meta:
]


class PopulateDeviceBayForm(BootstrapMixin, forms.Form):
class PopulateDeviceBayForm(forms.Form):
installed_device = forms.ModelChoiceField(
queryset=Device.objects.all(),
label=_('Child Device'),
Expand Down
25 changes: 10 additions & 15 deletions netbox/dcim/forms/object_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from dcim.choices import InterfacePoEModeChoices, InterfacePoETypeChoices, InterfaceTypeChoices, PortTypeChoices
from dcim.models import *
from utilities.forms import BootstrapMixin
from wireless.choices import WirelessRoleChoices

__all__ = (
Expand All @@ -24,11 +23,7 @@
# Component template import forms
#

class ComponentTemplateImportForm(BootstrapMixin, forms.ModelForm):
pass


class ConsolePortTemplateImportForm(ComponentTemplateImportForm):
class ConsolePortTemplateImportForm(forms.ModelForm):

class Meta:
model = ConsolePortTemplate
Expand All @@ -37,7 +32,7 @@ class Meta:
]


class ConsoleServerPortTemplateImportForm(ComponentTemplateImportForm):
class ConsoleServerPortTemplateImportForm(forms.ModelForm):

class Meta:
model = ConsoleServerPortTemplate
Expand All @@ -46,7 +41,7 @@ class Meta:
]


class PowerPortTemplateImportForm(ComponentTemplateImportForm):
class PowerPortTemplateImportForm(forms.ModelForm):

class Meta:
model = PowerPortTemplate
Expand All @@ -55,7 +50,7 @@ class Meta:
]


class PowerOutletTemplateImportForm(ComponentTemplateImportForm):
class PowerOutletTemplateImportForm(forms.ModelForm):
power_port = forms.ModelChoiceField(
label=_('Power port'),
queryset=PowerPortTemplate.objects.all(),
Expand Down Expand Up @@ -84,7 +79,7 @@ def clean_module_type(self):
return module_type


class InterfaceTemplateImportForm(ComponentTemplateImportForm):
class InterfaceTemplateImportForm(forms.ModelForm):
type = forms.ChoiceField(
label=_('Type'),
choices=InterfaceTypeChoices.CHOICES
Expand Down Expand Up @@ -113,7 +108,7 @@ class Meta:
]


class FrontPortTemplateImportForm(ComponentTemplateImportForm):
class FrontPortTemplateImportForm(forms.ModelForm):
type = forms.ChoiceField(
label=_('Type'),
choices=PortTypeChoices.CHOICES
Expand Down Expand Up @@ -145,7 +140,7 @@ class Meta:
]


class RearPortTemplateImportForm(ComponentTemplateImportForm):
class RearPortTemplateImportForm(forms.ModelForm):
type = forms.ChoiceField(
label=_('Type'),
choices=PortTypeChoices.CHOICES
Expand All @@ -158,7 +153,7 @@ class Meta:
]


class ModuleBayTemplateImportForm(ComponentTemplateImportForm):
class ModuleBayTemplateImportForm(forms.ModelForm):

class Meta:
model = ModuleBayTemplate
Expand All @@ -167,7 +162,7 @@ class Meta:
]


class DeviceBayTemplateImportForm(ComponentTemplateImportForm):
class DeviceBayTemplateImportForm(forms.ModelForm):

class Meta:
model = DeviceBayTemplate
Expand All @@ -176,7 +171,7 @@ class Meta:
]


class InventoryItemTemplateImportForm(ComponentTemplateImportForm):
class InventoryItemTemplateImportForm(forms.ModelForm):
parent = forms.ModelChoiceField(
label=_('Parent'),
queryset=InventoryItemTemplate.objects.all(),
Expand Down
4 changes: 2 additions & 2 deletions netbox/extras/dashboard/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from extras.choices import DashboardWidgetColorChoices
from netbox.registry import registry
from utilities.forms import BootstrapMixin, add_blank_choice
from utilities.forms import add_blank_choice

__all__ = (
'DashboardWidgetAddForm',
Expand All @@ -16,7 +16,7 @@ def get_widget_choices():
return registry['widgets'].items()


class DashboardWidgetForm(BootstrapMixin, forms.Form):
class DashboardWidgetForm(forms.Form):
title = forms.CharField(
required=False
)
Expand Down
3 changes: 1 addition & 2 deletions netbox/extras/dashboard/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from core.models import ContentType
from extras.choices import BookmarkOrderingChoices
from utilities.choices import ButtonColorChoices
from utilities.forms import BootstrapMixin
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
Expand Down Expand Up @@ -58,7 +57,7 @@ def get_models_from_content_types(content_types):
return models


class WidgetConfigForm(BootstrapMixin, forms.Form):
class WidgetConfigForm(forms.Form):
pass


Expand Down
22 changes: 11 additions & 11 deletions netbox/extras/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from extras.models import *
from netbox.forms import NetBoxModelForm
from tenancy.models import Tenant, TenantGroup
from utilities.forms import BootstrapMixin, add_blank_choice, get_field_value
from utilities.forms import add_blank_choice, get_field_value
from utilities.forms.fields import (
CommentField, ContentTypeChoiceField, ContentTypeMultipleChoiceField, DynamicModelChoiceField,
DynamicModelMultipleChoiceField, JSONField, SlugField,
Expand All @@ -38,7 +38,7 @@
)


class CustomFieldForm(BootstrapMixin, forms.ModelForm):
class CustomFieldForm(forms.ModelForm):
content_types = ContentTypeMultipleChoiceField(
label=_('Content types'),
queryset=ContentType.objects.with_feature('custom_fields')
Expand Down Expand Up @@ -83,7 +83,7 @@ def __init__(self, *args, **kwargs):
self.fields['type'].disabled = True


class CustomFieldChoiceSetForm(BootstrapMixin, forms.ModelForm):
class CustomFieldChoiceSetForm(forms.ModelForm):
extra_choices = forms.CharField(
widget=ChoicesWidget(),
required=False,
Expand Down Expand Up @@ -122,7 +122,7 @@ def clean_extra_choices(self):
return data


class CustomLinkForm(BootstrapMixin, forms.ModelForm):
class CustomLinkForm(forms.ModelForm):
content_types = ContentTypeMultipleChoiceField(
label=_('Content types'),
queryset=ContentType.objects.with_feature('custom_links')
Expand All @@ -149,7 +149,7 @@ class Meta:
}


class ExportTemplateForm(BootstrapMixin, SyncedDataMixin, forms.ModelForm):
class ExportTemplateForm(SyncedDataMixin, forms.ModelForm):
content_types = ContentTypeMultipleChoiceField(
label=_('Content types'),
queryset=ContentType.objects.with_feature('export_templates')
Expand Down Expand Up @@ -189,7 +189,7 @@ def clean(self):
return self.cleaned_data


class SavedFilterForm(BootstrapMixin, forms.ModelForm):
class SavedFilterForm(forms.ModelForm):
slug = SlugField()
content_types = ContentTypeMultipleChoiceField(
label=_('Content types'),
Expand All @@ -216,7 +216,7 @@ def __init__(self, *args, initial=None, **kwargs):
super().__init__(*args, initial=initial, **kwargs)


class BookmarkForm(BootstrapMixin, forms.ModelForm):
class BookmarkForm(forms.ModelForm):
object_type = ContentTypeChoiceField(
label=_('Object type'),
queryset=ContentType.objects.with_feature('bookmarks')
Expand Down Expand Up @@ -367,7 +367,7 @@ def save(self, *args, **kwargs):
return super().save(*args, **kwargs)


class TagForm(BootstrapMixin, forms.ModelForm):
class TagForm(forms.ModelForm):
slug = SlugField()
object_types = ContentTypeMultipleChoiceField(
label=_('Object types'),
Expand All @@ -386,7 +386,7 @@ class Meta:
]


class ConfigContextForm(BootstrapMixin, SyncedDataMixin, forms.ModelForm):
class ConfigContextForm(SyncedDataMixin, forms.ModelForm):
regions = DynamicModelMultipleChoiceField(
label=_('Regions'),
queryset=Region.objects.all(),
Expand Down Expand Up @@ -497,7 +497,7 @@ def clean(self):
return self.cleaned_data


class ConfigTemplateForm(BootstrapMixin, SyncedDataMixin, forms.ModelForm):
class ConfigTemplateForm(SyncedDataMixin, forms.ModelForm):
tags = DynamicModelMultipleChoiceField(
label=_('Tags'),
queryset=Tag.objects.all(),
Expand Down Expand Up @@ -541,7 +541,7 @@ def clean(self):
return self.cleaned_data


class ImageAttachmentForm(BootstrapMixin, forms.ModelForm):
class ImageAttachmentForm(forms.ModelForm):

class Meta:
model = ImageAttachment
Expand Down
3 changes: 1 addition & 2 deletions netbox/extras/forms/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.utils.translation import gettext_lazy as _

from extras.choices import DurationChoices
from utilities.forms import BootstrapMixin
from utilities.forms.widgets import DateTimePicker, NumberWithOptions
from utilities.utils import local_now

Expand All @@ -11,7 +10,7 @@
)


class ReportForm(BootstrapMixin, forms.Form):
class ReportForm(forms.Form):
schedule_at = forms.DateTimeField(
required=False,
widget=DateTimePicker(),
Expand Down
Loading

0 comments on commit da085e6

Please sign in to comment.