當前位置: 首頁>>代碼示例>>Python>>正文


Python Record.create方法代碼示例

本文整理匯總了Python中invenio.modules.records.api.Record.create方法的典型用法代碼示例。如果您正苦於以下問題:Python Record.create方法的具體用法?Python Record.create怎麽用?Python Record.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在invenio.modules.records.api.Record的用法示例。


在下文中一共展示了Record.create方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_jsonalchemy_toint_usage

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_jsonalchemy_toint_usage(self):
        """Test the usage of ``to_int`` function in real life example.

        The ``test_toint`` model contains a field which contains an integer
        subfield. Whenever the record is obtained from ``MARCXML``, the
        string in mentioned subfield has to be converted to an integer.

        However, JSONAlchemy fills every absent subfield with a ``None`` value.
        If the record is not provided with the integer subfield and the
        built-in ``int`` function is used, the code will crash.

        The ``to_int`` function used inside definition of ``test_toint`` field
        prevents it. Here the unprovided subfield is ``999__a``.
        """
        xml = '<collection><record><datafield tag="999" ind1="" ind2= "">' \
              '<subfield code="b">Value</subfield></datafield></record>' \
              '</collection>'
        from invenio.modules.records.api import Record
        simple_record = Record.create(xml, master_format='marc',
                                      model="test_toint",
                                      namespace='testsuite')

        self.assertEqual(len(simple_record.__dict__['_dict']['__meta_metadata__']['__errors__']), 0)

        # Check if it works when the value is provided.
        xml = '<collection><record><datafield tag="999" ind1="" ind2= "">' \
              '<subfield code="a">9999</subfield>' \
              '<subfield code="b">Value</subfield></datafield></record>' \
              '</collection>'

        simple_record = Record.create(xml, master_format='marc',
                                      model="test_toint",
                                      namespace='testsuite')
        self.assertEqual(simple_record['with_integers'][0]['some_int'], 9999)
開發者ID:SCOAP3,項目名稱:invenio,代碼行數:36,代碼來源:test_functions.py

示例2: test_subjects_gnd

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_subjects_gnd(self):
        """Test contributor rules."""
        from invenio.modules.records.api import Record
        r = Record.create({'subjects': [
                {'term': 'Smith, John',
                 'identifier': 'gnd:118604740',
                 'scheme': 'gnd'},
            ]}, 'json')

        # Test that "gnd:" is not added in MARC
        print(r.produce('json_for_marc'))
        assert {'6501_a': 'Smith, John', '6501_0': '(gnd)118604740'} \
            in r.produce('json_for_marc')

        r = Record.create(
            '<record>'
            '<datafield tag="650" ind1="1" ind2=" ">'
            '<subfield code="a">Smith, John</subfield>'
            '<subfield code="0">(gnd)118604740</subfield>'
            '</datafield>'
            '</record>',
            master_format='marc'
        )

        # Test that "gnd:" is added back in JSON
        assert r['subjects'] == [{
            'identifier': 'gnd:118604740',
            'scheme': 'gnd',
            'term': 'Smith, John'}]
開發者ID:bruno314,項目名稱:zenodo,代碼行數:31,代碼來源:test_jsonext.py

示例3: test_gnd

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_gnd(self):
        """Test contributor rules."""
        from invenio.modules.records.api import Record
        r = Record.create({'contributors': [
                {'name': 'Smith, John',
                 'gnd': 'gnd:118604740',
                 'type': 'DataCurator'},
            ]}, 'json')

        print r.produce('json_for_marc')
        # Test that "gnd:" is not added in MARC
        assert {'700__0': ['(gnd)118604740', None],
                '700__4': 'cur',
                '700__a': 'Smith, John'} \
            in r.produce('json_for_marc')

        r = Record.create(
            '<record>'
            '<datafield tag="700" ind1=" " ind2=" ">'
            '<subfield code="4">cur</subfield>'
            '<subfield code="a">Smith, John</subfield>'
            '<subfield code="0">(gnd)118604740</subfield>'
            '</datafield>'
            '</record>',
            master_format='marc'
        )

        # Test that "gnd:" is added back in JSON
        print r['contributors']
        assert r['contributors'] == [{
            'gnd': 'gnd:118604740',
            'name': 'Smith, John',
            'orcid': '',
            'type': 'DataCurator'
        }]
開發者ID:bruno314,項目名稱:zenodo,代碼行數:37,代碼來源:test_jsonext.py

