Fix migration process

This commit is contained in:
Jean-Marie Favreau 2024-10-19 23:42:29 +02:00
parent 47b91b20fd
commit d5865bb65d
9 changed files with 41 additions and 12 deletions

View File

@ -43,8 +43,7 @@ class URLSubmissionForm(Form):
category = ModelChoiceField(
label=_("Category"),
queryset=Category.objects.all().order_by("name"),
initial=Category.get_default_category(),
empty_label=None,
initial=None,
help_text=_('Optional. If you don''t specify a category, we''ll find it for you.'),
required=False,
)

View File

@ -20,5 +20,5 @@ class Migration(migrations.Migration):
operations = [
migrations.RunPython(forwards_func),
migrations.RunPython(forwards_func, reverse_code=forwards_func),
]

View File

@ -10,6 +10,11 @@ def groups_permissions_creation(apps, schema_editor):
for name in user_roles:
Group.objects.create(name=name)
def groups_permissions_deletion(apps, schema_editor):
user_roles = ["Automation Manager", "Q&A Manager", "Receptionist"]
for name in user_roles:
Group.objects.filter(name=name).delete()
@ -21,5 +26,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(groups_permissions_creation),
migrations.RunPython(groups_permissions_creation, reverse_code=groups_permissions_deletion),
]

View File

@ -31,6 +31,12 @@ def update_groups_permissions(apps, schema_editor):
Group.objects.get(name="Receptionist").permissions.add(*receptionist_perms)
Group.objects.get(name="Receptionist").permissions.add(*read_mod_perms)
def update_groups_delete(apps, schema_editor):
user_roles = ["Moderator"]
for name in user_roles:
Group.objects.filter(name=name).delete()
class Migration(migrations.Migration):
@ -40,5 +46,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(update_groups_permissions),
migrations.RunPython(update_groups_permissions, reverse_code=update_groups_delete),
]

View File

@ -15,6 +15,9 @@ def update_groups_permissions(apps, schema_editor):
Group.objects.get(name="Q&A Manager").permissions.add(*qanda_perms)
Group.objects.get(name="Q&A Manager").permissions.add(*read_mod_perms)
def no_permission_change(apps, schema_editor):
pass
class Migration(migrations.Migration):
@ -23,5 +26,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(update_groups_permissions),
migrations.RunPython(update_groups_permissions, reverse_code=no_permission_change),
]

View File

@ -11,7 +11,8 @@ def update_groups_permissions(apps, schema_editor):
mod_perms = [i for i in all_perms if i.content_type.app_label == 'agenda_culturel' and i.content_type.model == 'moderationquestion' and i.codename.startswith('use_')]
Group.objects.get(name="Moderator").permissions.add(*mod_perms)
def no_permission_change(apps, schema_editor):
pass
class Migration(migrations.Migration):
@ -20,5 +21,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(update_groups_permissions),
migrations.RunPython(update_groups_permissions, reverse_code=no_permission_change),
]

View File

@ -16,6 +16,11 @@ def update_groups_permissions(apps, schema_editor):
editor_perms = [i for i in all_perms if i.content_type.app_label == 'agenda_culturel' and i.content_type.model == 'staticcontent']
Group.objects.get(name="Static content editor").permissions.add(*editor_perms)
def update_groups_delete(apps, schema_editor):
user_roles = ["Static content editor"]
for name in user_roles:
Group.objects.filter(name=name).delete()
class Migration(migrations.Migration):
@ -24,5 +29,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(update_groups_permissions),
migrations.RunPython(update_groups_permissions, reverse_code=update_groups_delete),
]

View File

@ -1,9 +1,10 @@
# Generated by Django 4.2.7 on 2024-04-27 16:29
from django.db import migrations
from django.contrib.auth.models import Group, Permission
def update_groups_permissions(apps, schema_editor):
Group = apps.get_model("auth", "Group")
Permission = apps.get_model("auth", "Permission")
all_perms = Permission.objects.all()
@ -11,6 +12,9 @@ def update_groups_permissions(apps, schema_editor):
moderator_perms = [i for i in all_perms if i.content_type.app_label == 'agenda_culturel' and i.content_type.model in ['place']]
Group.objects.get(name="Moderator").permissions.add(*moderator_perms)
def no_permission_change(apps, schema_editor):
pass
class Migration(migrations.Migration):
dependencies = [
@ -18,5 +22,5 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(update_groups_permissions),
migrations.RunPython(update_groups_permissions, reverse_code=no_permission_change),
]

View File

@ -15,6 +15,12 @@ def change_coord_format(apps, schema_editor):
p.location_pt = Point(3.08333, 45.783329)
p.save()
def reverse_coord_format(apps, schema_editor):
places = Place.objects.all()
for p in places:
p.location = ','.join([p.location_pt[1], p.location_pt[0]])
p.save()
@ -25,7 +31,7 @@ class Migration(migrations.Migration):
]
operations = [
migrations.RunPython(change_coord_format),
migrations.RunPython(change_coord_format, reverse_code=reverse_coord_format),
]