Ejemplo n.º 1
0
def import_risk_data(filepath, risk_app_name, risk_analysis_name, region_name,
                     final_name, current_user_id):
    try:
        risk_analysis = RiskAnalysis.objects.get(name=risk_analysis_name)
    except RiskAnalysis.DoesNotExist:
        raise ValueError("Risk Analysis not found")
    risk_analysis.set_queued()
    out = StringIO.StringIO()
    try:
        risk_analysis.set_processing()

        call_command('importriskdata',
                     commit=False,
                     risk_app=risk_app_name,
                     region=region_name,
                     excel_file=filepath,
                     risk_analysis=risk_analysis_name,
                     stdout=out)
        risk_analysis.refresh_from_db()
        risk_analysis.data_file = final_name
        risk_analysis.save()
        risk_analysis.set_ready()
        complete_upload(current_user_id, final_name, region_name)
    except Exception, e:
        error_message = "Sorry, the input file is not valid: {}".format(e)
        if risk_analysis is not None:
            risk_analysis.save()
            risk_analysis.set_error()
        raise ValueError(error_message)
Ejemplo n.º 2
0
def import_event_data(filepath, risk_app_name, region_name, filename_ori,
                      current_user_id):
    out = StringIO.StringIO()
    try:
        call_command('importriskevents',
                     commit=False,
                     risk_app=risk_app_name,
                     region=region_name,
                     excel_file=filepath,
                     stdout=out)
        complete_upload(current_user_id, filename_ori, region_name)
    except Exception, e:
        error_message = "Sorry, the input file is not valid: {}".format(e)
        raise ValueError(error_message)
Ejemplo n.º 3
0
                     risk_app=risk_app_name,
                     region=region_name,
                     excel_file=filepath,
                     risk_analysis=risk_analysis_name,
                     stdout=out)
    except Exception, e:
        risk_analysis.save()
        risk_analysis.set_error()
        report_processing_error(current_user_id, final_name, region_name, e)
        return None

    risk_analysis.refresh_from_db()
    risk_analysis.data_file = final_name
    risk_analysis.save()
    risk_analysis.set_ready()
    complete_upload(current_user_id, final_name, region_name)


@shared_task
def import_risk_metadata(filepath, risk_app_name, risk_analysis_name,
                         region_name, final_name):
    try:
        risk_analysis = RiskAnalysis.objects.get(name=risk_analysis_name)
    except RiskAnalysis.DoesNotExist:
        raise ValueError("Risk Analysis not found")
    risk_analysis.set_queued()
    out = StringIO.StringIO()
    try:
        risk_analysis.set_processing()
        call_command('importriskmetadata',
                     commit=False,