Skip to content

Commit

Permalink
data: implements local fields
Browse files Browse the repository at this point in the history
* Adds local fields on document, item and holdings (serial type).
* Adds the type column in the refs resolve.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
Co-Authored-by: Aly Badr <aly.badr@rero.ch>
  • Loading branch information
Garfield-fr and Aly Badr committed Dec 2, 2020
1 parent f3275b9 commit 728d3ec
Show file tree
Hide file tree
Showing 52 changed files with 1,523 additions and 16 deletions.
62 changes: 62 additions & 0 deletions data/local_fields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"pid": "1",
"organisation": {
"$ref": "https://ils.rero.ch/api/organisations/1"
},
"parent": {
"$ref": "https://ils.rero.ch/api/documents/1"
},
"fields": {
"field_1": [
"Auteur vald\u00f4tain",
"Bibliographie vald\u00f4taine"
]
}
},
{
"pid": "2",
"organisation": {
"$ref": "https://ils.rero.ch/api/organisations/2"
},
"parent": {
"$ref": "https://ils.rero.ch/api/documents/1"
},
"fields": {
"field_1": [
"Production by Hogwarts' students"
]
}
},
{
"pid": "3",
"organisation": {
"$ref": "https://ils.rero.ch/api/organisations/1"
},
"parent": {
"$ref": "https://ils.rero.ch/api/documents/93"
},
"fields": {
"field_1": [
"Don \u00c9mile Chanoux"
],
"field_2": [
"Fonds de la Fondation Grand Paradis"
]
}
},
{
"pid": "4",
"organisation": {
"$ref": "https://ils.rero.ch/api/organisations/2"
},
"parent": {
"$ref": "https://ils.rero.ch/api/documents/93"
},
"fields": {
"field_1": [
"Donation Albus Dumbledore"
]
}
}
]
63 changes: 60 additions & 3 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
get_extension_params, is_item_available_for_checkout, \
loan_build_document_ref, loan_build_item_ref, loan_build_patron_ref, \
loan_satisfy_circ_policies, validate_item_pickup_transaction_locations
from .modules.local_fields.api import LocalField
from .modules.local_fields.permissions import LocalFieldPermission
from .modules.locations.api import Location
from .modules.locations.permissions import LocationPermission
from .modules.notifications.api import Notification
Expand Down Expand Up @@ -463,7 +465,8 @@ def _(x):
},
record_class='rero_ils.modules.collections.api:Collection',
list_route='/collections/',
item_route='/collections/<pid(coll, record_class="rero_ils.modules.collections.api:Collection"):pid_value>',
item_route='/collections/<pid(coll, record_class='
'"rero_ils.modules.collections.api:Collection"):pid_value>',
default_media_type='application/json',
max_result_window=10000,
search_factory_imp='rero_ils.query:view_search_collection_factory',
Expand Down Expand Up @@ -507,7 +510,8 @@ def _(x):
),
},
record_loaders={
'application/marcxml+xml': 'rero_ils.modules.documents.loaders:marcxml_loader',
'application/marcxml+xml':
'rero_ils.modules.documents.loaders:marcxml_loader',
'application/json': lambda: Document(request.get_json()),
},

