Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Create marc21 record #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 82 additions & 56 deletions invenio_marc21/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,90 @@

from invenio_records_rest.config import RECORDS_REST_ENDPOINTS
from invenio_records_rest.query import es_search_factory
from invenio_records_rest.utils import allow_all, check_elasticsearch
from invenio_records_ui.config import RECORDS_UI_ENDPOINTS
from invenio_search import RecordsSearch

MARC21_UI_EXPORT_FORMATS = {
"recid": {
"marcxml": dict(
title="MARCXML",
serializer="invenio_marc21.serializers.marcxml_v1",
order=1,
),
"mods": dict(
title="MODS",
serializer="invenio_marc21.serializers.mods_v1",
order=2,
),
"dc": dict(
title="DublinCore",
serializer="invenio_marc21.serializers.dublincore_v1",
order=3,
),
"json": dict(
title="JSON",
serializer="invenio_records_rest.serializers.json_v1",
order=4,
),
# Deprecated names
"hx": False,
"hm": False,
"xm": False,
"xd": False,
"xe": False,
"xn": False,
"xw": False,
}
MARC21_REST_ENDPOINTS = {
"recid": dict(
pid_type="recid",
pid_minter="recid",
pid_fetcher="recid",
default_endpoint_prefix=True,
record_class="invenio_records.api:Record",
search_class=RecordsSearch,
search_index=None,
search_type=None,
record_serializers={
"application/json": "invenio_records_rest.serializers:json_v1_response",
"application/marcxml+xml": (
"invenio_marc21.serializers:marcxml_v1_response"
),
"application/mods+xml": "invenio_marc21.serializers:mods_v1_response",
"application/xml": "invenio_marc21.serializers:dublincore_v1_response",
},
search_serializers={
"application/json": "invenio_records_rest.serializers:json_v1_search",
"application/marcxml+xml": ("invenio_marc21.serializers:marcxml_v1_search"),
"application/mods+xml": "invenio_marc21.serializers:mods_v1_search",
"application/xml": "invenio_marc21.serializers:dublincore_v1_search",
},
# TODO: create my own loader for application/marcxml+xml
# record_loaders={
# "application/json": ("invenio_marc21.loaders" ":json_v1"),
# },
list_route="/marc/",
item_route="/marc/<pid(recid):pid_value>",
default_media_type="application/json",
max_result_window=10000,
error_handlers=dict(),
create_permission_factory_imp=allow_all,
read_permission_factory_imp=check_elasticsearch,
update_permission_factory_imp=allow_all,
delete_permission_factory_imp=allow_all,
),
}

MARC21_REST_ENDPOINTS = copy.deepcopy(RECORDS_REST_ENDPOINTS)
MARC21_REST_ENDPOINTS["recid"]["search_index"] = "marc21"
MARC21_REST_ENDPOINTS["recid"]["default_media_type"] = "application/marcxml+xml"
MARC21_REST_ENDPOINTS["recid"]["record_serializers"] = {
"application/json": "invenio_records_rest.serializers:json_v1_response",
"application/marcxml+xml": ("invenio_marc21.serializers:marcxml_v1_response"),
"application/mods+xml": "invenio_marc21.serializers:mods_v1_response",
"application/xml": "invenio_marc21.serializers:dublincore_v1_response",
}
MARC21_REST_ENDPOINTS["recid"]["search_serializers"] = {
"application/json": "invenio_records_rest.serializers:json_v1_search",
"application/marcxml+xml": ("invenio_marc21.serializers:marcxml_v1_search"),
"application/mods+xml": "invenio_marc21.serializers:mods_v1_search",
"application/xml": "invenio_marc21.serializers:dublincore_v1_search",
}

MARC21_UI_ENDPOINTS = copy.deepcopy(RECORDS_UI_ENDPOINTS)
MARC21_UI_ENDPOINTS["recid"]["template"] = "invenio_marc21/detail.html"
MARC21_UI_ENDPOINTS["recid_export"] = {
"pid_type": "recid",
"route": "/record/<pid_value>/export/<any({0}):format>".format(
", ".join(list(MARC21_UI_EXPORT_FORMATS["recid"].keys()))
),
"template": "invenio_marc21/export.html",
"view_imp": "invenio_records_ui.views.export",
}
# TODO: implement ui endpoints
# MARC21_UI_EXPORT_FORMATS = {
# "recid": {
# "marcxml": dict(
# title="MARCXML",
# serializer="invenio_marc21.serializers.marcxml_v1",
# order=1,
# ),
# "mods": dict(
# title="MODS",
# serializer="invenio_marc21.serializers.mods_v1",
# order=2,
# ),
# "dc": dict(
# title="DublinCore",
# serializer="invenio_marc21.serializers.dublincore_v1",
# order=3,
# ),
# "json": dict(
# title="JSON",
# serializer="invenio_records_rest.serializers.json_v1",
# order=4,
# ),
# # Deprecated names
# "hx": False,
# "hm": False,
# "xm": False,
# "xd": False,
# "xe": False,
# "xn": False,
# "xw": False,
# }
# }

# MARC21_UI_ENDPOINTS = copy.deepcopy(RECORDS_UI_ENDPOINTS)
# MARC21_UI_ENDPOINTS['recid']['template'] = 'invenio_marc21/detail.html'
# MARC21_UI_ENDPOINTS['recid_export'] = {
# 'pid_type': 'recid',
# 'route': '/record/<pid_value>/export/<any({0}):format>'.format(
# ', '.join(list(MARC21_UI_EXPORT_FORMATS['recid'].keys()))),
# 'template': 'invenio_marc21/export.html',
# 'view_imp': 'invenio_records_ui.views.export',
6 changes: 6 additions & 0 deletions invenio_marc21/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from __future__ import absolute_import, print_function

from werkzeug.utils import cached_property

from . import config
from .views import blueprint

Expand Down Expand Up @@ -46,4 +48,8 @@ def init_config(self, app):
)
for k in dir(config):
if k.startswith("MARC21_"):
if k == "MARC21_REST_ENDPOINTS":
# Make sure of registration process.
app.config.setdefault("RECORDS_REST_ENDPOINTS", {})
app.config["RECORDS_REST_ENDPOINTS"].update(getattr(config, k))
app.config.setdefault(k, getattr(config, k))
21 changes: 16 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from setuptools import find_packages, setup


