onix and cover improvements
onix recipients need both a pubdate and an isbn in the records. the cover imagefiles from thumbnail occasionally result in broken images- these are now detected.pull/1/head
parent
a466a251a0
commit
11ea9b4d93
15
api/onix.py
15
api/onix.py
|
@ -61,11 +61,13 @@ def product(edition, facet=None):
|
|||
ident_node.append(text_node("ProductIDType", "01" )) #proprietary
|
||||
ident_node.append(text_node("IDTypeName", "unglue.it edition id" )) #proprietary
|
||||
ident_node.append(text_node("IDValue", unicode(edition.id) ))
|
||||
|
||||
if edition.isbn_13:
|
||||
|
||||
# wrong isbn better than no isbn
|
||||
isbn = edition.isbn_13 if edition.isbn_13 else edition.work.first_isbn_13()
|
||||
if isbn:
|
||||
ident_node = etree.SubElement(product_node, "ProductIdentifier")
|
||||
ident_node.append(text_node("ProductIDType", "03" )) #proprietary
|
||||
ident_node.append(text_node("IDValue", edition.isbn_13 ))
|
||||
ident_node.append(text_node("IDValue", isbn ))
|
||||
|
||||
# Descriptive Detail Block
|
||||
descriptive_node = etree.SubElement(product_node, "DescriptiveDetail")
|
||||
|
@ -163,10 +165,13 @@ def product(edition, facet=None):
|
|||
pub_node.append(text_node("PublishingRole", '01')) #publisher
|
||||
pub_node.append(text_node("PublisherName", edition.publisher_name.name))
|
||||
pubdetail_node.append(text_node("PublishingStatus", '00')) #unspecified
|
||||
if edition.publication_date:
|
||||
|
||||
#consumers really want a pub date
|
||||
publication_date = edition.publication_date if edition.publication_date else edition.work.earliest_publication_date
|
||||
if publication_date:
|
||||
pubdate_node = etree.SubElement(pubdetail_node, "PublishingDate")
|
||||
pubdate_node.append(text_node("PublishingDateRole", '01')) #nominal pub date
|
||||
pubdate_node.append(text_node("Date", edition.publication_date.replace('-','')))
|
||||
pubdate_node.append(text_node("Date", publication_date.replace('-','')))
|
||||
|
||||
# Product Supply Block
|
||||
supply_node = etree.SubElement(product_node,"ProductSupply")
|
||||
|
|
|
@ -1490,7 +1490,13 @@ class Work(models.Model):
|
|||
return self.identifiers.filter(type='isbn')[0].value
|
||||
except IndexError:
|
||||
return ''
|
||||
|
||||
|
||||
@property
|
||||
def earliest_publication_date(self):
|
||||
for edition in Edition.objects.filter(work=self, publication_date__isnull=False).order_by('publication_date'):
|
||||
if edition.publication_date and len(edition.publication_date)>=4:
|
||||
return edition.publication_date
|
||||
|
||||
@property
|
||||
def publication_date(self):
|
||||
if self.publication_range:
|
||||
|
@ -1781,8 +1787,9 @@ class Edition(models.Model):
|
|||
def cover_image_large(self):
|
||||
#550 pixel high image
|
||||
if self.cover_image:
|
||||
im = get_thumbnail(self.cover_image, 'x550', crop='noop', quality=95)
|
||||
return im.url
|
||||
im = get_thumbnail(self.cover_image, 'x550', crop='noop', quality=95)
|
||||
if im.exists():
|
||||
return im.url
|
||||
elif self.googlebooks_id:
|
||||
url = "https://encrypted.google.com/books?id=%s&printsec=frontcover&img=1&zoom=0" % self.googlebooks_id
|
||||
im = get_thumbnail(url, 'x550', crop='noop', quality=95)
|
||||
|
@ -1800,8 +1807,9 @@ class Edition(models.Model):
|
|||
#80 pixel high image
|
||||
if self.cover_image:
|
||||
im = get_thumbnail(self.cover_image, 'x80', crop='noop', quality=95)
|
||||
return im.url
|
||||
elif self.googlebooks_id:
|
||||
if im.exists():
|
||||
return im.url
|
||||
if self.googlebooks_id:
|
||||
return "https://encrypted.google.com/books?id=%s&printsec=frontcover&img=1&zoom=5" % self.googlebooks_id
|
||||
else:
|
||||
return ''
|
||||
|
@ -1810,8 +1818,9 @@ class Edition(models.Model):
|
|||
#128 pixel wide image
|
||||
if self.cover_image:
|
||||
im = get_thumbnail(self.cover_image, '128', crop='noop', quality=95)
|
||||
return im.url
|
||||
elif self.googlebooks_id:
|
||||
if im.exists():
|
||||
return im.url
|
||||
if self.googlebooks_id:
|
||||
return "https://encrypted.google.com/books?id=%s&printsec=frontcover&img=1&zoom=1" % self.googlebooks_id
|
||||
else:
|
||||
return ''
|
||||
|
@ -2065,9 +2074,16 @@ class Ebook(models.Model):
|
|||
f = urllib.urlopen(self.url)
|
||||
return f
|
||||
else:
|
||||
f= self.edition.ebook_files.filter(format=self.format).order_by('-created')[0].file
|
||||
f.open()
|
||||
return f
|
||||
ebf = self.edition.ebook_files.filter(format=self.format).order_by('-created')[0]
|
||||
try:
|
||||
ebf.file.open()
|
||||
except ValueError:
|
||||
logger.error(u'couldn\'t open EbookFile {}'.format(ebf.id) )
|
||||
return None
|
||||
except IOError:
|
||||
logger.error(u'EbookFile {} does not exist'.format(ebf.id) )
|
||||
return None
|
||||
return ebf.file
|
||||
|
||||
def set_provider(self):
|
||||
self.provider=Ebook.infer_provider(self.url)
|
||||
|
|
Loading…
Reference in New Issue