Merge pull request #415 from mouse-reeve/author_text

Generate author_text field dynamically
This commit is contained in:
Mouse Reeve 2020-12-21 13:09:40 -08:00 committed by GitHub
commit 1fb728edbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 5 deletions

View file

@ -13,7 +13,7 @@ class Connector(AbstractConnector):
that gets implemented it will totally rule ''' that gets implemented it will totally rule '''
vector = SearchVector('title', weight='A') +\ vector = SearchVector('title', weight='A') +\
SearchVector('subtitle', weight='B') +\ SearchVector('subtitle', weight='B') +\
SearchVector('author_text', weight='C') +\ SearchVector('authors__name', weight='C') +\
SearchVector('isbn_13', weight='A') +\ SearchVector('isbn_13', weight='A') +\
SearchVector('isbn_10', weight='A') +\ SearchVector('isbn_10', weight='A') +\
SearchVector('openlibrary_key', weight='C') +\ SearchVector('openlibrary_key', weight='C') +\

View 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',
),
]

View file

@ -51,7 +51,6 @@ class Book(ActivitypubMixin, BookWyrmModel):
# TODO: include an annotation about the type of authorship (ie, translator) # TODO: include an annotation about the type of authorship (ie, translator)
authors = fields.ManyToManyField('Author') authors = fields.ManyToManyField('Author')
# preformatted authorship string for search and easier display # preformatted authorship string for search and easier display
author_text = models.CharField(max_length=255, blank=True, null=True)
cover = fields.ImageField( cover = fields.ImageField(
upload_to='covers/', blank=True, null=True, alt_field='alt_text') upload_to='covers/', blank=True, null=True, alt_field='alt_text')
first_published_date = fields.DateTimeField(blank=True, null=True) first_published_date = fields.DateTimeField(blank=True, null=True)
@ -59,6 +58,11 @@ class Book(ActivitypubMixin, BookWyrmModel):
objects = InheritanceManager() objects = InheritanceManager()
@property
def author_text(self):
''' format a list of authors '''
return ', '.join(a.name for a in self.authors.all())
@property @property
def edition_info(self): def edition_info(self):
''' properties of this edition, as a string ''' ''' properties of this edition, as a string '''

View file

@ -25,12 +25,13 @@ class SelfConnector(TestCase):
self.work = models.Work.objects.create( self.work = models.Work.objects.create(
title='Example Work', title='Example Work',
) )
author = models.Author.objects.create(name='Anonymous')
self.edition = models.Edition.objects.create( self.edition = models.Edition.objects.create(
title='Edition of Example Work', title='Edition of Example Work',
author_text='Anonymous',
published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc), published_date=datetime.datetime(1980, 5, 10, tzinfo=timezone.utc),
parent_work=self.work, parent_work=self.work,
) )
self.edition.authors.add(author)
models.Edition.objects.create( models.Edition.objects.create(
title='Another Edition', title='Another Edition',
parent_work=self.work, parent_work=self.work,
@ -41,11 +42,12 @@ class SelfConnector(TestCase):
subtitle='The Anonymous Edition', subtitle='The Anonymous Edition',
parent_work=self.work, parent_work=self.work,
) )
models.Edition.objects.create(
edition = models.Edition.objects.create(
title='An Edition', title='An Edition',
author_text='Fish',
parent_work=self.work parent_work=self.work
) )
edition.authors.add(models.Author.objects.create(name='Fish'))
def test_format_search_result(self): def test_format_search_result(self):