diff --git a/netbox/project-static/js/secrets.js b/netbox/project-static/js/secrets.js
index d1ec3d883..a592330fd 100644
--- a/netbox/project-static/js/secrets.js
+++ b/netbox/project-static/js/secrets.js
@@ -18,7 +18,7 @@ $(document).ready(function() {
$('form').submit(function(event) {
$(this).find('.requires-session-key').each(function() {
if (this.value && document.cookie.indexOf('session_key') == -1) {
- console.log('Field ' + this.value + ' requires a session key');
+ console.log('Field ' + this.name + ' requires a session key');
$('#privkey_modal').modal('show');
event.preventDefault();
return false;
diff --git a/netbox/secrets/views.py b/netbox/secrets/views.py
index 6197faf10..e7f6939a9 100644
--- a/netbox/secrets/views.py
+++ b/netbox/secrets/views.py
@@ -203,7 +203,9 @@ class SecretBulkImportView(BulkImportView):
permission_required = 'ipam.add_vlan'
model_form = forms.SecretCSVForm
table = tables.SecretTable
+ template_name = 'secrets/secret_import.html'
default_return_url = 'secrets:secret_list'
+ widget_attrs = {'class': 'requires-session-key'}
master_key = None
diff --git a/netbox/templates/secrets/secret_import.html b/netbox/templates/secrets/secret_import.html
index 1f12494ec..a460f80e8 100644
--- a/netbox/templates/secrets/secret_import.html
+++ b/netbox/templates/secrets/secret_import.html
@@ -1,70 +1,8 @@
-{% extends '_base.html' %}
+{% extends 'utilities/obj_import.html' %}
{% load static from staticfiles %}
-{% load form_helpers %}
{% block content %}
-
{% block title %}Secret Import{% endblock %}
-
-
- {% if form.non_field_errors %}
-
-
Errors
-
- {{ form.non_field_errors }}
-
-
- {% endif %}
-
-
-
-
CSV Format
-
-
-
- Field |
- Description |
- Example |
-
-
-
-
- Device |
- Name of the parent device |
- edge-router1 |
-
-
- Role |
- Functional role |
- Login Credentials |
-
-
- Name (optional) |
- Username or other label |
- root |
-
-
- Secret |
- Secret data |
- MyP@ssw0rd! |
-
-
-
-
Example
-
edge-router1,Login Credentials,root,MyP@ssw0rd!
-
-
-
+{{ block.super }}
{% include 'secrets/inc/private_key_modal.html' %}
{% endblock %}
diff --git a/netbox/utilities/views.py b/netbox/utilities/views.py
index 89acf5bcb..d7b82236c 100644
--- a/netbox/utilities/views.py
+++ b/netbox/utilities/views.py
@@ -10,7 +10,7 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db import transaction, IntegrityError
from django.db.models import ProtectedError
-from django.forms import CharField, Form, ModelMultipleChoiceField, MultipleHiddenInput, TypedChoiceField
+from django.forms import CharField, Form, ModelMultipleChoiceField, MultipleHiddenInput, Textarea, TypedChoiceField
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.template import TemplateSyntaxError
@@ -380,11 +380,13 @@ class BulkImportView(View):
table: The django-tables2 Table used to render the list of imported objects
template_name: The name of the template
default_return_url: The name of the URL to use for the cancel button
+ widget_attrs: A dict of attributes to apply to the import widget (e.g. to require a session key)
"""
model_form = None
table = None
default_return_url = None
template_name = 'utilities/obj_import.html'
+ widget_attrs = {}
def _import_form(self, *args, **kwargs):
@@ -392,7 +394,7 @@ class BulkImportView(View):
required_fields = [name for name, field in self.model_form().fields.items() if field.required]
class ImportForm(BootstrapMixin, Form):
- csv = CSVDataField(fields=fields, required_fields=required_fields)
+ csv = CSVDataField(fields=fields, required_fields=required_fields, widget=Textarea(attrs=self.widget_attrs))
return ImportForm(*args, **kwargs)