mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-12 18:25:35 +00:00
responding to review comments
This commit is contained in:
parent
6b39052fcc
commit
575e1bac4c
4 changed files with 15 additions and 23 deletions
|
@ -18,16 +18,10 @@ def populate_sort_title(apps, schema_editor):
|
||||||
articles = chain(
|
articles = chain(
|
||||||
*(LANGUAGE_ARTICLES.get(language, ()) for language in edition.languages)
|
*(LANGUAGE_ARTICLES.get(language, ()) for language in edition.languages)
|
||||||
)
|
)
|
||||||
if articles:
|
edition.sort_title = re.sub(
|
||||||
icase_articles = (
|
f'^{" |^".join(articles)} ', "", str(edition.title).lower()
|
||||||
f"[{a[0].capitalize()}{a[0].lower()}]{a[1:]}" for a in articles
|
)
|
||||||
)
|
Edition.objects.bulk_update(editions_wo_sort_title, ["sort_title"])
|
||||||
edition.sort_title = re.sub(
|
|
||||||
f'^{" |^".join(icase_articles)} ', "", edition.title
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
edition.sort_title = edition.title
|
|
||||||
edition.save()
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
|
@ -366,14 +366,14 @@ class Edition(Book):
|
||||||
cache.delete(f"author-books-{author_id}")
|
cache.delete(f"author-books-{author_id}")
|
||||||
|
|
||||||
# Create sort title by removing articles from title
|
# Create sort title by removing articles from title
|
||||||
if self.sort_title is None:
|
if self.sort_title in [None, ""]:
|
||||||
articles = chain(
|
if self.sort_title in [None, ""]:
|
||||||
*(LANGUAGE_ARTICLES[language] for language in self.languages)
|
articles = chain(
|
||||||
)
|
*(LANGUAGE_ARTICLES.get(language, ()) for language in self.languages)
|
||||||
icase_articles = (
|
)
|
||||||
f"[{a[0].capitalize()}{a[0].lower()}]{a[1:]}" for a in articles
|
self.sort_title = re.sub(
|
||||||
)
|
f'^{" |^".join(articles)} ', "", str(self.title).lower()
|
||||||
self.sort_title = re.sub(f'^{" |^".join(icase_articles)} ', "", self.title)
|
)
|
||||||
|
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -313,7 +313,7 @@ LANGUAGES = [
|
||||||
]
|
]
|
||||||
|
|
||||||
LANGUAGE_ARTICLES = {
|
LANGUAGE_ARTICLES = {
|
||||||
"English": {"The", "A", "An"},
|
"English": {"the", "a", "an"},
|
||||||
}
|
}
|
||||||
|
|
||||||
TIME_ZONE = "UTC"
|
TIME_ZONE = "UTC"
|
||||||
|
|
|
@ -140,8 +140,6 @@ class Book(TestCase):
|
||||||
title=f"{article} Test Edition", languages=[langauge]
|
title=f"{article} Test Edition", languages=[langauge]
|
||||||
)
|
)
|
||||||
for langauge, articles in settings.LANGUAGE_ARTICLES.items()
|
for langauge, articles in settings.LANGUAGE_ARTICLES.items()
|
||||||
for article in article
|
for article in articles
|
||||||
)
|
|
||||||
self.assertEqual(
|
|
||||||
all([book.sort_title == "Test Edition" for book in books])
|
|
||||||
)
|
)
|
||||||
|
self.assertTrue(all(book.sort_title == "Test Edition" for book in books))
|
||||||
|
|
Loading…
Reference in a new issue