cleanup ids
This commit is contained in:
parent
bea8efe6c4
commit
a1833cc937
2 changed files with 10 additions and 4 deletions
|
@ -20,6 +20,7 @@ from websocket import trigger_event
|
||||||
import metaremote as meta
|
import metaremote as meta
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
|
from utils import cleanup_id
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger('oml.item.api')
|
logger = logging.getLogger('oml.item.api')
|
||||||
|
@ -120,8 +121,7 @@ def edit(data):
|
||||||
if data['primaryid']:
|
if data['primaryid']:
|
||||||
key, value = data['primaryid']
|
key, value = data['primaryid']
|
||||||
logger.debug('update primaryid %s %s', key, value)
|
logger.debug('update primaryid %s %s', key, value)
|
||||||
if key == 'isbn':
|
value = cleanup_id(key, value)
|
||||||
value = utils.normalize_isbn(value)
|
|
||||||
item.update_primaryid(key, value)
|
item.update_primaryid(key, value)
|
||||||
else:
|
else:
|
||||||
item.update_primaryid()
|
item.update_primaryid()
|
||||||
|
@ -181,8 +181,7 @@ def getMetadata(data):
|
||||||
else:
|
else:
|
||||||
include_edits = False
|
include_edits = False
|
||||||
key, value = data.iteritems().next()
|
key, value = data.iteritems().next()
|
||||||
if key == 'isbn':
|
value = cleanup_id(key, value)
|
||||||
value = utils.normalize_isbn(value)
|
|
||||||
response = meta.lookup(key, value)
|
response = meta.lookup(key, value)
|
||||||
if include_edits:
|
if include_edits:
|
||||||
response.update(models.Metadata.load(key, value))
|
response.update(models.Metadata.load(key, value))
|
||||||
|
|
|
@ -25,6 +25,13 @@ logger = logging.getLogger('oml.utils')
|
||||||
|
|
||||||
ENCODING='base64'
|
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):
|
def valid_olid(id):
|
||||||
return id.startswith('OL') and id.endswith('M')
|
return id.startswith('OL') and id.endswith('M')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue