diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 5afd10897..86ac74353 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -140,7 +140,7 @@ class AbstractConnector(AbstractMinimalConnector): for author in self.get_authors_from_data(edition_data): edition.authors.add(author) if not edition.authors.exists() and work.authors.exists(): - edition.authors.add(work.authors.all()) + edition.authors.set(work.authors.all()) return edition diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index 74f76668c..3b60c3073 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -174,7 +174,7 @@ def pick_default_edition(options): if len(options) == 1: return options[0] - options = [e for e in options if e.get('cover')] or options + options = [e for e in options if e.get('covers')] or options options = [e for e in options if \ '/languages/eng' in str(e.get('languages'))] or options formats = ['paperback', 'hardcover', 'mass market paperback'] diff --git a/bookwyrm/connectors/self_connector.py b/bookwyrm/connectors/self_connector.py index 80d3a67d9..8d31c8a1a 100644 --- a/bookwyrm/connectors/self_connector.py +++ b/bookwyrm/connectors/self_connector.py @@ -13,7 +13,7 @@ class Connector(AbstractConnector): that gets implemented it will totally rule ''' vector = SearchVector('title', weight='A') +\ SearchVector('subtitle', weight='B') +\ - SearchVector('author_text', weight='C') +\ + SearchVector('authors__name', weight='C') +\ SearchVector('isbn_13', weight='A') +\ SearchVector('isbn_10', weight='A') +\ SearchVector('openlibrary_key', weight='C') +\ diff --git a/bookwyrm/migrations/0028_remove_book_author_text.py b/bookwyrm/migrations/0028_remove_book_author_text.py new file mode 100644 index 000000000..8743c910d --- /dev/null +++ b/bookwyrm/migrations/0028_remove_book_author_text.py @@ -0,0 +1,17 @@ +# Generated by Django 3.0.7 on 2020-12-21 19:57 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0027_auto_20201220_2007'), + ] + + operations = [ + migrations.RemoveField( + model_name='book', + name='author_text', + ), + ] diff --git a/bookwyrm/models/author.py b/bookwyrm/models/author.py index 911cc109d..a2eac507b 100644 --- a/bookwyrm/models/author.py +++ b/bookwyrm/models/author.py @@ -21,7 +21,7 @@ class Author(ActivitypubMixin, BookWyrmModel): # idk probably other keys would be useful here? born = fields.DateTimeField(blank=True, null=True) died = fields.DateTimeField(blank=True, null=True) - name = fields.CharField(max_length=255) + name = fields.CharField(max_length=255, deduplication_field=True) aliases = fields.ArrayField( models.CharField(max_length=255), blank=True, default=list ) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 0a3265915..21311d6c4 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -51,7 +51,6 @@ class Book(ActivitypubMixin, BookWyrmModel): # TODO: include an annotation about the type of authorship (ie, translator) authors = fields.ManyToManyField('Author') # preformatted authorship string for search and easier display - author_text = models.CharField(max_length=255, blank=True, null=True) cover = fields.ImageField( upload_to='covers/', blank=True, null=True, alt_field='alt_text') first_published_date = fields.DateTimeField(blank=True, null=True) @@ -59,6 +58,11 @@ class Book(ActivitypubMixin, BookWyrmModel): objects = InheritanceManager() + @property + def author_text(self): + ''' format a list of authors ''' + return ', '.join(a.name for a in self.authors.all()) + @property def edition_info(self): ''' properties of this edition, as a string ''' diff --git a/bookwyrm/tests/connectors/test_openlibrary_connector.py b/bookwyrm/tests/connectors/test_openlibrary_connector.py index b3d97ba31..e2d54cd36 100644 --- a/bookwyrm/tests/connectors/test_openlibrary_connector.py +++ b/bookwyrm/tests/connectors/test_openlibrary_connector.py @@ -44,7 +44,7 @@ class Openlibrary(TestCase): def test_pick_default_edition(self): edition = pick_default_edition(self.edition_list_data['entries']) - self.assertEqual(edition['key'], '/books/OL9952943M') + self.assertEqual(edition['key'], '/books/OL9788823M') def test_format_search_result(self): diff --git a/bookwyrm/tests/connectors/test_self_connector.py b/bookwyrm/tests/connectors/test_self_connector.py index 4627bc8c8..91857def0 100644 --- a/bookwyrm/tests/connectors/test_self_connector.py +++ b/bookwyrm/tests/connectors/test_self_connector.py @@ -25,12 +25,13 @@ class SelfConnector(TestCase): self.work = models.Work.objects.create( title='Example Work', ) + author = models.Author.objects.create(name='Anonymous') self.edition = models.Edition.objects.create( title='Edition of Example Work', - author_text='Anonymous', published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc), parent_work=self.work, ) + self.edition.authors.add(author) models.Edition.objects.create( title='Another Edition', parent_work=self.work, @@ -41,11 +42,12 @@ class SelfConnector(TestCase): subtitle='The Anonymous Edition', parent_work=self.work, ) - models.Edition.objects.create( + + edition = models.Edition.objects.create( title='An Edition', - author_text='Fish', parent_work=self.work ) + edition.authors.add(models.Author.objects.create(name='Fish')) def test_format_search_result(self):