Пример #1
0
def convert_marcxml(source):
    """Convert MARC XML to JSON."""
    from dojson.contrib.marc21.utils import create_record, split_blob

    from inspire.dojson.hep import hep
    from inspire.dojson.institutions import institutions
    from inspire.dojson.journals import journals
    from inspire.dojson.experiments import experiments
    from inspire.dojson.hepnames import hepnames
    from inspire.dojson.jobs import jobs
    from inspire.dojson.conferences import conferences

    for data in split_blob(source.read()):
        record = create_record(data)
        if _collection_in_record(record, 'institution'):
            yield institutions.do(record)
        elif _collection_in_record(record, 'experiment'):
            yield experiments.do(record)
        elif _collection_in_record(record, 'journals'):
            yield journals.do(record)
        elif _collection_in_record(record, 'hepnames'):
            yield hepnames.do(record)
        elif _collection_in_record(record, 'job') or \
                _collection_in_record(record, 'jobhidden'):
            yield jobs.do(record)
        elif _collection_in_record(record, 'conferences'):
            yield conferences.do(record)
        else:
            yield hep.do(record)
Пример #2
0
def update(recid):
    """View for INSPIRE author update form."""
    from dojson.contrib.marc21.utils import create_record
    from inspire.dojson.hepnames import hepnames

    data = {}
    if recid:
        try:
            url = os.path.join(cfg["AUTHORS_UPDATE_BASE_URL"], "record",
                               str(recid), "export", "xm")
            xml = requests.get(url)
            data = hepnames.do(create_record(xml.content.encode("utf-8")))
            convert_for_form(data)
        except requests.exceptions.RequestException:
            pass
        data["recid"] = recid
    else:
        return redirect(url_for("inspire_authors.new"))
    form = AuthorUpdateForm(data=data)
    ctx = {
        "action": url_for('.submitupdate'),
        "name": "authorUpdateForm",
        "id": "authorUpdateForm",
    }

    return render_template('authors/forms/update_form.html', form=form, **ctx)