示例4: test_types

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_types(self):
        """Test upload_type rules."""
        from invenio.modules.records.api import Record

        for t in cfg['UPLOAD_TYPES']:
            if t['subtypes']:
                for st in t['subtypes']:
                    r = Record.create(
                        '<record><datafield tag="980" ind1=" " ind2=" ">'
                        '<subfield code="b">{1}</subfield>'
                        '<subfield code="a">{0}</subfield>'
                        '</datafield></record>'.format(t['type'], st['type']),
                        master_format='marc'
                    )
                    assert r['upload_type'] == {"type": t['type'],
                                                "subtype": st['type']}
                    assert len(r.get('collections', [])) == 0
            else:
                r = Record.create(
                    '<record><datafield tag="980" ind1=" " ind2=" ">'
                    '<subfield code="a">{0}</subfield>'
                    '</datafield></record>'.format(t['type']),
                    master_format='marc'
                )
                assert r['upload_type'] == {"type": t['type']}
                assert len(r.get('collections', [])) == 0
開發者ID:bruno314,項目名稱:zenodo,代碼行數:28,代碼來源:test_jsonext.py

示例5: update

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
def update(recid):
    """View for INSPIRE author update form."""
    # Store referrer in session for later redirection to original page
    session["author_update_referrer"] = request.referrer
    data = {}
    if recid:
        try:
            url = os.path.join(cfg["AUTHORS_UPDATE_BASE_URL"], "record",
                               str(recid), "export", "xm")
            xml = requests.get(url)
            data = Record.create(xml.text.encode("utf-8"), 'marc',
                                 model='author').produce("json_for_form")
            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)
開發者ID:Lilykos,項目名稱:inspire-next,代碼行數:28,代碼來源:views.py

示例6: test_jsonalchemy_tooldvalue

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_jsonalchemy_tooldvalue(self):
        """Test behaviour of ``set_default_value``.

        In this example, the value provided to the reader in ``d`` subfield
        is in wrong format. However, the behaviour of ``JSONAlchemy`` in such
        case is to skip the value.

        Given the below value of the subfield, the module crashes in
        ``set_default_value``. The error has been caught.
        What is the reason behind the mentioned behaviour needs further
        investigation.
        """
        from invenio.modules.records.api import Record

        # Check if it works when the value is provided.
        xml = '''<collection><record><datafield tag="100" ind1=" " ind2=" ">
              <subfield code="a">Guy, Bobby</subfield>
              <subfield code="d">I like trains</subfield>
              <subfield code="g">ACTIVE</subfield>
              <subfield code="q">Bobby Guy</subfield>
              </datafield></record></collection>'''

        simple_record = Record.create(xml, master_format='marc',
                                      model="test_oldvalue",
                                      namespace='testsuite')
        self.assertEqual(simple_record['dates']['birth'], None)
開發者ID:SCOAP3,項目名稱:invenio,代碼行數:28,代碼來源:test_oldvalue.py

示例7: test_lossless_marc_import_export

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_lossless_marc_import_export(self):
        from invenio.modules.records.api import Record

        r = Record.create(test_marc, master_format="marc").dumps()

        for k in test_record.keys():
            self.assertEqual(test_record[k], r[k])
開發者ID:LibrarPotter,項目名稱:zenodo,代碼行數:9,代碼來源:test_jsonext.py

示例8: test_json_for_ld

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_json_for_ld(self):
        from invenio.modules.records.api import Record
        r = Record.create({'title': 'Test'}, 'json')

        import copy
        r = Record(json=copy.copy(test_record), master_format='marc')
        r.produce('json_for_ld')
開發者ID:bruno314,項目名稱:zenodo,代碼行數:9,代碼來源:test_jsonext.py

示例9: _create_marcxml_record

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
 def _create_marcxml_record(obj, eng):
     from invenio.modules.records.api import Record
     obj.log.info("Creating marcxml record")
     x = Record.create(obj.data, 'json', model='author')
     obj.extra_data["marcxml"] = x.legacy_export_as_marc()
     obj.log.info("Produced MarcXML: \n {}".format(
         obj.extra_data["marcxml"])
     )
開發者ID:annetteholtkamp,項目名稱:inspire-next,代碼行數:10,代碼來源:tasks.py

