from django.shortcuts import render from django.http import HttpResponse from apps.synthea.forms import SyntheaForm from apps.synthea.models import Synthea from .lib.utils import run_synthea import mimetypes # Create your views here. def index(request): template_name = 'synthea/index.html' return render(request,template_name,{}) def api(request): template_name = 'synthea/api.html' return render(request,template_name,{}) def show_synthea_form(request): template_name = 'synthea/generator_form.html' # if this is a POST request we need to process the form data if request.method == 'POST': # create a form instance and populate it with data from the request: form = SyntheaForm(request.POST) # check whether it's valid: if form.is_valid(): # process the data in form.cleaned_data as required synthea = form.save() zipfile = synthea.generate() response = HttpResponse(zipfile.open('rb'), content_type='application/zip') response['Content-Disposition'] = f'attachment; filename={zipfile.name}' return response # if a GET (or any other method) we'll create a blank form else: form = SyntheaForm() return render(request,template_name,{ 'form':form })