Exemplo n.º 1
0
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
    )
Exemplo n.º 2
0
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
        )
Exemplo n.º 3
0
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
    )
Exemplo n.º 4
0
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,
    )
Exemplo n.º 5
0
def upload(request):
    #Handle file upload
    if request.method == 'GET' and 'error' in request.GET:
        print("error")
        form = DocumentForm() # An empty form
        sessionExpired = True

    elif request.method == 'POST' and "viewReport" in request.POST:
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            dataDoc = Document(docfile = request.FILES['dataFile'])
            dataDoc.save()
            data = None
            if 'templateFile' in request.FILES:
                templateDoc = Document(docfile = request.FILES['templateFile'])
                templateDoc.save()
                templateObject = Template(templateDoc.getPath())
                data = Data(dataDoc.getPath(), templateObject)
                templateDoc.delete()
            else:
                data = Data(dataDoc.getPath())
            # Load data from CSV
            #data = Data(dataDoc.getPath())
            data.filename = dataDoc.getName()
            # Perform Analysis
            data.remove_invalid()
            data.create_columns()
            data.clean()
            data.pre_analysis()
            data.find_errors()
            data.analysis() 
            # Generate Report
            report = Report(data, dataDoc.getPath())
            report_string = report.html_report()
            # Delete uploaded CSV file & report from server
            dataDoc.delete()
            return HttpResponse( report_string )

    elif request.method == 'POST' and "viewOptions" in request.POST:
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            dataDoc = Document(docfile = request.FILES['dataFile'])
            dataDoc.save()
            if 'templateFile' in request.FILES:
                templateDoc = Document(docfile = request.FILES['templateFile'])
                templateDoc.save()
                templateObject = Template(templateDoc.getPath())
                data = Data(dataDoc.getPath(), templateObject)
                templateDoc.delete()
            else:
                data = Data(dataDoc.getPath())
            data.filename = dataDoc.getName()
            dataDoc.delete()
            request.session.set_expiry(0)
            tabID = hasher.makeTabID()
            request.session[tabID] = serialiser.serialise( data)
            request.session[tabID+'_remove_invalid()'] = False
            request.session[tabID+'_create_columns()'] = False
            request.session[tabID+'_clean()'] = False
            request.session[tabID+'_pre_analysis()'] = False
            request.session[tabID+'_find_errors()'] = False
            request.session[tabID+'_analysis()'] = False
            request.session[tabID+'_referrer'] = 'upload'
            #Redirect to the generated report after POST
            return HttpResponseRedirect( '/invalid_rows' + "?tabID=" + tabID)

    else:
        form = DocumentForm() # An empty form

    # Contstruct template context object
    context = {}
    context['form'] = form
    try:
        context['tabID'] = tabID
    except NameError:
        context['tabID'] = None

    try:
        context['sessionExpired'] = sessionExpired
    except:
        context['sessionExpired'] = False
    # Render the form
    return render( request,
        'upload/index.html',
        context = context,
        )