293 | def import_form(request): |
294 | logger.info("__ input_forms import_form __") |
295 | if request.method == "POST": |
296 | json_file = request.FILES['file'] |
297 | json_string = json_file.read() |
298 | json_data = json.loads(json_string) |
299 | |
300 | template_options = json_data["template"] |
301 | form_options = json_data["form"] |
302 | |
303 | template = ConfigTemplate() |
304 | template.name = template_options["name"] |
305 | template.description = template_options["description"] |
306 | template.action_provider = template_options["action_provider"] |
307 | template.action_provider_options = template_options["action_provider_options"] |
308 | template.type = template_options["type"] |
309 | template.template = unquote(template_options["template"]) |
310 | |
311 | template.save() |
312 | |
313 | input_form = InputForm() |
314 | input_form.name = form_options["name"] |
315 | input_form.description = form_options["description"] |
316 | input_form.instructions = form_options["instructions"] |
317 | input_form.json = unquote(form_options["json"]) |
318 | input_form.script = template |
319 | |
320 | input_form.save() |
321 | |
322 | return HttpResponseRedirect("/input_forms") |
323 | else: |
324 | form = ImportForm() |
325 | context = {'form': form} |
326 | return render(request, 'input_forms/import.html', context) |