From 594a0226d3eb7ae15fa80d13f21ef470cc592403 Mon Sep 17 00:00:00 2001 From: vaz Date: Thu, 1 Dec 2022 13:40:25 +0100 Subject: [PATCH 1/7] Make a default entry with RunPython --- admin_interface/apps.py | 3 --- admin_interface/migrations/0001_initial.py | 6 ++++++ admin_interface/models.py | 5 ----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/admin_interface/apps.py b/admin_interface/apps.py index ffeafdcb..dcfa34c3 100644 --- a/admin_interface/apps.py +++ b/admin_interface/apps.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from django.apps import AppConfig -from django.db.models.signals import post_migrate from admin_interface.compat import gettext_lazy as _ @@ -15,7 +14,5 @@ class AdminInterfaceConfig(AppConfig): def ready(self): from admin_interface import settings - from admin_interface.models import Theme settings.check_installed_apps() - post_migrate.connect(Theme.post_migrate_handler, sender=self) diff --git a/admin_interface/migrations/0001_initial.py b/admin_interface/migrations/0001_initial.py index d86ba93f..ba7d9086 100644 --- a/admin_interface/migrations/0001_initial.py +++ b/admin_interface/migrations/0001_initial.py @@ -8,6 +8,11 @@ class Migration(migrations.Migration): + + def create_default_theme(apps, schema_editor): + Theme = apps.get_model('admin_interface', 'Theme') + Theme.objects.create() + dependencies = [] operations = [ @@ -225,4 +230,5 @@ class Migration(migrations.Migration): "verbose_name_plural": "Themes", }, ), + migrations.RunPython(create_default_theme) ] diff --git a/admin_interface/models.py b/admin_interface/models.py index 25970ee2..473a1ecc 100644 --- a/admin_interface/models.py +++ b/admin_interface/models.py @@ -14,11 +14,6 @@ @python_2_unicode_compatible class Theme(models.Model): - @staticmethod - def post_migrate_handler(**kwargs): - del_cached_active_theme() - db = kwargs["using"] - Theme.get_active_theme(database=db) @staticmethod def post_delete_handler(**kwargs): From d8337385a1be4a06bbd1ef1f9760ae56b498dab7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Dec 2022 12:52:23 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- admin_interface/migrations/0001_initial.py | 6 ++---- admin_interface/models.py | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/admin_interface/migrations/0001_initial.py b/admin_interface/migrations/0001_initial.py index ba7d9086..f308515b 100644 --- a/admin_interface/migrations/0001_initial.py +++ b/admin_interface/migrations/0001_initial.py @@ -7,10 +7,8 @@ class Migration(migrations.Migration): - - def create_default_theme(apps, schema_editor): - Theme = apps.get_model('admin_interface', 'Theme') + Theme = apps.get_model("admin_interface", "Theme") Theme.objects.create() dependencies = [] @@ -230,5 +228,5 @@ def create_default_theme(apps, schema_editor): "verbose_name_plural": "Themes", }, ), - migrations.RunPython(create_default_theme) + migrations.RunPython(create_default_theme), ] diff --git a/admin_interface/models.py b/admin_interface/models.py index 473a1ecc..b32455aa 100644 --- a/admin_interface/models.py +++ b/admin_interface/models.py @@ -14,7 +14,6 @@ @python_2_unicode_compatible class Theme(models.Model): - @staticmethod def post_delete_handler(**kwargs): del_cached_active_theme() From f9767758e63a5cc2f832775ab73c7a95621f3bb7 Mon Sep 17 00:00:00 2001 From: vaz Date: Thu, 1 Dec 2022 17:28:23 +0100 Subject: [PATCH 3/7] switch to raw sql as using model throws error --- admin_interface/migrations/0001_initial.py | 65 +++++++++++++++++-- .../migrations/0020_module_selected_colors.py | 2 +- 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/admin_interface/migrations/0001_initial.py b/admin_interface/migrations/0001_initial.py index f308515b..fb1f96d1 100644 --- a/admin_interface/migrations/0001_initial.py +++ b/admin_interface/migrations/0001_initial.py @@ -7,9 +7,6 @@ class Migration(migrations.Migration): - def create_default_theme(apps, schema_editor): - Theme = apps.get_model("admin_interface", "Theme") - Theme.objects.create() dependencies = [] @@ -228,5 +225,65 @@ def create_default_theme(apps, schema_editor): "verbose_name_plural": "Themes", }, ), - migrations.RunPython(create_default_theme), + migrations.RunSQL(""" + INSERT INTO + "admin_interface_theme" ( + "name", + "active", + "title", + "title_visible", + "logo", + "logo_visible", + "css_header_background_color", + "css_header_title_color", + "css_header_text_color", + "css_header_link_color", + "css_header_link_hover_color", + "css_module_background_color", + "css_module_text_color", + "css_module_link_color", + "css_module_link_hover_color", + "css_module_rounded_corners", + "css_generic_link_color", + "css_generic_link_hover_color", + "css_save_button_background_color", + "css_save_button_background_hover_color", + "css_save_button_text_color", + "css_delete_button_background_color", + "css_delete_button_background_hover_color", + "css_delete_button_text_color", + "css", + "list_filter_dropdown" + ) + values + ( + 'Django', + true, + 'Django administration', + true, + null, + true, + "#0C4B33", + "#F5DD5D", + "#44B78B", + "#FFFFFF", + "#C9F0DD", + "#44B78B", + "#FFFFFF", + "#FFFFFF", + "#C9F0DD", + true, + "#0C3C26", + "#156641", + "#0C4B33", + "#0C3C26", + "#FFFFFF", + "#BA2121", + "#A41515", + "#FFFFFF", + '', + false + ) + """, + reverse_sql=migrations.RunPython.noop), ] diff --git a/admin_interface/migrations/0020_module_selected_colors.py b/admin_interface/migrations/0020_module_selected_colors.py index 7f69ef5d..8f6219de 100644 --- a/admin_interface/migrations/0020_module_selected_colors.py +++ b/admin_interface/migrations/0020_module_selected_colors.py @@ -44,5 +44,5 @@ class Migration(migrations.Migration): verbose_name="link selected color", ), ), - migrations.RunPython(default_link_selected), + migrations.RunPython(default_link_selected, reverse_code=migrations.RunPython.noop), ] From 73ea577b23ded85e6bcb512df2d06c1701e1b55b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Dec 2022 16:30:25 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- admin_interface/migrations/0001_initial.py | 8 +++++--- admin_interface/migrations/0020_module_selected_colors.py | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/admin_interface/migrations/0001_initial.py b/admin_interface/migrations/0001_initial.py index fb1f96d1..ba84cead 100644 --- a/admin_interface/migrations/0001_initial.py +++ b/admin_interface/migrations/0001_initial.py @@ -225,7 +225,8 @@ class Migration(migrations.Migration): "verbose_name_plural": "Themes", }, ), - migrations.RunSQL(""" + migrations.RunSQL( + """ INSERT INTO "admin_interface_theme" ( "name", @@ -284,6 +285,7 @@ class Migration(migrations.Migration): '', false ) - """, - reverse_sql=migrations.RunPython.noop), + """, + reverse_sql=migrations.RunPython.noop, + ), ] diff --git a/admin_interface/migrations/0020_module_selected_colors.py b/admin_interface/migrations/0020_module_selected_colors.py index 8f6219de..a68636f6 100644 --- a/admin_interface/migrations/0020_module_selected_colors.py +++ b/admin_interface/migrations/0020_module_selected_colors.py @@ -44,5 +44,7 @@ class Migration(migrations.Migration): verbose_name="link selected color", ), ), - migrations.RunPython(default_link_selected, reverse_code=migrations.RunPython.noop), + migrations.RunPython( + default_link_selected, reverse_code=migrations.RunPython.noop + ), ] From 007388333f53e418449b1642ed20bf873bc173bf Mon Sep 17 00:00:00 2001 From: vaz Date: Thu, 1 Dec 2022 17:37:56 +0100 Subject: [PATCH 5/7] oops .. fix strings --- admin_interface/migrations/0001_initial.py | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/admin_interface/migrations/0001_initial.py b/admin_interface/migrations/0001_initial.py index ba84cead..a62c768a 100644 --- a/admin_interface/migrations/0001_initial.py +++ b/admin_interface/migrations/0001_initial.py @@ -262,30 +262,32 @@ class Migration(migrations.Migration): true, 'Django administration', true, - null, + '', true, - "#0C4B33", - "#F5DD5D", - "#44B78B", - "#FFFFFF", - "#C9F0DD", - "#44B78B", - "#FFFFFF", - "#FFFFFF", - "#C9F0DD", + '#0C4B33', + '#F5DD5D', + '#44B78B', + '#FFFFFF', + '#C9F0DD', + '#44B78B', + '#FFFFFF', + '#FFFFFF', + '#C9F0DD', true, - "#0C3C26", - "#156641", - "#0C4B33", - "#0C3C26", - "#FFFFFF", - "#BA2121", - "#A41515", - "#FFFFFF", + '#0C3C26', + '#156641', + '#0C4B33', + '#0C3C26', + '#FFFFFF', + '#BA2121', + '#A41515', + '#FFFFFF', '', false ) - """, - reverse_sql=migrations.RunPython.noop, - ), + """, + reverse_sql=""" + DELETE FROM "admin_interface_theme" WHERE name='Django' + """ + ), ] From 329dafa5c83095430bae62ad1f51a695eae6019f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Dec 2022 16:39:18 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- admin_interface/migrations/0001_initial.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/admin_interface/migrations/0001_initial.py b/admin_interface/migrations/0001_initial.py index a62c768a..cd4429a9 100644 --- a/admin_interface/migrations/0001_initial.py +++ b/admin_interface/migrations/0001_initial.py @@ -285,9 +285,9 @@ class Migration(migrations.Migration): '', false ) - """, - reverse_sql=""" + """, + reverse_sql=""" DELETE FROM "admin_interface_theme" WHERE name='Django' - """ - ), + """, + ), ] From 2ff78ff8f4f2f2b851b748984b43d78118dc5893 Mon Sep 17 00:00:00 2001 From: vaz Date: Fri, 2 Dec 2022 10:03:19 +0100 Subject: [PATCH 7/7] To be reverted :: examples error (tests break) --- admin_interface/migrations/0001_initial.py | 65 ------------------- .../migrations/0029_auto_20221202_0849.py | 21 ++++++ ...eme_css_delete_button_bg_color_and_more.py | 58 +++++++++++++++++ admin_interface/models.py | 22 +++---- 4 files changed, 90 insertions(+), 76 deletions(-) create mode 100644 admin_interface/migrations/0029_auto_20221202_0849.py create mode 100644 admin_interface/migrations/0030_rename_css_delete_button_background_color_theme_css_delete_button_bg_color_and_more.py diff --git a/admin_interface/migrations/0001_initial.py b/admin_interface/migrations/0001_initial.py index cd4429a9..d86ba93f 100644 --- a/admin_interface/migrations/0001_initial.py +++ b/admin_interface/migrations/0001_initial.py @@ -225,69 +225,4 @@ class Migration(migrations.Migration): "verbose_name_plural": "Themes", }, ), - migrations.RunSQL( - """ - INSERT INTO - "admin_interface_theme" ( - "name", - "active", - "title", - "title_visible", - "logo", - "logo_visible", - "css_header_background_color", - "css_header_title_color", - "css_header_text_color", - "css_header_link_color", - "css_header_link_hover_color", - "css_module_background_color", - "css_module_text_color", - "css_module_link_color", - "css_module_link_hover_color", - "css_module_rounded_corners", - "css_generic_link_color", - "css_generic_link_hover_color", - "css_save_button_background_color", - "css_save_button_background_hover_color", - "css_save_button_text_color", - "css_delete_button_background_color", - "css_delete_button_background_hover_color", - "css_delete_button_text_color", - "css", - "list_filter_dropdown" - ) - values - ( - 'Django', - true, - 'Django administration', - true, - '', - true, - '#0C4B33', - '#F5DD5D', - '#44B78B', - '#FFFFFF', - '#C9F0DD', - '#44B78B', - '#FFFFFF', - '#FFFFFF', - '#C9F0DD', - true, - '#0C3C26', - '#156641', - '#0C4B33', - '#0C3C26', - '#FFFFFF', - '#BA2121', - '#A41515', - '#FFFFFF', - '', - false - ) - """, - reverse_sql=""" - DELETE FROM "admin_interface_theme" WHERE name='Django' - """, - ), ] diff --git a/admin_interface/migrations/0029_auto_20221202_0849.py b/admin_interface/migrations/0029_auto_20221202_0849.py new file mode 100644 index 00000000..7d796690 --- /dev/null +++ b/admin_interface/migrations/0029_auto_20221202_0849.py @@ -0,0 +1,21 @@ +# Generated by Django 4.1.3 on 2022-12-02 08:49 + +from django.db import migrations + + +class Migration(migrations.Migration): + def create_default_theme(apps, schema_editor): + Theme = apps.get_model("admin_interface", "Theme") + instance = Theme.objects.first() + if not instance: + Theme.objects.create() + + dependencies = [ + ("admin_interface", "0028_theme_show_fieldsets_as_tabs_and_more"), + ] + + operations = [ + migrations.RunPython( + create_default_theme, reverse_code=migrations.RunPython.noop + ), + ] diff --git a/admin_interface/migrations/0030_rename_css_delete_button_background_color_theme_css_delete_button_bg_color_and_more.py b/admin_interface/migrations/0030_rename_css_delete_button_background_color_theme_css_delete_button_bg_color_and_more.py new file mode 100644 index 00000000..bb6b0894 --- /dev/null +++ b/admin_interface/migrations/0030_rename_css_delete_button_background_color_theme_css_delete_button_bg_color_and_more.py @@ -0,0 +1,58 @@ +# Generated by Django 4.1.3 on 2022-12-02 09:02 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("admin_interface", "0029_auto_20221202_0849"), + ] + + operations = [ + migrations.RenameField( + model_name="theme", + old_name="css_delete_button_background_color", + new_name="css_delete_button_bg_color", + ), + migrations.RenameField( + model_name="theme", + old_name="css_delete_button_background_hover_color", + new_name="css_delete_button_bg_hover_color", + ), + migrations.RenameField( + model_name="theme", + old_name="css_header_background_color", + new_name="css_header_bg_color", + ), + migrations.RenameField( + model_name="theme", + old_name="css_module_background_color", + new_name="css_module_bg_color", + ), + migrations.RenameField( + model_name="theme", + old_name="css_module_background_selected_color", + new_name="css_module_bg_selected_color", + ), + migrations.RenameField( + model_name="theme", + old_name="css_save_button_background_color", + new_name="css_save_button_bg_color", + ), + migrations.RenameField( + model_name="theme", + old_name="css_save_button_background_hover_color", + new_name="css_save_button_bg_hover_color", + ), + migrations.RenameField( + model_name="theme", + old_name="related_modal_background_color", + new_name="related_modal_bg_color", + ), + migrations.RenameField( + model_name="theme", + old_name="related_modal_background_opacity", + new_name="related_modal_bg_opacity", + ), + ] diff --git a/admin_interface/models.py b/admin_interface/models.py index b32455aa..bdccc17a 100644 --- a/admin_interface/models.py +++ b/admin_interface/models.py @@ -162,7 +162,7 @@ def get_active_theme(database=None): verbose_name=_("display"), ) - css_header_background_color = ColorField( + css_header_bg_color = ColorField( blank=True, default="#0C4B33", help_text="#0C4B33", @@ -191,14 +191,14 @@ def get_active_theme(database=None): verbose_name=_("link hover color"), ) - css_module_background_color = ColorField( + css_module_bg_color = ColorField( blank=True, default="#44B78B", help_text="#44B78B", max_length=10, verbose_name=_("background color"), ) - css_module_background_selected_color = ColorField( + css_module_bg_selected_color = ColorField( blank=True, default="#FFFFCC", help_text="#FFFFCC", @@ -252,14 +252,14 @@ def get_active_theme(database=None): verbose_name=_("link hover color"), ) - css_save_button_background_color = ColorField( + css_save_button_bg_color = ColorField( blank=True, default="#0C4B33", help_text="#0C4B33", max_length=10, verbose_name=_("background color"), ) - css_save_button_background_hover_color = ColorField( + css_save_button_bg_hover_color = ColorField( blank=True, default="#0C3C26", help_text="#0C3C26", @@ -274,14 +274,14 @@ def get_active_theme(database=None): verbose_name=_("text color"), ) - css_delete_button_background_color = ColorField( + css_delete_button_bg_color = ColorField( blank=True, default="#BA2121", help_text="#BA2121", max_length=10, verbose_name=_("background color"), ) - css_delete_button_background_hover_color = ColorField( + css_delete_button_bg_hover_color = ColorField( blank=True, default="#A41515", help_text="#A41515", @@ -297,14 +297,14 @@ def get_active_theme(database=None): ) related_modal_active = models.BooleanField(default=True, verbose_name=_("active")) - related_modal_background_color = ColorField( + related_modal_bg_color = ColorField( blank=True, default="#000000", help_text="#000000", max_length=10, verbose_name=_("background color"), ) - related_modal_background_opacity_choices = ( + related_modal_bg_opacity_choices = ( ("0.1", "10%"), ("0.2", "20%"), ("0.3", "30%"), @@ -315,9 +315,9 @@ def get_active_theme(database=None): ("0.8", "80%"), ("0.9", "90%"), ) - related_modal_background_opacity = models.CharField( + related_modal_bg_opacity = models.CharField( max_length=5, - choices=related_modal_background_opacity_choices, + choices=related_modal_bg_opacity_choices, default="0.3", help_text="20%", verbose_name=_("background opacity"),