forked from mirrors/bookwyrm
Merge branch 'main' into production
This commit is contained in:
commit
77db2e183d
8 changed files with 32 additions and 9 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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') +\
|
||||
|
|
17
bookwyrm/migrations/0028_remove_book_author_text.py
Normal file
17
bookwyrm/migrations/0028_remove_book_author_text.py
Normal file
|
@ -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',
|
||||
),
|
||||
]
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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 '''
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue