diff --git a/oml/item/api.py b/oml/item/api.py index 117d591..ca671e9 100644 --- a/oml/item/api.py +++ b/oml/item/api.py @@ -20,6 +20,7 @@ from websocket import trigger_event import metaremote as meta import utils +from utils import cleanup_id import logging logger = logging.getLogger('oml.item.api') @@ -120,8 +121,7 @@ def edit(data): if data['primaryid']: key, value = data['primaryid'] logger.debug('update primaryid %s %s', key, value) - if key == 'isbn': - value = utils.normalize_isbn(value) + value = cleanup_id(key, value) item.update_primaryid(key, value) else: item.update_primaryid() @@ -181,8 +181,7 @@ def getMetadata(data): else: include_edits = False key, value = data.iteritems().next() - if key == 'isbn': - value = utils.normalize_isbn(value) + value = cleanup_id(key, value) response = meta.lookup(key, value) if include_edits: response.update(models.Metadata.load(key, value)) diff --git a/oml/utils.py b/oml/utils.py index c8ea599..5e0cfa0 100644 --- a/oml/utils.py +++ b/oml/utils.py @@ -25,6 +25,13 @@ logger = logging.getLogger('oml.utils') ENCODING='base64' +def cleanup_id(key, value): + if key == 'isbn': + value = normalize_isbn(value) + if key in ('lccn', 'olid', 'oclc'): + value = ''.join([v for v in value if v!='-']) + return value + def valid_olid(id): return id.startswith('OL') and id.endswith('M')