Converted device fields to use FlexibleModelChoiceField; misc cleanup

This commit is contained in:
Jeremy Stretch 2017-06-07 15:51:11 -04:00
parent 4671829ad8
commit 65b6fe576f
3 changed files with 36 additions and 24 deletions

View File

@ -125,6 +125,7 @@ class SiteCSVForm(forms.ModelForm):
'contact_name', 'contact_phone', 'contact_email', 'comments', 'contact_name', 'contact_phone', 'contact_email', 'comments',
] ]
help_texts = { help_texts = {
'name': 'Site name',
'slug': 'URL-friendly slug', 'slug': 'URL-friendly slug',
'asn': '32-bit autonomous system number', 'asn': '32-bit autonomous system number',
} }
@ -733,6 +734,9 @@ class BaseDeviceCSVForm(forms.ModelForm):
class Meta: class Meta:
fields = [] fields = []
model = Device model = Device
help_texts = {
'name': 'Device name',
}
def clean(self): def clean(self):
@ -777,9 +781,6 @@ class DeviceCSVForm(BaseDeviceCSVForm):
'name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'asset_tag', 'status', 'name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'asset_tag', 'status',
'site', 'rack_group', 'rack_name', 'position', 'face', 'site', 'rack_group', 'rack_name', 'position', 'face',
] ]
help_texts = {
'name': 'Device name',
}
def clean(self): def clean(self):
@ -806,7 +807,7 @@ class ChildDeviceCSVForm(BaseDeviceCSVForm):
parent = FlexibleModelChoiceField( parent = FlexibleModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Name of parent device', help_text='Name or ID of parent device',
error_messages={ error_messages={
'invalid_choice': 'Parent device not found.', 'invalid_choice': 'Parent device not found.',
} }
@ -938,7 +939,7 @@ class ConsoleConnectionCSVForm(forms.ModelForm):
console_server = FlexibleModelChoiceField( console_server = FlexibleModelChoiceField(
queryset=Device.objects.filter(device_type__is_console_server=True), queryset=Device.objects.filter(device_type__is_console_server=True),
to_field_name='name', to_field_name='name',
help_text='Console server name or PK', help_text='Console server name or ID',
error_messages={ error_messages={
'invalid_choice': 'Console server not found', 'invalid_choice': 'Console server not found',
} }
@ -949,7 +950,7 @@ class ConsoleConnectionCSVForm(forms.ModelForm):
device = FlexibleModelChoiceField( device = FlexibleModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Device name or PK', help_text='Device name or ID',
error_messages={ error_messages={
'invalid_choice': 'Device not found', 'invalid_choice': 'Device not found',
} }
@ -1195,7 +1196,7 @@ class PowerConnectionCSVForm(forms.ModelForm):
pdu = FlexibleModelChoiceField( pdu = FlexibleModelChoiceField(
queryset=Device.objects.filter(device_type__is_pdu=True), queryset=Device.objects.filter(device_type__is_pdu=True),
to_field_name='name', to_field_name='name',
help_text='PDU name or PK', help_text='PDU name or ID',
error_messages={ error_messages={
'invalid_choice': 'PDU not found.', 'invalid_choice': 'PDU not found.',
} }
@ -1206,7 +1207,7 @@ class PowerConnectionCSVForm(forms.ModelForm):
device = FlexibleModelChoiceField( device = FlexibleModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Device name or PK', help_text='Device name or ID',
error_messages={ error_messages={
'invalid_choice': 'Device not found', 'invalid_choice': 'Device not found',
} }
@ -1602,20 +1603,20 @@ class InterfaceConnectionCSVForm(forms.ModelForm):
device_a = FlexibleModelChoiceField( device_a = FlexibleModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Device name or PK', help_text='Name or ID of device A',
error_messages={'invalid_choice': 'Device A not found.'} error_messages={'invalid_choice': 'Device A not found.'}
) )
interface_a = forms.CharField( interface_a = forms.CharField(
help_text='Interface name' help_text='Name of interface A'
) )
device_b = FlexibleModelChoiceField( device_b = FlexibleModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Device name or PK', help_text='Name or ID of device B',
error_messages={'invalid_choice': 'Device B not found.'} error_messages={'invalid_choice': 'Device B not found.'}
) )
interface_b = forms.CharField( interface_b = forms.CharField(
help_text='Interface name' help_text='Name of interface B'
) )
connection_status = CSVChoiceField( connection_status = CSVChoiceField(
choices=CONNECTION_STATUS_CHOICES, choices=CONNECTION_STATUS_CHOICES,

View File

@ -9,7 +9,8 @@ from tenancy.forms import TenancyForm
from tenancy.models import Tenant from tenancy.models import Tenant
from utilities.forms import ( from utilities.forms import (
APISelect, BootstrapMixin, BulkEditNullBooleanSelect, ChainedModelChoiceField, CSVChoiceField, APISelect, BootstrapMixin, BulkEditNullBooleanSelect, ChainedModelChoiceField, CSVChoiceField,
ExpandableIPAddressField, FilterChoiceField, Livesearch, ReturnURLForm, SlugField, add_blank_choice, ExpandableIPAddressField, FilterChoiceField, FlexibleModelChoiceField, Livesearch, ReturnURLForm, SlugField,
add_blank_choice,
) )
from .models import ( from .models import (
Aggregate, IPAddress, IPADDRESS_STATUS_CHOICES, Prefix, PREFIX_STATUS_CHOICES, RIR, Role, Service, VLAN, Aggregate, IPAddress, IPADDRESS_STATUS_CHOICES, Prefix, PREFIX_STATUS_CHOICES, RIR, Role, Service, VLAN,
@ -61,6 +62,9 @@ class VRFCSVForm(forms.ModelForm):
class Meta: class Meta:
model = VRF model = VRF
fields = ['name', 'rd', 'tenant', 'enforce_unique', 'description'] fields = ['name', 'rd', 'tenant', 'enforce_unique', 'description']
help_texts = {
'name': 'VRF name',
}
class VRFBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): class VRFBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm):
@ -239,13 +243,13 @@ class PrefixCSVForm(forms.ModelForm):
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=IPADDRESS_STATUS_CHOICES, choices=IPADDRESS_STATUS_CHOICES,
help_text='Status name' help_text='Operational status'
) )
role = forms.ModelChoiceField( role = forms.ModelChoiceField(
queryset=Role.objects.all(), queryset=Role.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Role name', help_text='Functional role',
error_messages={ error_messages={
'invalid_choice': 'Invalid role.', 'invalid_choice': 'Invalid role.',
} }
@ -558,13 +562,13 @@ class IPAddressCSVForm(forms.ModelForm):
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=PREFIX_STATUS_CHOICES, choices=PREFIX_STATUS_CHOICES,
help_text='Status name' help_text='Operational status'
) )
device = forms.ModelChoiceField( device = FlexibleModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Name of assigned Device', help_text='Name or ID of assigned device',
error_messages={ error_messages={
'invalid_choice': 'Device not found.', 'invalid_choice': 'Device not found.',
} }
@ -574,7 +578,7 @@ class IPAddressCSVForm(forms.ModelForm):
required=False required=False
) )
is_primary = forms.BooleanField( is_primary = forms.BooleanField(
help_text='This is the primary IP for the assigned device', help_text='Make this the primary IP for the assigned device',
required=False required=False
) )
@ -743,13 +747,13 @@ class VLANCSVForm(forms.ModelForm):
) )
status = CSVChoiceField( status = CSVChoiceField(
choices=VLAN_STATUS_CHOICES, choices=VLAN_STATUS_CHOICES,
help_text='Status name' help_text='Operational status'
) )
role = forms.ModelChoiceField( role = forms.ModelChoiceField(
queryset=Role.objects.all(), queryset=Role.objects.all(),
required=False, required=False,
to_field_name='name', to_field_name='name',
help_text='Name of assigned role', help_text='Functional role',
error_messages={ error_messages={
'invalid_choice': 'Invalid role.', 'invalid_choice': 'Invalid role.',
} }
@ -758,6 +762,10 @@ class VLANCSVForm(forms.ModelForm):
class Meta: class Meta:
model = VLAN model = VLAN
fields = ['site', 'group_name', 'vid', 'name', 'tenant', 'status', 'role', 'description'] fields = ['site', 'group_name', 'vid', 'name', 'tenant', 'status', 'role', 'description']
help_texts = {
'vid': 'Numeric VLAN ID (1-4095)',
'name': 'VLAN name',
}
def clean(self): def clean(self):

View File

@ -7,7 +7,7 @@ from django import forms
from django.db.models import Count from django.db.models import Count
from dcim.models import Device from dcim.models import Device
from utilities.forms import BootstrapMixin, BulkEditForm, CSVDataField, FilterChoiceField, SlugField from utilities.forms import BootstrapMixin, BulkEditForm, FilterChoiceField, FlexibleModelChoiceField, SlugField
from .models import Secret, SecretRole, UserKey from .models import Secret, SecretRole, UserKey
@ -66,10 +66,10 @@ class SecretForm(BootstrapMixin, forms.ModelForm):
class SecretCSVForm(forms.ModelForm): class SecretCSVForm(forms.ModelForm):
device = forms.ModelChoiceField( device = FlexibleModelChoiceField(
queryset=Device.objects.all(), queryset=Device.objects.all(),
to_field_name='name', to_field_name='name',
help_text='Device name', help_text='Device name or ID',
error_messages={ error_messages={
'invalid_choice': 'Device not found.', 'invalid_choice': 'Device not found.',
} }
@ -89,6 +89,9 @@ class SecretCSVForm(forms.ModelForm):
class Meta: class Meta:
model = Secret model = Secret
fields = ['device', 'role', 'name', 'plaintext'] fields = ['device', 'role', 'name', 'plaintext']
help_texts = {
'name': 'Name or username',
}
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
s = super(SecretCSVForm, self).save(*args, **kwargs) s = super(SecretCSVForm, self).save(*args, **kwargs)