readme = open("README.rst").read()
history = open("CHANGES.rst").read()

Expand All @@ -23,7 +22,7 @@
"invenio-indexer>=1.1.0",
"invenio-pidstore>=1.0.0",
"invenio-records>=1.0.0",
"pytest-invenio>=1.4.0",
"SQLAlchemy-Continuum>=1.3.11",
]

# Should follow inveniosoftware/invenio versions
Expand All @@ -32,7 +31,7 @@

extras_require = {
"docs": [
"Sphinx>=1.5.2",
"Sphinx>=2.4",
],
"elasticsearch7": [
"invenio-search[elasticsearch7]>={}".format(invenio_search_version),
Expand All @@ -59,8 +58,14 @@
"Flask-BabelEx>=0.9.3",
"dojson>=1.3.0",
"invenio-jsonschemas>=1.0.0",
"invenio-records-rest>=1.0.0",
"invenio-records-ui>=1.0.0",
"invenio-records>=1.4.0a4,<2.0.0",
"invenio-records-files>=1.2.1,<2.0.0",
"invenio-records-ui>=1.2.0a1,<2.0.0",
"invenio-previewer>=1.2.1,<2.0.0",
# until fix in invenio-previewer is released
"nbconvert[execute]>=4.1.0,<6.0.0",
# TODO: Get from invenio-base
"six>=1.12.0", # Needed to pass CI tests
]

packages = find_packages()
Expand Down Expand Up @@ -90,6 +95,9 @@
"invenio_base.apps": [
"invenio_marc21 = invenio_marc21:InvenioMARC21",
],
"invenio_base.api_apps": [
"invenio_marc21 = invenio_marc21:InvenioMARC21",
],
"invenio_i18n.translations": [
"messages = invenio_marc21",
],
Expand All @@ -99,6 +107,9 @@
"invenio_search.mappings": [
"marc21 = invenio_marc21.mappings",
],
"invenio_config.module": [
"invenio_marc21 = invenio_marc21.config",
],
},
extras_require=extras_require,
install_requires=install_requires,
Expand Down