Skip to content

Commit

Permalink
location: Update schema location
Browse files Browse the repository at this point in the history
* Update schema location for UCL paging feature
* Adapt existing features with new locations attributes
* Fixture tests

Co-Authored-by: Renaud Michotte <[email protected]>
  • Loading branch information
zannkukai committed Jan 29, 2020
1 parent f64f014 commit 29bfabf
Show file tree
Hide file tree
Showing 12 changed files with 324 additions and 79 deletions.
96 changes: 64 additions & 32 deletions data/locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"$ref": "https://ils.rero.ch/api/libraries/1"
},
"is_pickup": true,
"pickup_name": "AOSTE CANT1: Espaces publics"
"pickup_name": "AOSTE CANT1: Espaces publics",
"allow_request": true
},
{
"pid": "2",
Expand All @@ -17,7 +18,8 @@
"name": "Bibliographie vald\u00f4taine",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/1"
}
},
"allow_request": true
},
{
"pid": "3",
Expand All @@ -26,7 +28,8 @@
"name": "Magasin A",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/1"
}
},
"allow_request": true
},
{
"pid": "4",
Expand All @@ -37,7 +40,8 @@
"library": {
"$ref": "https://ils.rero.ch/api/libraries/1"
},
"is_online": true
"is_online": true,
"allow_request": true
},
{
"pid": "5",
Expand All @@ -48,7 +52,8 @@
"$ref": "https://ils.rero.ch/api/libraries/2"
},
"is_pickup": true,
"pickup_name": "AOSTE CANT2: Espaces publics"
"pickup_name": "AOSTE CANT2: Espaces publics",
"allow_request": true
},
{
"pid": "7",
Expand All @@ -57,7 +62,8 @@
"name": "Section fiction",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
}
},
"allow_request": true
},
{
"pid": "8",
Expand All @@ -66,7 +72,8 @@
"name": "Section documentaires",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
}
},
"allow_request": true
},
{
"pid": "9",
Expand All @@ -75,7 +82,8 @@
"name": "Section enfants",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
}
},
"allow_request": true
},
{
"pid": "10",
Expand All @@ -84,7 +92,8 @@
"name": "Section multim\u00e9dia",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
}
},
"allow_request": true
},
{
"pid": "11",
Expand All @@ -95,7 +104,8 @@
"$ref": "https://ils.rero.ch/api/libraries/3"
},
"is_pickup": true,
"pickup_name": "AOSTE-AVISE-PUB: Espaces publics"
"pickup_name": "AOSTE-AVISE-PUB: Espaces publics",
"allow_request": true
},
{
"pid": "12",
Expand All @@ -106,7 +116,8 @@
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
},
"is_online": true
"is_online": true,
"allow_request": true
},
{
"pid": "13",
Expand All @@ -117,7 +128,8 @@
"$ref": "https://ils.rero.ch/api/libraries/4"
},
"is_pickup": true,
"pickup_name": "AOSTE-LYCEE: Espaces publics"
"pickup_name": "AOSTE-LYCEE: Espaces publics",
"allow_request": true
},
{
"pid": "14",
Expand All @@ -126,7 +138,8 @@
"name": "Travaux de maturit\u00e9",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/4"
}
},
"allow_request": true
},
{
"pid": "16",
Expand All @@ -135,7 +148,8 @@
"name": "Restricted Section",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/5"
}
},
"allow_request": true
},
{
"pid": "17",
Expand All @@ -145,7 +159,8 @@
"is_pickup": true,
"library": {
"$ref": "https://ils.rero.ch/api/libraries/5"
}
},
"allow_request": true
},
{
"pid": "18",
Expand All @@ -156,7 +171,8 @@
"library": {
"$ref": "https://ils.rero.ch/api/libraries/5"
},
"is_online": true
"is_online": true,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -168,7 +184,8 @@
},
"is_pickup": true,
"pickup_name": "La Citadelle",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -180,7 +197,8 @@
},
"is_pickup": true,
"pickup_name": "Beast's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -192,7 +210,8 @@
},
"is_pickup": true,
"pickup_name": "Dream's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -204,7 +223,8 @@
},
"is_pickup": true,
"pickup_name": "Lux Foundation Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -216,7 +236,8 @@
},
"is_pickup": true,
"pickup_name": "Hogwarts Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -228,7 +249,8 @@
},
"is_pickup": true,
"pickup_name": "Biblioth\u00e8que de Babel",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -240,7 +262,8 @@
},
"is_pickup": true,
"pickup_name": "Biblioth\u00e8que de l\u2019abbaye",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -252,7 +275,8 @@
},
"is_pickup": true,
"pickup_name": "The University's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -264,7 +288,8 @@
},
"is_pickup": true,
"pickup_name": "Cemetery of Forgotten Books",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -276,7 +301,8 @@
},
"is_pickup": true,
"pickup_name": "Ministry of Truth",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -288,7 +314,8 @@
},
"is_pickup": true,
"pickup_name": "Rivendell Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -300,7 +327,8 @@
},
"is_pickup": true,
"pickup_name": "Matilda's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -312,7 +340,8 @@
},
"is_pickup": true,
"pickup_name": "Unseen University Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -324,7 +353,8 @@
},
"is_pickup": true,
"pickup_name": "Wan Shi Tong's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -336,7 +366,8 @@
},
"is_pickup": true,
"pickup_name": "Sunnydale High School library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -348,6 +379,7 @@
},
"is_pickup": true,
"pickup_name": "Jedi Archives",
"is_online": false
"is_online": false,
"allow_request": true
}
]
14 changes: 14 additions & 0 deletions rero_ils/modules/loans/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ def library_pid(self):
return loc.library_pid
return None

