Skip to content

Commit

Permalink
Revert using bulk_create for new projectlocales (#3265)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli authored Jun 28, 2024
1 parent c73f1aa commit 7746964
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
10 changes: 4 additions & 6 deletions pontoon/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
48 changes: 48 additions & 0 deletions pontoon/base/migrations/0065_fix_projectlocale_permissions.py
Original file line number Diff line number Diff line change
@@ -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,
),
]

0 comments on commit 7746964

Please sign in to comment.