From d5865bb65dda4ab7b1396fc23c748f07c5a8c4db Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Sat, 19 Oct 2024 23:42:29 +0200 Subject: [PATCH] Fix migration process --- src/agenda_culturel/forms.py | 3 +-- src/agenda_culturel/migrations/0027_set_dtstart_dtend.py | 2 +- src/agenda_culturel/migrations/0036_auto_20240331_1421.py | 7 ++++++- src/agenda_culturel/migrations/0038_auto_20240331_1815.py | 8 +++++++- src/agenda_culturel/migrations/0040_auto_20240403_1924.py | 5 ++++- src/agenda_culturel/migrations/0045_auto_20240405_1941.py | 5 +++-- src/agenda_culturel/migrations/0048_auto_20240417_1212.py | 7 ++++++- src/agenda_culturel/migrations/0059_auto_20240427_1829.py | 8 ++++++-- src/agenda_culturel/migrations/0081_auto_20241010_2235.py | 8 +++++++- 9 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/agenda_culturel/forms.py b/src/agenda_culturel/forms.py index 3ff6c20..52cbb2e 100644 --- a/src/agenda_culturel/forms.py +++ b/src/agenda_culturel/forms.py @@ -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, ) diff --git a/src/agenda_culturel/migrations/0027_set_dtstart_dtend.py b/src/agenda_culturel/migrations/0027_set_dtstart_dtend.py index 3092284..a6145f4 100644 --- a/src/agenda_culturel/migrations/0027_set_dtstart_dtend.py +++ b/src/agenda_culturel/migrations/0027_set_dtstart_dtend.py @@ -20,5 +20,5 @@ class Migration(migrations.Migration): operations = [ - migrations.RunPython(forwards_func), + migrations.RunPython(forwards_func, reverse_code=forwards_func), ] \ No newline at end of file diff --git a/src/agenda_culturel/migrations/0036_auto_20240331_1421.py b/src/agenda_culturel/migrations/0036_auto_20240331_1421.py index b8bd566..3e5c58f 100644 --- a/src/agenda_culturel/migrations/0036_auto_20240331_1421.py +++ b/src/agenda_culturel/migrations/0036_auto_20240331_1421.py @@ -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), ] diff --git a/src/agenda_culturel/migrations/0038_auto_20240331_1815.py b/src/agenda_culturel/migrations/0038_auto_20240331_1815.py index e50ae6c..07b31c6 100644 --- a/src/agenda_culturel/migrations/0038_auto_20240331_1815.py +++ b/src/agenda_culturel/migrations/0038_auto_20240331_1815.py @@ -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), ] diff --git a/src/agenda_culturel/migrations/0040_auto_20240403_1924.py b/src/agenda_culturel/migrations/0040_auto_20240403_1924.py index cdcadcd..27c83d6 100644 --- a/src/agenda_culturel/migrations/0040_auto_20240403_1924.py +++ b/src/agenda_culturel/migrations/0040_auto_20240403_1924.py @@ -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), ] diff --git a/src/agenda_culturel/migrations/0045_auto_20240405_1941.py b/src/agenda_culturel/migrations/0045_auto_20240405_1941.py index c0082b3..9c71ff1 100644 --- a/src/agenda_culturel/migrations/0045_auto_20240405_1941.py +++ b/src/agenda_culturel/migrations/0045_auto_20240405_1941.py @@ -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), ] diff --git a/src/agenda_culturel/migrations/0048_auto_20240417_1212.py b/src/agenda_culturel/migrations/0048_auto_20240417_1212.py index dea65db..f88a299 100644 --- a/src/agenda_culturel/migrations/0048_auto_20240417_1212.py +++ b/src/agenda_culturel/migrations/0048_auto_20240417_1212.py @@ -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), ] diff --git a/src/agenda_culturel/migrations/0059_auto_20240427_1829.py b/src/agenda_culturel/migrations/0059_auto_20240427_1829.py index 843b354..216f5da 100644 --- a/src/agenda_culturel/migrations/0059_auto_20240427_1829.py +++ b/src/agenda_culturel/migrations/0059_auto_20240427_1829.py @@ -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), ] diff --git a/src/agenda_culturel/migrations/0081_auto_20241010_2235.py b/src/agenda_culturel/migrations/0081_auto_20241010_2235.py index 0b8f2ec..1f6e475 100644 --- a/src/agenda_culturel/migrations/0081_auto_20241010_2235.py +++ b/src/agenda_culturel/migrations/0081_auto_20241010_2235.py @@ -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), ]