mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-18 11:22:25 -06:00
Added dynamic examples for CSV form fields
This commit is contained in:
@@ -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.'
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user