Fixes #1567: Prompt user for session key when importing secrets

This commit is contained in:
Jeremy Stretch
2017-10-10 13:22:40 -04:00
parent c300879995
commit 8403e91fc9
4 changed files with 9 additions and 67 deletions

View File

@@ -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)