Expand Down Expand Up @@ -568,7 +572,8 @@ def _(x):
},
record_class='rero_ils.modules.ill_requests.api:ILLRequest',
list_route='/ill_requests/',
item_route='/ill_requests/<pid(illr, record_class="rero_ils.modules.ill_requests.api:ILLRequest"):pid_value>',
item_route='/ill_requests/<pid(illr, record_class='
'"rero_ils.modules.ill_requests.api:ILLRequest"):pid_value>',
default_media_type='application/json',
max_result_window=10000,
search_factory_imp='rero_ils.query:loans_search_factory',
Expand Down Expand Up @@ -720,6 +725,48 @@ def _(x):
delete_permission_factory_imp=lambda record: record_permission_factory(
action='delete', record=record, cls=HoldingPermission)
),
lofi=dict(
pid_type='lofi',
pid_minter='local_field_id',
pid_fetcher='local_field_id',
search_class='rero_ils.modules.local_fields.api:LocalFieldsSearch',
search_index='local_fields',
search_type=None,
indexer_class='rero_ils.modules.local_fields.api:LocalFieldsIndexer',
record_serializers={
'application/json': (
'rero_ils.modules.serializers:json_v1_response'
)
},
record_serializers_aliases={
'json': 'application/json',
},
search_serializers={
'application/json': (
'rero_ils.modules.serializers:json_v1_search'
)
},
record_loaders={
'application/json': lambda: LocalField(request.get_json()),
},
record_class='rero_ils.modules.local_fields.api:LocalField',
list_route='/local_fields/',
item_route='/local_fields/<pid(lofi, record_class='
'"rero_ils.modules.local_fields.api:LocalField"):pid_value>',
default_media_type='application/json',
max_result_window=10000,
search_factory_imp='rero_ils.query:organisation_search_factory',
list_permission_factory_imp=lambda record: record_permission_factory(
action='list', record=record, cls=LocalFieldPermission),
read_permission_factory_imp=lambda record: record_permission_factory(
action='read', record=record, cls=LocalFieldPermission),
create_permission_factory_imp=lambda record: record_permission_factory(
action='create', record=record, cls=LocalFieldPermission),
update_permission_factory_imp=lambda record: record_permission_factory(
action='update', record=record, cls=LocalFieldPermission),
delete_permission_factory_imp=lambda record: record_permission_factory(
action='delete', record=record, cls=LocalFieldPermission)
),
ptrn=dict(
pid_type='ptrn',
pid_minter='patron_id',
Expand Down Expand Up @@ -1824,6 +1871,7 @@ def _(x):
'item_types',
'ill_requests',
'libraries',
'local_fields',
'loans',
'locations',
'organisations',
Expand Down Expand Up @@ -2022,6 +2070,14 @@ def _(x):
record_class='rero_ils.modules.contributions.api:Contribution',
view_imp='rero_ils.modules.contributions.'
'views.contribution_view_method'
),
'lofi': dict(
pid_type='lofi',
route='/local_fields/<pid_value>',
template='rero_ils/detailed_view_local_fields.html',
record_class='rero_ils.modules.local_fields.api:LocalField',
permission_factory_imp='rero_ils.permissions.'
'librarian_permission_factory',
)
}

Expand Down Expand Up @@ -2051,6 +2107,7 @@ def _(x):
'itty': '/item_types/item_type-v0.0.1.json',
'lib': '/libraries/library-v0.0.1.json',
'loc': '/locations/location-v0.0.1.json',
'lofi': '/local_fields/local_field-v0.0.1.json',
'notif': '/notifications/notification-v0.0.1.json',
'org': '/organisations/organisation-v0.0.1.json',
'pttr': '/patron_transactions/patron_transaction-v0.0.1.json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@
},
"document": {
"properties": {
"type": {
"type": "keyword"
},
"pid": {
"type": "keyword"
}
}
},
"organisation": {
"properties": {
"type": {
"type": "keyword"
},
"pid": {
"type": "keyword"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
},
"organisation": {
"properties": {
"type": {
"type": "keyword"
},
"pid": {
"type": "keyword"
}
Expand Down Expand Up @@ -63,6 +66,9 @@
},
"libraries": {
"properties": {
"type": {
"type": "keyword"
},
"pid": {
"type": "keyword"
}
Expand All @@ -73,13 +79,19 @@
"properties": {
"patron_type": {
"properties": {
"type": {
"type": "keyword"
},
"pid": {
"type": "keyword"
}
}
},
"item_type": {
"properties": {
"type": {
"type": "keyword"
},
"pid": {
"type": "keyword"
}
Expand Down
16 changes: 16 additions & 0 deletions rero_ils/modules/documents/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from ..holdings.api import Holding, HoldingsSearch
from ..items.api import ItemsSearch
from ..items.models import ItemNoteTypes
from ..local_fields.api import LocalField
from ..utils import extracted_data_from_ref


Expand Down Expand Up @@ -56,6 +57,10 @@ def enrich_document_data(sender, json=None, record=None, index=None,
'library_pid': holding['library']['pid']
}
}
# Local fields on the holding
if 'local_fields' in holding:
data['local_fields'] = holding.to_dict()['local_fields']

# items linked to the holding
es_items = list(
ItemsSearch().filter('term', holding__pid=holding.pid).scan()
Expand All @@ -67,6 +72,12 @@ def enrich_document_data(sender, json=None, record=None, index=None,
'status': item.status,
'available': item.available
}

# Local fields on the item
if 'local_fields' in item:
item_record['local_fields'] =\
item.to_dict()['local_fields']

call_number = item.to_dict().get('call_number')
if call_number:
item_record['call_number'] = call_number
Expand Down Expand Up @@ -126,3 +137,8 @@ def enrich_document_data(sender, json=None, record=None, index=None,
json.get('title', []),
with_subtitle=True
)
# Local fields in JSON
local_fields = LocalField.get_local_fields_by_resource(
'doc', document_pid)
if local_fields:
json['local_fields'] = local_fields
Loading

0 comments on commit 728d3ec

Please sign in to comment.