cleanup ids

This commit is contained in:
j 2014-05-24 12:50:27 +02:00
parent bea8efe6c4
commit a1833cc937
2 changed files with 10 additions and 4 deletions

View file

@ -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))

View file

@ -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')