From 6e218a85defbfd7e965cfbf9857ed94e7f8f134f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 29 Apr 2020 10:09:14 -0700 Subject: [PATCH] Adds more fields to book data --- fedireads/activitypub/book.py | 3 +- fedireads/connectors/openlibrary.py | 6 ++-- .../migrations/0035_auto_20200429_1708.py | 33 +++++++++++++++++++ fedireads/models/book.py | 9 +++-- fedireads/models/import_job.py | 2 +- fedireads/templates/edit_book.html | 2 +- fedireads/views.py | 2 +- 7 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 fedireads/migrations/0035_auto_20200429_1708.py diff --git a/fedireads/activitypub/book.py b/fedireads/activitypub/book.py index a1a0a637..cbaa7a04 100644 --- a/fedireads/activitypub/book.py +++ b/fedireads/activitypub/book.py @@ -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', diff --git a/fedireads/connectors/openlibrary.py b/fedireads/connectors/openlibrary.py index 7b34e5f7..54a19148 100644 --- a/fedireads/connectors/openlibrary.py +++ b/fedireads/connectors/openlibrary.py @@ -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) diff --git a/fedireads/migrations/0035_auto_20200429_1708.py b/fedireads/migrations/0035_auto_20200429_1708.py new file mode 100644 index 00000000..e8d6ed30 --- /dev/null +++ b/fedireads/migrations/0035_auto_20200429_1708.py @@ -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), + ), + ] diff --git a/fedireads/models/book.py b/fedireads/models/book.py index fd21e2de..e501fc6b 100644 --- a/fedireads/models/book.py +++ b/fedireads/models/book.py @@ -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( diff --git a/fedireads/models/import_job.py b/fedireads/models/import_job.py index 2465fe12..8e61ed00 100644 --- a/fedireads/models/import_job.py +++ b/fedireads/models/import_job.py @@ -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 diff --git a/fedireads/templates/edit_book.html b/fedireads/templates/edit_book.html index ed641482..053cecd6 100644 --- a/fedireads/templates/edit_book.html +++ b/fedireads/templates/edit_book.html @@ -40,7 +40,7 @@

Book Identifiers

-

{{ form.isbn }}

+

{{ form.isbn_13 }}

{{ form.fedireads_key }}

{{ form.openlibrary_key }}

{{ form.librarything_key }}

diff --git a/fedireads/views.py b/fedireads/views.py index ff76166a..95b707f2 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -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},