当前位置: 首页>>代码示例>>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;未经允许,请勿转载。