def report(request): context = {} tabID = request.GET.get('tabID') try: data = serialiser.deserialise(request.session[tabID]) except KeyError: return HttpResponseRedirect( '/upload/dev/' + "?error=sessionExpired") if request.session[tabID+'_referrer'] == 'errors': data.analysis() request.session[tabID+'_analysis()'] = True request.session[tabID+'_referrer'] = 'viewReport' request.session[tabID] = serialiser.serialise( data) form = ReportButton(None) context['form'] = form context['tabID'] = tabID return render( request, 'viewReport/index.html', context = context ) elif 'makeReport' in request.POST: report = Report(data, "") report_string = report.html_report() return HttpResponse( report_string ) elif 'downloadData' in request.POST: return HttpResponseRedirect( saveData(data) ) elif 'datatypetemplate' in request.POST: return HttpResponseRedirect( saveDatatypes(data) ) elif request.session[tabID+'_referrer'] == 'viewReport': form = ReportButton(None) context['form'] = form context['tabID'] = tabID return render( request, 'viewReport/index.html', context = context )
def invalid_rows(request): context = {} tabID = request.GET.get('tabID') try: data = serialiser.deserialise(request.session[tabID]) except KeyError: return HttpResponseRedirect( '/upload/dev/' + "?error=sessionExpired") if request.session[tabID+'_referrer'] == 'upload': data.remove_invalid() request.session[tabID+'_remove_invalid()'] = True form = SetErrorsForm(None, data=data) elif request.session[tabID+'_referrer'] == 'invalid_rows': data.rebuild_raw_data() data.remove_invalid() request.session[tabID+'_referrer'] = 'invalid_rows' if any("delete_" in s for s in request.POST): row = [s for s in request.POST if "delete_" in s] rowID = int(row[0][7:]) data.delete_invalid_row(rowID) data.rebuild_raw_data() data.remove_invalid() form = SetErrorsForm( None, data=data) elif "cancel" in request.POST: form = SetErrorsForm( None, data=data) elif "refresh" in request.POST: for i, row in enumerate(data.invalid_rows): data.invalid_rows[i] = processRowInput(request.POST["error_" + str(i)]) print(str(row) + "ROWLENGTH:: " + str(len(row)) ) data.rebuild_raw_data() data.remove_invalid() form = SetErrorsForm( None, data=data) elif "toNext" in request.POST: for i, row in enumerate(data.invalid_rows): data.invalid_rows[i] = processRowInput(request.POST["error_" + str(i)]) print(row) data.rebuild_raw_data() data.remove_invalid() request.session[tabID] = serialiser.serialise( data) return HttpResponseRedirect( '/datatypes/' + "?tabID=" + tabID) request.session[tabID] = serialiser.serialise( data) context['form'] = form context['tabID'] = tabID return render( request, 'invalid_rows/index.html', context = context )
def errors(request): context = {} tabID = request.GET.get('tabID') try: data = serialiser.deserialise(request.session[tabID]) except KeyError: return HttpResponseRedirect( '/upload/dev/' + "?error=sessionExpired") if request.session[tabID+'_referrer'] == 'datatypes': request.session[tabID+'_referrer'] = 'errors' data.find_errors() elif request.session[tabID+'_referrer'] == 'viewReport': pass # error about going back elif "toNext" in request.GET: for i, error in enumerate(data.errors): data.columns[error[1]].values[error[4]]=request.POST.get("error_"+errorID(error), data.columns[error[1]].values[error[4]]) request.session[tabID] = serialiser.serialise( data) return HttpResponseRedirect('/report/?tabID=' + tabID) elif "cancel" in request.POST: pass elif "refresh" in request.POST: for i, error in enumerate(data.errors): data.columns[error[1]].values[error[4]]=request.POST.get("error_"+errorID(error), data.columns[error[1]].values[error[4]]) data.clear_errors() data.find_errors() elif "toNext" in request.POST: for i, error in enumerate(data.errors): data.columns[error[1]].values[error[4]]=request.POST.get("error_"+errorID(error), data.columns[error[1]].values[error[4]]) data.clear_errors() data.find_errors() request.session[tabID] = serialiser.serialise( data) return HttpResponseRedirect('/report/?tabID=' + tabID) form = SetErrorsForm(None, data=data) request.session[tabID] = serialiser.serialise( data) context['form'] = form context['tabID'] = tabID return render( request, 'errors/index.html', context = context )
def datatypes(request): context = {} tabID = request.GET.get('tabID') try: data = serialiser.deserialise(request.session[tabID]) except KeyError: return HttpResponseRedirect( '/upload/dev/' + "?error=sessionExpired") if request.session[tabID+'_referrer'] == 'invalid_rows': data.create_columns() data.clean() data.pre_analysis() request.session[tabID+'_referrer'] = 'datatypes' elif 'toErrors' in request.POST: for i, column in enumerate(data.columns): column.type = request.POST[column.header] request.session[tabID] = serialiser.serialise( data) return HttpResponseRedirect( '/errors/' + "?tabID=" + tabID) elif 'refresh' in request.POST: for i, column in enumerate(data.columns): column.type = request.POST[column.header] request.session[tabID] = serialiser.serialise( data) elif 'cancel' in request.POST: pass elif request.method == 'POST': for i, column in enumerate(data.columns): column.type = request.POST[column.header] request.session[tabID] = serialiser.serialise( data) form = SetTypesForm(None, columns=data.columns) # pack data back into session informatio request.session[tabID] = serialiser.serialise( data) # Construct template context object context['form'] = form context['tabID'] = tabID # Render Page return render(request, 'datatypes/index.html', context = context, )