示例#1
0
def process_payload(recid, file, redirect_url):
    if file and (allowed_file(file.filename)):
        errors = process_zip_archive(file, recid)
        if errors:
            return render_template('hepdata_records/error_page.html',
                                   redirect_url=redirect_url.format(recid),
                                   errors=errors)
        else:
            update_action_for_submission_participant(recid,
                                                     current_user.get_id(),
                                                     'uploader')
            return redirect(redirect_url.format(recid))
    else:
        return render_template(
            'hepdata_records/error_page.html',
            redirect_url=redirect_url.format(recid),
            message="Incorrect file type uploaded.",
            errors={
                "Submission": [{
                    "level":
                    "error",
                    "message":
                    "You must upload a .zip, .tar, .tar.gz or .tgz file" +
                    " (or a .oldhepdata or single .yaml file)."
                }]
            })
示例#2
0
def process_payload(recid, file, redirect_url, synchronous=False):
    """Process an uploaded file

    :param recid: int
        The id of the record to update
    :param file: file
        The file to process
    :param redirect_url: string
        Redirect URL to record, for use if the upload fails or in synchronous mode
    :param synchronous: bool
        Whether to process asynchronously via celery (default) or immediately (only recommended for tests)
    :return: JSONResponse either containing 'url' (for success cases) or
             'message' (for error cases, which will give a 400 error).
    """

    if file and (allowed_file(file.filename)):
        file_path = save_zip_file(file, recid)
        hepsubmission = get_latest_hepsubmission(publication_recid=recid)

        if hepsubmission.overall_status == 'finished':
            # If it is finished and we receive an update,
            # then we need to reopen the submission to allow for revisions,
            # by creating a new HEPSubmission object.
            _rev_hepsubmission = HEPSubmission(
                publication_recid=recid,
                overall_status='todo',
                inspire_id=hepsubmission.inspire_id,
                coordinator=hepsubmission.coordinator,
                version=hepsubmission.version + 1)
            db.session.add(_rev_hepsubmission)
            hepsubmission = _rev_hepsubmission

        previous_status = hepsubmission.overall_status
        hepsubmission.overall_status = 'sandbox_processing' if previous_status == 'sandbox' else 'processing'
        db.session.add(hepsubmission)
        db.session.commit()

        if synchronous:
            process_saved_file(file_path, recid, current_user.get_id(),
                               redirect_url, previous_status)
        else:
            process_saved_file.delay(file_path, recid, current_user.get_id(),
                                     redirect_url, previous_status)
            flash(
                'File saved. You will receive an email when the file has been processed.',
                'info')

        return jsonify({'url': redirect_url.format(recid)})
    else:
        return jsonify({
            "message":
            "You must upload a .zip, .tar, .tar.gz or .tgz file" +
            " (or a .oldhepdata or single .yaml or .yaml.gz file)."
        }), 400
示例#3
0
文件: api.py 项目: HEPData/hepdata3
def process_payload(recid, file, redirect_url):
    if file and (allowed_file(file.filename)):
        errors = process_zip_archive(file, recid)
        if errors:
            remove_submission(recid)
            return render_template('hepdata_records/error_page.html',
                                   recid=None, errors=errors)
        else:
            update_action_for_submission_participant(recid, current_user.get_id(), 'uploader')
            return redirect(redirect_url.format(recid))
    else:
        return render_template('hepdata_records/error_page.html', recid=recid,
                               message="Incorrect file type uploaded.",
                               errors={"Submission": [{"level": "error",
                                                       "message": "You must upload a .zip, .tar, or .tar.gz file."}]})
示例#4
0
def test_allowed_file():
    assert (allowed_file('test.zip'))
    assert (allowed_file('test.tar'))
    assert (allowed_file('test.tar.gz'))
    assert (not allowed_file('test.pdf'))
示例#5
0
def test_allowed_file():
    assert (allowed_file('test.zip'))
    assert (allowed_file('test.tar'))
    assert (allowed_file('test.tar.gz'))
    assert (not allowed_file('test.pdf'))