Revert using bulk_create for new projectlocales (#3265)

This commit is contained in:
Eemeli Aro 2024-06-28 09:01:18 -04:00 коммит произвёл GitHub
Родитель c73f1aa762
Коммит 7746964827
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 52 добавлений и 6 удалений

Просмотреть файл

@ -182,12 +182,10 @@ def manage_project(request, slug=None, template="admin_project.html"):
.delete()
)
project_locales = [
ProjectLocale(project=project, locale=locale) for locale in locales
]
ProjectLocale.objects.bulk_create(
project_locales, ignore_conflicts=True
)
for locale in locales:
# The implicit pre_save and post_save signals sent here are required
# to maintain django-guardian permissions.
ProjectLocale.objects.get_or_create(project=project, locale=locale)
project_locales = ProjectLocale.objects.filter(project=project)

Просмотреть файл

@ -0,0 +1,48 @@
from django.db import migrations
from pontoon.base.models import ProjectLocale
from pontoon.base.signals import assign_group_permissions, create_group
def fix_projectlocale_permissions(apps, schema_editor):
for project, locale in [
("common-voice", "cdo"),
("common-voice", "dar"),
("common-voice", "nqo"),
("common-voice", "shn"),
("firefox-bridge", "de"),
("firefox-bridge", "fr"),
("firefox-bridge", "it"),
("firefox-multi-account-containers", "fur"),
("firefox-profiler", "en-CA"),
("firefox-profiler", "fur"),
("firefox-profiler", "tr"),
]:
try:
project_locale = ProjectLocale.objects.get(
project__slug=project, locale__code=locale
)
create_group(
project_locale,
"translators",
["can_translate_project_locale"],
f"{project}/{locale}",
)
assign_group_permissions(
project_locale, "translators", ["can_translate_project_locale"]
)
except ProjectLocale.DoesNotExist:
pass
class Migration(migrations.Migration):
dependencies = [
("base", "0064_populate_unique_id"),
]
operations = [
migrations.RunPython(
code=fix_projectlocale_permissions,
reverse_code=migrations.RunPython.noop,
),
]