diff --git a/netbox/circuits/forms.py b/netbox/circuits/forms.py index 444974240..b5dc31e73 100644 --- a/netbox/circuits/forms.py +++ b/netbox/circuits/forms.py @@ -47,8 +47,9 @@ class ProviderCSVForm(forms.ModelForm): fields = ['name', 'slug', 'asn', 'account', 'portal_url', 'comments'] help_texts = { 'name': 'Provider name', - 'asn': 'Autonomous system number', - 'comments': 'Free-form comments' + 'asn': '32-bit autonomous system number', + 'portal_url': 'Portal URL', + 'comments': 'Free-form comments', } @@ -116,7 +117,7 @@ class CircuitCSVForm(forms.ModelForm): type = forms.ModelChoiceField( queryset=CircuitType.objects.all(), to_field_name='name', - help_text='Name of assigned tenant', + help_text='Name of circuit type', error_messages={ 'invalid_choice': 'Invalid circuit type.' } @@ -125,7 +126,7 @@ class CircuitCSVForm(forms.ModelForm): queryset=Tenant.objects.all(), required=False, to_field_name='name', - help_text='Name of circuit type', + help_text='Name of assigned tenant', error_messages={ 'invalid_choice': 'Tenant not found.' } diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index 541ffbfa3..a017a41bc 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -146,6 +146,10 @@ class SiteCSVForm(forms.ModelForm): 'name', 'slug', 'region', 'tenant', 'facility', 'asn', 'physical_address', 'shipping_address', 'contact_name', 'contact_phone', 'contact_email', 'comments', ] + help_texts = { + 'slug': 'URL-friendly slug', + 'asn': '32-bit autonomous system number', + } class SiteBulkEditForm(BootstrapMixin, CustomFieldBulkEditForm): @@ -271,13 +275,15 @@ class RackCSVForm(forms.ModelForm): 'invalid_choice': 'Role not found.', } ) - type = forms.CharField(required=False) class Meta: model = Rack fields = [ 'site', 'group', 'name', 'facility_id', 'tenant', 'role', 'type', 'width', 'u_height', 'desc_units', ] + help_texts = { + 'type': 'Rack type', + } def clean_group(self): diff --git a/netbox/templates/utilities/obj_import.html b/netbox/templates/utilities/obj_import.html index 7aa7d3b0f..95dc996f1 100644 --- a/netbox/templates/utilities/obj_import.html +++ b/netbox/templates/utilities/obj_import.html @@ -42,7 +42,16 @@ {{ name }} {% if field.required %}{% endif %} - {{ field.help_text|default:field.label }} + + {{ field.help_text|default:field.label }} + {% if field.choices %} +
Examples: {{ field.choices|example_choices }} + {% elif field|widget_type == 'dateinput' %} +
Format: YYYY-MM-DD + {% elif field|widget_type == 'checkboxinput' %} +
Specify "true" or "false" + {% endif %} + {% endfor %} diff --git a/netbox/utilities/forms.py b/netbox/utilities/forms.py index 25a2d92df..628bb9d2a 100644 --- a/netbox/utilities/forms.py +++ b/netbox/utilities/forms.py @@ -235,7 +235,7 @@ class CSVDataField(forms.CharField): if not self.initial: self.initial = ','.join(required_fields) + '\n' if not self.help_text: - self.help_text = 'Enter the list of column headers followed by one line per record to be imported. Use ' \ + self.help_text = 'Enter the list of column headers followed by one line per record to be imported, using ' \ 'commas to separate values. Multi-line data and values containing commas may be wrapped ' \ 'in double quotes.' diff --git a/netbox/utilities/templatetags/form_helpers.py b/netbox/utilities/templatetags/form_helpers.py index 572be15fe..d3451ce86 100644 --- a/netbox/utilities/templatetags/form_helpers.py +++ b/netbox/utilities/templatetags/form_helpers.py @@ -40,7 +40,9 @@ def widget_type(field): """ Return the widget type """ - try: + if hasattr(field, 'widget'): + return field.widget.__class__.__name__.lower() + elif hasattr(field, 'field'): return field.field.widget.__class__.__name__.lower() - except AttributeError: + else: return None diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 2dc0b429a..257f061ab 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -1,3 +1,5 @@ +from __future__ import unicode_literals + from markdown import markdown from django import template @@ -60,6 +62,22 @@ def bettertitle(value): return ' '.join([w[0].upper() + w[1:] for w in value.split()]) +@register.filter() +def example_choices(value, arg=3): + """ + Returns a number (default: 3) of example choices for a ChoiceFiled (useful for CSV import forms). + """ + choices = [] + for id, label in value: + if len(choices) == arg: + choices.append('etc.') + break + if not id: + continue + choices.append(label) + return ', '.join(choices) or 'None found' + + # # Tags #