Merge branch 'main' into report-actions
This commit is contained in:
commit
a166af9990
88 changed files with 15768 additions and 326 deletions
49
bookwyrm/migrations/0179_populate_sort_title.py
Normal file
49
bookwyrm/migrations/0179_populate_sort_title.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
import re
|
||||
from itertools import chain
|
||||
|
||||
from django.db import migrations, transaction
|
||||
from django.db.models import Q
|
||||
|
||||
from bookwyrm.settings import LANGUAGE_ARTICLES
|
||||
|
||||
|
||||
def set_sort_title(edition):
|
||||
articles = chain(
|
||||
*(LANGUAGE_ARTICLES.get(language, ()) for language in tuple(edition.languages))
|
||||
)
|
||||
edition.sort_title = re.sub(
|
||||
f'^{" |^".join(articles)} ', "", str(edition.title).lower()
|
||||
)
|
||||
return edition
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def populate_sort_title(apps, schema_editor):
|
||||
Edition = apps.get_model("bookwyrm", "Edition")
|
||||
db_alias = schema_editor.connection.alias
|
||||
editions_wo_sort_title = Edition.objects.using(db_alias).filter(
|
||||
Q(sort_title__isnull=True) | Q(sort_title__exact="")
|
||||
)
|
||||
batch_size = 1000
|
||||
start = 0
|
||||
end = batch_size
|
||||
while True:
|
||||
batch = editions_wo_sort_title[start:end]
|
||||
if not batch.exists():
|
||||
break
|
||||
Edition.objects.bulk_update(
|
||||
(set_sort_title(edition) for edition in batch), ["sort_title"]
|
||||
)
|
||||
start = end
|
||||
end += batch_size
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0178_auto_20230328_2132"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(populate_sort_title),
|
||||
]
|
44
bookwyrm/migrations/0180_alter_user_preferred_language.py
Normal file
44
bookwyrm/migrations/0180_alter_user_preferred_language.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
# Generated by Django 3.2.19 on 2023-07-23 19:33
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookwyrm", "0179_populate_sort_title"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="user",
|
||||
name="preferred_language",
|
||||
field=models.CharField(
|
||||
blank=True,
|
||||
choices=[
|
||||
("en-us", "English"),
|
||||
("ca-es", "Català (Catalan)"),
|
||||
("de-de", "Deutsch (German)"),
|
||||
("eo-uy", "Esperanto (Esperanto)"),
|
||||
("es-es", "Español (Spanish)"),
|
||||
("eu-es", "Euskara (Basque)"),
|
||||
("gl-es", "Galego (Galician)"),
|
||||
("it-it", "Italiano (Italian)"),
|
||||
("fi-fi", "Suomi (Finnish)"),
|
||||
("fr-fr", "Français (French)"),
|
||||
("lt-lt", "Lietuvių (Lithuanian)"),
|
||||
("nl-nl", "Nederlands (Dutch)"),
|
||||
("no-no", "Norsk (Norwegian)"),
|
||||
("pl-pl", "Polski (Polish)"),
|
||||
("pt-br", "Português do Brasil (Brazilian Portuguese)"),
|
||||
("pt-pt", "Português Europeu (European Portuguese)"),
|
||||
("ro-ro", "Română (Romanian)"),
|
||||
("sv-se", "Svenska (Swedish)"),
|
||||
("zh-hans", "简体中文 (Simplified Chinese)"),
|
||||
("zh-hant", "繁體中文 (Traditional Chinese)"),
|
||||
],
|
||||
max_length=255,
|
||||
null=True,
|
||||
),
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue