Adds more fields to book data

This commit is contained in:
Mouse Reeve 2020-04-29 10:09:14 -07:00
parent 4f9edae05a
commit 6e218a85de
7 changed files with 48 additions and 9 deletions

View file

@ -7,13 +7,12 @@ def get_book(book):
fields = [
'sort_title',
'subtitle',
'isbn',
'isbn_13',
'oclc_number',
'openlibrary_key',
'librarything_key',
'fedireads_key',
'lccn',
'isbn',
'oclc_number',
'pages',
'physical_format',

View file

@ -19,7 +19,7 @@ class Connector(AbstractConnector):
'publish_date': ('published_date', get_date),
'first_publish_date': ('first_published_date', get_date),
'description': ('description', get_description),
'isbn_13': ('isbn', get_first),
'isbn_13': ('isbn_13', get_first),
'oclc_numbers': ('oclc_number', get_first),
'lccn': ('lccn', get_first),
'languages': ('languages', get_languages),
@ -118,8 +118,10 @@ class Connector(AbstractConnector):
update_from_mappings(book, data, self.book_mappings)
book.save()
for author in self.get_authors_from_data(data):
authors = self.get_authors_from_data(data)
for author in authors:
book.authors.add(author)
book.author_text = ', '.join(a.name for a in authors)
if data.get('covers'):
book.cover.save(*self.get_cover(data['covers'][0]), save=True)

View file

@ -0,0 +1,33 @@
# Generated by Django 3.0.3 on 2020-04-29 17:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('fedireads', '0034_importjob_import_status'),
]
operations = [
migrations.RenameField(
model_name='edition',
old_name='isbn',
new_name='isbn_13',
),
migrations.AddField(
model_name='book',
name='author_text',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='edition',
name='asin',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='edition',
name='isbn_10',
field=models.CharField(blank=True, max_length=255, null=True),
),
]

View file

@ -82,6 +82,8 @@ class Book(FedireadsModel):
)
# TODO: include an annotation about the type of authorship (ie, translator)
authors = models.ManyToManyField('Author')
# preformatted authorship string for search and easier display
author_text = models.CharField(max_length=255, blank=True, null=True)
cover = models.ImageField(upload_to='covers/', blank=True, null=True)
first_published_date = models.DateTimeField(blank=True, null=True)
published_date = models.DateTimeField(blank=True, null=True)
@ -123,10 +125,13 @@ class Work(Book):
class Edition(Book):
''' an edition of a book '''
# default -> this is what gets displayed for a work
default = models.BooleanField(default=False)
# these identifiers only apply to work
isbn = models.CharField(max_length=255, blank=True, null=True)
# these identifiers only apply to editions, not works
isbn_10 = models.CharField(max_length=255, blank=True, null=True)
isbn_13 = models.CharField(max_length=255, blank=True, null=True)
oclc_number = models.CharField(max_length=255, blank=True, null=True)
asin = models.CharField(max_length=255, blank=True, null=True)
pages = models.IntegerField(blank=True, null=True)
physical_format = models.CharField(max_length=255, blank=True, null=True)
publishers = ArrayField(

View file

@ -61,7 +61,7 @@ class ImportItem(models.Model):
def get_book_from_db_isbn(self):
''' see if we already know about the book '''
try:
return Edition.objects.get(isbn=self.isbn)
return Edition.objects.get(isbn_13=self.isbn)
except Edition.DoesNotExist:
return None

View file

@ -40,7 +40,7 @@
<h3>Book Identifiers</h2>
<div>
<p><label for="id_isbn">ISBN:</label> {{ form.isbn }} </p>
<p><label for="id_isbn">ISBN 13:</label> {{ form.isbn_13 }} </p>
<p><label for="id_fedireads_key">Fedireads key:</label> {{ form.fedireads_key }} </p>
<p><label for="id_openlibrary_key">Openlibrary key:</label> {{ form.openlibrary_key }} </p>
<p><label for="id_librarything_key">Librarything key:</label> {{ form.librarything_key }} </p>

View file

@ -431,7 +431,7 @@ def book_page(request, book_identifier, tab='friends'):
'path': '/book/%s' % book_identifier,
'cover_form': forms.CoverForm(instance=book),
'info_fields': [
{'name': 'ISBN', 'value': book.isbn},
{'name': 'ISBN', 'value': book.isbn_13},
{'name': 'OCLC number', 'value': book.oclc_number},
{'name': 'OpenLibrary ID', 'value': book.openlibrary_key},
{'name': 'Goodreads ID', 'value': book.goodreads_key},