responding to review comments

This commit is contained in:
Zach Flanders 2023-04-25 19:46:38 -05:00
parent 6b39052fcc
commit 575e1bac4c
4 changed files with 15 additions and 23 deletions

View file

@ -18,16 +18,10 @@ def populate_sort_title(apps, schema_editor):
articles = chain(
*(LANGUAGE_ARTICLES.get(language, ()) for language in edition.languages)
)
if articles:
icase_articles = (
f"[{a[0].capitalize()}{a[0].lower()}]{a[1:]}" for a in articles
)
edition.sort_title = re.sub(
f'^{" |^".join(icase_articles)} ', "", edition.title
)
else:
edition.sort_title = edition.title
edition.save()
edition.sort_title = re.sub(
f'^{" |^".join(articles)} ', "", str(edition.title).lower()
)
Edition.objects.bulk_update(editions_wo_sort_title, ["sort_title"])
class Migration(migrations.Migration):

View file

@ -366,14 +366,14 @@ class Edition(Book):
cache.delete(f"author-books-{author_id}")
# Create sort title by removing articles from title
if self.sort_title is None:
articles = chain(
*(LANGUAGE_ARTICLES[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(icase_articles)} ', "", self.title)
if self.sort_title in [None, ""]:
if self.sort_title in [None, ""]:
articles = chain(
*(LANGUAGE_ARTICLES.get(language, ()) for language in self.languages)
)
self.sort_title = re.sub(
f'^{" |^".join(articles)} ', "", str(self.title).lower()
)
return super().save(*args, **kwargs)

View file

@ -313,7 +313,7 @@ LANGUAGES = [
]
LANGUAGE_ARTICLES = {
"English": {"The", "A", "An"},
"English": {"the", "a", "an"},
}
TIME_ZONE = "UTC"

View file

@ -140,8 +140,6 @@ class Book(TestCase):
title=f"{article} Test Edition", languages=[langauge]
)
for langauge, articles in settings.LANGUAGE_ARTICLES.items()
for article in article
)
self.assertEqual(
all([book.sort_title == "Test Edition" for book in books])
for article in articles
)
self.assertTrue(all(book.sort_title == "Test Edition" for book in books))