@property
def location_pid(self):
"""Get location PID regarding transaction Location PID or location."""
from ..items.api import Item

location_pid = self.get('transaction_location_pid')
item_pid = self.get('item_pid')
if not location_pid and item_pid:
item = Item.get_record_by_pid(item_pid)
return item.location_pid
elif location_pid:
return location_pid
return None

def dumps_for_circulation(self):
"""Dumps for circulation."""
loan = self.replace_refs()
Expand Down
13 changes: 8 additions & 5 deletions rero_ils/modules/loans/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def create_loan(barcode, transaction_type, loanable_items, verbose=False,
transaction_user_pid=user_pid,
transaction_date=transaction_date,
pickup_location_pid=get_random_pickup_location(
requested_patron.pid),
requested_patron.pid, item),
document_pid=item.replace_refs()['document']['pid'],
)
loan.create_notification(notification_type='recall')
Expand Down Expand Up @@ -256,7 +256,7 @@ def create_request(barcode, transaction_type, loanable_items, verbose=False,
transaction_user_pid=user_pid,
transaction_date=transaction_date,
pickup_location_pid=get_random_pickup_location(
rank_1_patron.pid),
rank_1_patron.pid, item),
document_pid=item.replace_refs()['document']['pid'],
)
transaction_date = datetime.now(timezone.utc).isoformat()
Expand All @@ -267,7 +267,7 @@ def create_request(barcode, transaction_type, loanable_items, verbose=False,
transaction_location_pid=user_location,
transaction_user_pid=user_pid,
transaction_date=transaction_date,
pickup_location_pid=get_random_pickup_location(patron.pid),
pickup_location_pid=get_random_pickup_location(patron.pid, item),
document_pid=item.replace_refs()['document']['pid'],
)
return item['barcode']
Expand Down Expand Up @@ -314,9 +314,12 @@ def get_loanable_items(patron_type_pid):
yield item


def get_random_pickup_location(patron_pid):
def get_random_pickup_location(patron_pid, item):
"""Find a qualified pickup location."""
pickup_locations_pids = list(Location.get_pickup_location_pids(patron_pid))
pickup_locations_pids = list(Location.get_pickup_location_pids(
patron_pid=patron_pid,
item_barcode=item.get('barcode')
))
return random.choice(pickup_locations_pids)


Expand Down
Loading

0 comments on commit 29bfabf

Please sign in to comment.