Пример #1
0
def fixture_upload_async(domain, download_id, replace):
    task = fixture_upload_async
    DownloadBase.set_progress(task, 0, 100)
    download_ref = DownloadBase.get(download_id)
    result = upload_fixture_file(domain, download_ref.get_filename(), replace, task)
    DownloadBase.set_progress(task, 100, 100)
    return {"messages": result}
Пример #2
0
def fixture_upload_async(domain,
                         download_id,
                         replace,
                         skip_orm,
                         user_email=None):
    task = fixture_upload_async
    DownloadBase.set_progress(task, 0, 100)
    download_ref = DownloadBase.get(download_id)
    time_start = datetime.datetime.now()
    result = upload_fixture_file(domain, download_ref.get_filename(), replace,
                                 task, skip_orm)
    time_end = datetime.datetime.now()
    DownloadBase.set_progress(task, 100, 100)
    messages = {
        'success': result.success,
        'messages': result.messages,
        'errors': result.errors,
        'number_of_fixtures': result.number_of_fixtures
    }
    if user_email:
        send_upload_fixture_complete_email(user_email, domain, time_start,
                                           time_end, messages)
    return {
        'messages': messages,
    }
Пример #3
0
def fixture_upload_async(domain, download_id, replace):
    task = fixture_upload_async
    DownloadBase.set_progress(task, 0, 100)
    download_ref = DownloadBase.get(download_id)
    result = upload_fixture_file(domain, download_ref.get_filename(), replace, task)
    DownloadBase.set_progress(task, 100, 100)
    return {
        'messages': result,
    }
Пример #4
0
def fixture_upload_async(domain, download_id, replace, skip_orm):
    task = fixture_upload_async
    DownloadBase.set_progress(task, 0, 100)
    download_ref = DownloadBase.get(download_id)
    result = upload_fixture_file(domain, download_ref.get_filename(), replace, task, skip_orm)
    DownloadBase.set_progress(task, 100, 100)
    return {
        'messages': {
            'success': result.success,
            'messages': result.messages,
            'errors': result.errors,
            'number_of_fixtures': result.number_of_fixtures,
        },
    }
Пример #5
0
def _upload_fixture_api(request, domain):
    try:
        excel_file, replace, is_async = _get_fixture_upload_args_from_request(request, domain)
    except FixtureAPIRequestError as e:
        return UploadFixtureAPIResponse('fail', six.text_type(e))

    with excel_file as filename:

        if is_async:
            with open(filename, 'r') as f:
                file_ref = expose_cached_download(
                    f.read(),
                    file_extension=file_extention_from_filename(filename),
                    expiry=1 * 60 * 60,
                )
                download_id = file_ref.download_id
                task = fixture_upload_async.delay(
                    domain,
                    download_id,
                    replace,
                )
                file_ref.set_task(task)

                status_url = "{}{}".format(
                    get_url_base(),
                    reverse('fixture_api_status', args=(domain, download_id))
                )

                curl_command = "curl -v --digest {} -u {}".format(
                    status_url, request.user.username
                )

                return UploadFixtureAPIResponse('success', {
                    "download_id": download_id,
                    "status_url": status_url,
                    "curl_command": curl_command,
                    "message": _("File uploaded successfully.")
                })

        try:
            validate_fixture_file_format(filename)
        except FixtureUploadError as e:
            return UploadFixtureAPIResponse(
                'fail',
                _('Please fix the following formatting issues in your Excel file: %s')
                % '\n'.join(e.errors))

        result = upload_fixture_file(domain, filename, replace=replace)
        status = 'warning' if result.errors else 'success'
        return UploadFixtureAPIResponse(status, result.get_display_message())
Пример #6
0
def _upload_fixture_api(request, domain):
    try:
        excel_file, replace = _get_fixture_upload_args_from_request(request, domain)
    except FixtureAPIRequestError as e:
        return UploadFixtureAPIResponse('fail', e.message)

    with excel_file as filename:
        try:
            validate_fixture_file_format(filename)
        except FixtureUploadError as e:
            return UploadFixtureAPIResponse(
                'fail',
                _('Please fix the following formatting issues in your Excel file: %s')
                % '\n'.join(e.errors))

        result = upload_fixture_file(domain, filename, replace=replace)
        status = 'warning' if result.errors else 'success'
        return UploadFixtureAPIResponse(status, result.get_display_message())
Пример #7
0
def _upload_fixture_api(request, domain):
    try:
        excel_file, replace = _get_fixture_upload_args_from_request(request, domain)
    except FixtureAPIRequestError as e:
        return UploadFixtureAPIResponse('fail', e.message)

    with excel_file as filename:
        try:
            validate_fixture_file_format(filename)
        except FixtureUploadError as e:
            return UploadFixtureAPIResponse(
                'fail',
                _(u'Please fix the following formatting issues in your excel file: %s')
                % '\n'.join(e.errors))

        result = upload_fixture_file(domain, filename, replace=replace)
        status = 'warning' if result.errors else 'success'
        return UploadFixtureAPIResponse(status, result.get_display_message())
Пример #8
0
def _upload_fixture_api(request, domain):
    try:
        excel_file, replace, is_async, skip_orm, email = _get_fixture_upload_args_from_request(
            request, domain)
    except FixtureAPIRequestError as e:
        return UploadFixtureAPIResponse('fail', str(e))

    with excel_file as filename:

        if is_async:
            with open(filename, 'rb') as f:
                file_ref = expose_cached_download(
                    f.read(),
                    file_extension=file_extention_from_filename(filename),
                    expiry=1 * 60 * 60,
                )
                download_id = file_ref.download_id
                task = fixture_upload_async.delay(domain,
                                                  download_id,
                                                  replace,
                                                  skip_orm,
                                                  user_email=email)
                file_ref.set_task(task)

                status_url = "{}{}".format(
                    get_url_base(),
                    reverse('fixture_api_status', args=(domain, download_id)))

                return AsyncUploadFixtureAPIResponse(
                    'success',
                    _("File has been uploaded successfully and is queued for processing."
                      ), download_id, status_url)

        try:
            validate_fixture_file_format(filename)
        except FixtureUploadError as e:
            return UploadFixtureAPIResponse(
                'fail',
                _('Please fix the following formatting issues in your Excel file: %s'
                  ) % '\n'.join(e.errors))

        result = upload_fixture_file(domain, filename, replace=replace)
        status = 'warning' if result.errors else 'success'
        return UploadFixtureAPIResponse(status, result.get_display_message())