-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
items: Add call number validation to ItemSchema
- Loading branch information
1 parent
3fdf092
commit f081d00
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# CDS-ILS is free software; you can redistribute it and/or modify it under | ||
# the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""CDS-ILS items module.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
Check failure on line 1 in cds_ils/items/loaders.py
|
||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# CDS-ILS is free software; you can redistribute it and/or modify it under | ||
# the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""CDS-ILS items loaders.""" | ||
|
||
from marshmallow import fields, ValidationError | ||
|
||
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema | ||
from invenio_app_ils.items.loaders.jsonschemas.items import ( | ||
ItemSchemaV1 as ILSItemSchemaV1, | ||
) | ||
from invenio_app_ils.records.loaders import ils_marshmallow_loader | ||
|
||
|
||
def validate_call_number_exists(identifiers): | ||
"""Check if Call number exists.""" | ||
for identifier in identifiers: | ||
if identifier["scheme"] == "CALL_NUMBER": | ||
return | ||
raise ValidationError("The Call number identifier field is mandatory.") | ||
|
||
|
||
class ItemSchemaV1(ILSItemSchemaV1): | ||
identifiers = fields.List( | ||
fields.Nested(IdentifierSchema), | ||
required=True, | ||
validate=validate_call_number_exists, | ||
) | ||
|
||
|
||
item_loader = ils_marshmallow_loader(ItemSchemaV1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters