From 65b6fe576fb14f87c26c6a72c301f0efb8673f02 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 7 Jun 2017 15:51:11 -0400 Subject: [PATCH] Converted device fields to use FlexibleModelChoiceField; misc cleanup --- netbox/dcim/forms.py | 25 +++++++++++++------------ netbox/ipam/forms.py | 26 +++++++++++++++++--------- netbox/secrets/forms.py | 9 ++++++--- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 40452172b..996c231c8 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -125,6 +125,7 @@ class SiteCSVForm(forms.ModelForm): 'contact_name', 'contact_phone', 'contact_email', 'comments', ] help_texts = { + 'name': 'Site name', 'slug': 'URL-friendly slug', 'asn': '32-bit autonomous system number', } @@ -733,6 +734,9 @@ class BaseDeviceCSVForm(forms.ModelForm): class Meta: fields = [] model = Device + help_texts = { + 'name': 'Device name', + } def clean(self): @@ -777,9 +781,6 @@ class DeviceCSVForm(BaseDeviceCSVForm): 'name', 'device_role', 'tenant', 'manufacturer', 'model_name', 'platform', 'serial', 'asset_tag', 'status', 'site', 'rack_group', 'rack_name', 'position', 'face', ] - help_texts = { - 'name': 'Device name', - } def clean(self): @@ -806,7 +807,7 @@ class ChildDeviceCSVForm(BaseDeviceCSVForm): parent = FlexibleModelChoiceField( queryset=Device.objects.all(), to_field_name='name', - help_text='Name of parent device', + help_text='Name or ID of parent device', error_messages={ 'invalid_choice': 'Parent device not found.', } @@ -938,7 +939,7 @@ class ConsoleConnectionCSVForm(forms.ModelForm): console_server = FlexibleModelChoiceField( queryset=Device.objects.filter(device_type__is_console_server=True), to_field_name='name', - help_text='Console server name or PK', + help_text='Console server name or ID', error_messages={ 'invalid_choice': 'Console server not found', } @@ -949,7 +950,7 @@ class ConsoleConnectionCSVForm(forms.ModelForm): device = FlexibleModelChoiceField( queryset=Device.objects.all(), to_field_name='name', - help_text='Device name or PK', + help_text='Device name or ID', error_messages={ 'invalid_choice': 'Device not found', } @@ -1195,7 +1196,7 @@ class PowerConnectionCSVForm(forms.ModelForm): pdu = FlexibleModelChoiceField( queryset=Device.objects.filter(device_type__is_pdu=True), to_field_name='name', - help_text='PDU name or PK', + help_text='PDU name or ID', error_messages={ 'invalid_choice': 'PDU not found.', } @@ -1206,7 +1207,7 @@ class PowerConnectionCSVForm(forms.ModelForm): device = FlexibleModelChoiceField( queryset=Device.objects.all(), to_field_name='name', - help_text='Device name or PK', + help_text='Device name or ID', error_messages={ 'invalid_choice': 'Device not found', } @@ -1602,20 +1603,20 @@ class InterfaceConnectionCSVForm(forms.ModelForm): device_a = FlexibleModelChoiceField( queryset=Device.objects.all(), 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.'} ) interface_a = forms.CharField( - help_text='Interface name' + help_text='Name of interface A' ) device_b = FlexibleModelChoiceField( queryset=Device.objects.all(), 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.'} ) interface_b = forms.CharField( - help_text='Interface name' + help_text='Name of interface B' ) connection_status = CSVChoiceField( choices=CONNECTION_STATUS_CHOICES, diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index 0ea10c838..82e489fa8 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -9,7 +9,8 @@ from tenancy.forms import TenancyForm from tenancy.models import Tenant from utilities.forms import ( 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 ( Aggregate, IPAddress, IPADDRESS_STATUS_CHOICES, Prefix, PREFIX_STATUS_CHOICES, RIR, Role, Service, VLAN, @@ -61,6 +62,9 @@ class VRFCSVForm(forms.ModelForm): class Meta: model = VRF fields = ['name', 'rd', 'tenant', 'enforce_unique', 'description'] + help_texts = { + 'name': 'VRF name', + } class VRFBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -239,13 +243,13 @@ class PrefixCSVForm(forms.ModelForm): ) status = CSVChoiceField( choices=IPADDRESS_STATUS_CHOICES, - help_text='Status name' + help_text='Operational status' ) role = forms.ModelChoiceField( queryset=Role.objects.all(), required=False, to_field_name='name', - help_text='Role name', + help_text='Functional role', error_messages={ 'invalid_choice': 'Invalid role.', } @@ -558,13 +562,13 @@ class IPAddressCSVForm(forms.ModelForm): ) status = CSVChoiceField( choices=PREFIX_STATUS_CHOICES, - help_text='Status name' + help_text='Operational status' ) - device = forms.ModelChoiceField( + device = FlexibleModelChoiceField( queryset=Device.objects.all(), required=False, to_field_name='name', - help_text='Name of assigned Device', + help_text='Name or ID of assigned device', error_messages={ 'invalid_choice': 'Device not found.', } @@ -574,7 +578,7 @@ class IPAddressCSVForm(forms.ModelForm): required=False ) 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 ) @@ -743,13 +747,13 @@ class VLANCSVForm(forms.ModelForm): ) status = CSVChoiceField( choices=VLAN_STATUS_CHOICES, - help_text='Status name' + help_text='Operational status' ) role = forms.ModelChoiceField( queryset=Role.objects.all(), required=False, to_field_name='name', - help_text='Name of assigned role', + help_text='Functional role', error_messages={ 'invalid_choice': 'Invalid role.', } @@ -758,6 +762,10 @@ class VLANCSVForm(forms.ModelForm): class Meta: model = VLAN fields = ['site', 'group_name', 'vid', 'name', 'tenant', 'status', 'role', 'description'] + help_texts = { + 'vid': 'Numeric VLAN ID (1-4095)', + 'name': 'VLAN name', + } def clean(self): diff --git a/netbox/secrets/forms.py b/netbox/secrets/forms.py index 4a2a75abf..aafa9c4b1 100644 --- a/netbox/secrets/forms.py +++ b/netbox/secrets/forms.py @@ -7,7 +7,7 @@ from django import forms from django.db.models import Count 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 @@ -66,10 +66,10 @@ class SecretForm(BootstrapMixin, forms.ModelForm): class SecretCSVForm(forms.ModelForm): - device = forms.ModelChoiceField( + device = FlexibleModelChoiceField( queryset=Device.objects.all(), to_field_name='name', - help_text='Device name', + help_text='Device name or ID', error_messages={ 'invalid_choice': 'Device not found.', } @@ -89,6 +89,9 @@ class SecretCSVForm(forms.ModelForm): class Meta: model = Secret fields = ['device', 'role', 'name', 'plaintext'] + help_texts = { + 'name': 'Name or username', + } def save(self, *args, **kwargs): s = super(SecretCSVForm, self).save(*args, **kwargs)