mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Clean up bulk import view
This commit is contained in:
@ -314,11 +314,20 @@ class BulkImportView(GetReturnURLMixin, BaseMultiObjectView):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def _get_form_fields(self):
|
def _get_form_fields(self):
|
||||||
# Exclude any fields which use a HiddenInput widget
|
form = self.model_form()
|
||||||
return {
|
required_fields = {}
|
||||||
name: field for name, field in self.model_form().fields.items()
|
optional_fields = {}
|
||||||
if type(field.widget) is not HiddenInput
|
|
||||||
}
|
# Return only visible fields, with required fields listed first
|
||||||
|
for field in form.visible_fields():
|
||||||
|
if field.is_hidden:
|
||||||
|
continue
|
||||||
|
elif field.field.required:
|
||||||
|
required_fields[field.name] = field.field
|
||||||
|
else:
|
||||||
|
optional_fields[field.name] = field.field
|
||||||
|
|
||||||
|
return {**required_fields, **optional_fields}
|
||||||
|
|
||||||
def _save_object(self, import_form, model_form, request):
|
def _save_object(self, import_form, model_form, request):
|
||||||
|
|
||||||
|
@ -103,87 +103,87 @@ Context:
|
|||||||
|
|
||||||
{% if fields %}
|
{% if fields %}
|
||||||
<div class="row my-3">
|
<div class="row my-3">
|
||||||
<div class="col col-md-12">
|
<div class="col col-md-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h5 class="card-header">{% trans "Field Options" %}</h5>
|
<h5 class="card-header">{% trans "Field Options" %}</h5>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<thead>
|
||||||
<th>{% trans "Field" %}</th>
|
<tr>
|
||||||
<th>{% trans "Required" %}</th>
|
<th>{% trans "Field" %}</th>
|
||||||
<th>{% trans "Accessor" %}</th>
|
<th>{% trans "Required" %}</th>
|
||||||
<th>{% trans "Description" %}</th>
|
<th>{% trans "Accessor" %}</th>
|
||||||
</tr>
|
<th>{% trans "Description" %}</th>
|
||||||
{% for name, field in fields.items %}
|
</tr>
|
||||||
<tr>
|
</thead>
|
||||||
<td>
|
<tbody>
|
||||||
<code>{% if field.required %}<strong>{% endif %}{{ name }}{% if field.required %}</strong>{% endif %}</code>
|
{% for name, field in fields.items %}
|
||||||
</td>
|
<tr>
|
||||||
<td>
|
<td class="font-monospace{% if field.required %} fw-bold{% endif %}">
|
||||||
{% if field.required %}
|
{{ name }}
|
||||||
{% checkmark True true="Required" %}
|
</td>
|
||||||
{% else %}
|
<td>
|
||||||
{{ ''|placeholder }}
|
{% if field.required %}
|
||||||
{% endif %}
|
{% checkmark True true="Required" %}
|
||||||
</td>
|
{% else %}
|
||||||
<td>
|
{{ ''|placeholder }}
|
||||||
{% if field.to_field_name %}
|
{% endif %}
|
||||||
<code>{{ field.to_field_name }}</code>
|
</td>
|
||||||
{% else %}
|
{% if field.to_field_name %}
|
||||||
{{ ''|placeholder }}
|
<td class="font-monospace">{{ field.to_field_name }}</td>
|
||||||
{% endif %}
|
{% else %}
|
||||||
</td>
|
<td>{{ ''|placeholder }}</td>
|
||||||
<td>
|
{% endif %}
|
||||||
{% if field.STATIC_CHOICES %}
|
<td>
|
||||||
<button type="button" class="btn btn-link float-end" data-bs-toggle="modal" data-bs-target="#{{ name }}_choices">
|
{% if field.help_text %}
|
||||||
<i class="mdi mdi-help-circle"></i>
|
{{ field.help_text }}
|
||||||
</button>
|
{% elif field.label %}
|
||||||
<div class="modal fade" id="{{ name }}_choices" tabindex="-1" role="dialog">
|
{{ field.label }}
|
||||||
<div class="modal-dialog" role="document">
|
{% endif %}
|
||||||
<div class="modal-content">
|
{% if field.STATIC_CHOICES %}
|
||||||
<div class="modal-header">
|
<a href="#" data-bs-toggle="modal" data-bs-target="#{{ name }}_choices"><i class="mdi mdi-help-circle"></i></a>
|
||||||
<h5 class="modal-title"><code>{{ name }}</code> {% trans "Choices" %}</h5>
|
<div class="modal fade" id="{{ name }}_choices" tabindex="-1" role="dialog">
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<div class="modal-dialog" role="document">
|
||||||
</div>
|
<div class="modal-content">
|
||||||
<div class="modal-body">
|
<div class="modal-header">
|
||||||
<table class="table table-striped">
|
<h5 class="modal-title">
|
||||||
<tr>
|
<span class="font-monospace">{{ name }}</span> {% trans "Choices" %}
|
||||||
<th>{% trans "Import Value" %}</th>
|
</h5>
|
||||||
<th>{% trans "Label" %}</th>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
</tr>
|
</div>
|
||||||
{% for value, label in field.choices %}
|
<table class="table table-striped modal-body">
|
||||||
{% if value %}
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<th>{% trans "Import Value" %}</th>
|
||||||
<samp>{{ value }}</samp>
|
<th>{% trans "Label" %}</th>
|
||||||
</td>
|
</tr>
|
||||||
<td>
|
</thead>
|
||||||
{{ label }}
|
<tbody>
|
||||||
</td>
|
{% for value, label in field.choices %}
|
||||||
</tr>
|
{% if value %}
|
||||||
{% endif %}
|
<tr>
|
||||||
{% endfor %}
|
<td><samp>{{ value }}</samp></td>
|
||||||
</table>
|
<td>{{ label }}</td>
|
||||||
</div>
|
</tr>
|
||||||
</div>
|
{% endif %}
|
||||||
</div>
|
{% endfor %}
|
||||||
</div>
|
</tbody>
|
||||||
{% endif %}
|
</table>
|
||||||
{% if field.help_text %}
|
</div>
|
||||||
{{ field.help_text }}<br />
|
</div>
|
||||||
{% elif field.label %}
|
</div>
|
||||||
{{ field.label }}<br />
|
{% endif %}
|
||||||
{% endif %}
|
{% if field|widget_type == 'dateinput' %}
|
||||||
{% if field|widget_type == 'dateinput' %}
|
<br /><small class="text-muted">{% trans "Format: YYYY-MM-DD" %}</small>
|
||||||
<small class="text-muted">{% trans "Format: YYYY-MM-DD" %}</small>
|
{% elif field|widget_type == 'checkboxinput' %}
|
||||||
{% elif field|widget_type == 'checkboxinput' %}
|
<br /><small class="text-muted">{% trans "Specify true or false" %}</small>
|
||||||
<small class="text-muted">{% trans "Specify true or false" %}</small>
|
{% endif %}
|
||||||
{% endif %}
|
</td>
|
||||||
</td>
|
</tr>
|
||||||
</tr>
|
{% endfor %}
|
||||||
{% endfor %}
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="small text-muted">
|
<p class="small text-muted">
|
||||||
<i class="mdi mdi-check-bold text-success"></i>
|
<i class="mdi mdi-check-bold text-success"></i>
|
||||||
|
Reference in New Issue
Block a user