Add a few comments to explain how various parts of our bookloading process works
parent
6466c4292f
commit
b7f47bfee5
|
@ -128,11 +128,20 @@ def add_ebooks(item, edition):
|
||||||
|
|
||||||
|
|
||||||
def update_edition(edition):
|
def update_edition(edition):
|
||||||
|
"""
|
||||||
|
attempt to update data associated with input edition and return that updated edition
|
||||||
|
"""
|
||||||
|
|
||||||
|
# if there is no ISBN associated with edition, just return the input edition
|
||||||
try:
|
try:
|
||||||
isbn=edition.identifiers.filter(type='isbn')[0].value
|
isbn=edition.identifiers.filter(type='isbn')[0].value
|
||||||
except models.Identifier.DoesNotExist:
|
except models.Identifier.DoesNotExist:
|
||||||
return edition
|
return edition
|
||||||
|
|
||||||
|
# do a Google Books lookup on the isbn associated with the edition (there should be either 0 or 1 isbns associated
|
||||||
|
# with an edition because of integrity constraint in Identifier)
|
||||||
|
|
||||||
|
# if we get some data about this isbn back from Google, update the edition data accordingly
|
||||||
results=get_google_isbn_results(isbn)
|
results=get_google_isbn_results(isbn)
|
||||||
if not results:
|
if not results:
|
||||||
return edition
|
return edition
|
||||||
|
@ -149,11 +158,15 @@ def update_edition(edition):
|
||||||
|
|
||||||
# check for language change
|
# check for language change
|
||||||
language = d['language']
|
language = d['language']
|
||||||
|
# don't track variants in main language (e.g., traditional vs simplified Chinese)
|
||||||
if len(language)>2:
|
if len(language)>2:
|
||||||
language= language[0:2]
|
language= language[0:2]
|
||||||
|
|
||||||
|
# if the language of the edition no longer matches that of the parent work, attach edition to the
|
||||||
if edition.work.language != language:
|
if edition.work.language != language:
|
||||||
logger.info("reconnecting %s since it is %s instead of %s" %(googlebooks_id, language, edition.work.language))
|
logger.info("reconnecting %s since it is %s instead of %s" %(googlebooks_id, language, edition.work.language))
|
||||||
old_work=edition.work
|
old_work=edition.work
|
||||||
|
|
||||||
new_work = models.Work(title=title, language=language)
|
new_work = models.Work(title=title, language=language)
|
||||||
new_work.save()
|
new_work.save()
|
||||||
edition.work = new_work
|
edition.work = new_work
|
||||||
|
|
Loading…
Reference in New Issue