def load_view(request): """Renders the load page.""" if request.method == 'POST': form = load_form(request.POST) form.is_valid() ci_filename = form.cleaned_data['ci_filename_field'] cimap_filename = form.cleaned_data['cimap_filename_field'] # called form loadresults.html if 'load_survey' in form.data: load.load_survey(request, ci_filename, cimap_filename) # called from load.html if form.is_valid(): cft_filename = form.cleaned_data['cft_filename_field'] excel_choices = form.cleaned_data['excel_choices_field'] excel_filename = form.cleaned_data['excel_filename_field'] indexname = form.cleaned_data['indexname_field'] ci_filename = form.cleaned_data['ci_filename_field'] cimap_filename = form.cleaned_data['cimap_filename_field'] if 'load_scentemotion' in form.data: load.load_scentemotion(cft_filename) if 'load_excel' in form.data: if not load.load_excel(excel_filename, excel_choices, indexname): form.add_form_error( "Could not retrieve or index excel file") if 'map_survey' in form.data: field_map, col_map, header_map = load.map_survey( ci_filename, cimap_filename) qa = {} for question, answers in survey.qa.items(): qa[question] = list(answers.keys()) context = { 'form': form, 'col_map': col_map, 'header_map': header_map, 'qa': qa, } return render(request, 'app/loadresults.html', context) if 'return_survey' in form.data: pass return render(request, 'app/load.html', { 'form': form, 'es_hosts': insights_etl.settings.ES_HOSTS }) else: form = load_form(initial={'excel_choices_field': ['recreate']}) return render(request, 'app/load.html', { 'form': form, 'es_hosts': insights_etl.settings.ES_HOSTS }, context_instance=RequestContext( request, { 'message': 'IFF - Insight Platform', 'year': datetime.now().year, }))
def load_view(request): """Renders the load page.""" if request.method == 'POST': form = load_form(request.POST) form.is_valid() ci_filename = form.cleaned_data['ci_filename_field'] cimap_filename = form.cleaned_data['cimap_filename_field'] # called form loadresults.html if 'load_survey' in form.data: load.load_survey(request, ci_filename, cimap_filename) # called from load.html if form.is_valid(): cft_filename = form.cleaned_data['cft_filename_field'] recipes_foldername = form.cleaned_data['recipes_foldername_field'] excel_choices = form.cleaned_data['excel_choices_field'] excel_filename = form.cleaned_data['excel_filename_field'] excelmap_filename = form.cleaned_data['excelmap_filename_field'] cmis_choices = form.cleaned_data['cmis_choices_field'] cmis_foldername = form.cleaned_data['cmis_foldername_field'] cmis_objtype = form.cleaned_data['cmis_objtype_field'] email_choices = form.cleaned_data['email_choices_field'] email_address = form.cleaned_data['email_address_field'] email_password = form.cleaned_data['email_password_field'] index_doc_name = form.cleaned_data['index_doc_name_field'] ci_filename = form.cleaned_data['ci_filename_field'] cimap_filename = form.cleaned_data['cimap_filename_field'] if 'load_bestmatch' in form.data: load.load_bestmatch(cft_filename) if 'load_recipes' in form.data: load.load_recipes(recipes_foldername) if 'load_excel' in form.data: if not load.load_excel(excel_filename, excelmap_filename, excel_choices, index_doc_name): form.add_form_error( "Could not retrieve or index excel file") if 'load_cmis' in form.data: if not cmis.load_cmis(cmis_foldername, cmis_objtype, cmis_choices): form.add_form_error( "Could not retrieve or index excel file") if 'load_mail' in form.data: if not load.load_mail(email_choices, email_address, email_password): form.add_form_error("Could not retrieve mailbox") if 'map_survey' in form.data: field_map, col_map, header_map = load.map_survey( ci_filename, cimap_filename) qa = {} for question, answers in survey.qa.items(): qa[question] = list(answers.keys()) context = { 'form': form, 'col_map': col_map, 'header_map': header_map, 'qa': qa, } return render(request, 'app/loadresults.html', context) if 'return_survey' in form.data: pass return render( request, 'app/load.html', { 'site': FMI.settings.site, 'form': form, 'es_hosts': FMI.settings.ES_HOSTS, 'year': datetime.now().year }) else: form = load_form(initial={ 'excel_choices_field': ['recreate'], 'email_choices_field': ['imap'] }) return render( request, 'app/load.html', { 'site': FMI.settings.site, 'form': form, 'es_hosts': FMI.settings.ES_HOSTS, 'year': datetime.now().year })