示例10: marshal_deposition

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def marshal_deposition(cls, deposition):
        """
        Generate a JSON representation for REST API of a Deposition
        """
        # Get draft
        if deposition.has_sip() and '_edit' in deposition.drafts:
            draft = deposition.get_draft('_edit')
            metadata_fields = cls.marshal_metadata_edit_fields
        elif deposition.has_sip():
            # FIXME: Not based on latest available data in record.
            sip = deposition.get_latest_sip(sealed=True)
            draft = record_to_draft(
                Record.create(sip.package, master_format='marc'),
                post_process=process_draft
            )
            metadata_fields = cls.marshal_metadata_edit_fields
        else:
            draft = deposition.get_or_create_draft('_metadata')
            metadata_fields = cls.marshal_metadata_fields

        # Fix known differences in marshalling
        current_app.logger.debug(draft.values)
        draft.values = filter_empty_elements(draft.values)
        current_app.logger.debug(draft.values)

        # Set disabled values to None in output
        for field, flags in draft.flags.items():
            if 'disabled' in flags and field in draft.values:
                current_app.logger.debug(field)
                del draft.values[field]

        # Marshal deposition
        obj = marshal(deposition, cls.marshal_deposition_fields)
        # Marshal the metadata attribute
        obj['metadata'] = marshal(unicodifier(draft.values), metadata_fields)

        # Add record and DOI information from latest SIP
        for sip in deposition.sips:
            if sip.is_sealed():
                recjson = sip.metadata
                if recjson.get('recid'):
                    obj['record_id'] = fields.Integer().format(
                        recjson.get('recid')
                    )
                    obj['record_url'] = fields.String().format(url_for(
                        'record.metadata',
                        recid=recjson.get('recid'),
                        _external=True
                    ))
                if (recjson.get('doi') and recjson.get('doi').startswith(
                        cfg['CFG_DATACITE_DOI_PREFIX'] + "/")):
                    obj['doi'] = fields.String().format(recjson.get('doi'))
                    obj['doi_url'] = fields.String().format(
                        "http://dx.doi.org/%s" % obj['doi']
                    )
                break

        return obj
開發者ID:rsalas82,項目名稱:lw-daap,代碼行數:60,代碼來源:upload.py

示例11: test_pre1900_embargo_date

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
 def test_pre1900_embargo_date(self):
     from invenio.modules.records.api import Record
     r = Record.create(
         '<record><datafield tag="942" ind1="" ind2="">'
         '<subfield code="a">0900-12-31</subfield>'
         '</datafield></record>', master_format='marc'
     )
     self.assertEqual(date(900, 12, 31), r['embargo_date'])
     self.assertEqual('0900-12-31', r.dumps()['embargo_date'])
     assert '0900-12-31' in r.legacy_export_as_marc()
開發者ID:SDSG-Invenio,項目名稱:zenodo,代碼行數:12,代碼來源:test_jsonext.py

示例12: test_json_for_ld

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_json_for_ld(self):
        from invenio.modules.records.api import Record

        r = Record.create({"title": "Test"}, "json")

        import copy

        r = Record(json=copy.copy(test_record), master_format="marc")

        ld = r.produce("json_for_ld")
        print(ld)
開發者ID:LibrarPotter,項目名稱:zenodo,代碼行數:13,代碼來源:test_jsonext.py

示例13: test_json_for_form

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_json_for_form(self):
        from invenio.modules.records.api import Record
        r = Record.create({'title': 'Test'}, 'json')
        assert r.produce('json_for_form')['title'] == 'Test'
        assert {'245__a': 'Test'} in r.produce('json_for_marc')

        import copy
        r = Record(json=copy.copy(test_record), master_format='marc')

        form_json = r.produce('json_for_form')
        for k, v in test_form_json.items():
            self.assertEqual(form_json[k], test_form_json[k])
開發者ID:SDSG-Invenio,項目名稱:zenodo,代碼行數:14,代碼來源:test_jsonext.py

示例14: test_pre1900_publication_date

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
    def test_pre1900_publication_date(self):
        from invenio.modules.records.api import Record

        r = Record.create(
            '<record><datafield tag="260" ind1="" ind2="">'
            '<subfield code="c">0900-12-31</subfield>'
            "</datafield></record>",
            master_format="marc",
        )
        self.assertEqual(date(900, 12, 31), r["publication_date"])
        self.assertEqual("0900-12-31", r.dumps()["publication_date"])
        assert "0900-12-31" in r.legacy_export_as_marc()
開發者ID:LibrarPotter,項目名稱:zenodo,代碼行數:14,代碼來源:test_jsonext.py

示例15: get_xml_and_jsonify

# 需要導入模塊: from invenio.modules.records.api import Record [as 別名]
# 或者: from invenio.modules.records.api.Record import create [as 別名]
def get_xml_and_jsonify(rep_no):
    """
    Retreives XML data from CDS and returns jsonified temp record
    :param rep_no: The report number to be retreived
    :type rep_no: String
    :returns: dict

    Workflow - Download an XML file from CDS using a link like:
    http://cds.cern.ch/search?p=reportnumber%3A"CERN-THESIS-2013-297"&of=xm
    JSONify the xml and return it.
    """
    xml = get("""http://cds.cern.ch/search?p=reportnumber%%3A"%s"&of=xm"""
              % rep_no).content
    if xml[83] == '1' and xml[84] == ' ':
        return Record.create(xml, 'marc', model='data_analysis_cds_extract')
    return None
開發者ID:crepererum,項目名稱:analysis-preservation.cern.ch,代碼行數:18,代碼來源:analysis_number.py


注:本文中的invenio.modules.records.api.Record.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。