Skip to content

Creating a theme at startup and enabling it #99

@qcoumes

Description

@qcoumes

Python version
3.8

Django version
3.1

Package version
0.14.0

Current behavior (bug description)
I am creating a theme from settings in an AppConfig.ready(), the Theme models is correctly created with the right values. active is set to True (and is the only Theme ticked in the admin panel), but the Django's default one is the theme applied. I have to manually save the model once from the Django admin panel for it to be applied.

Here's my ready() function creating the Theme at startup :

class WebsiteConfig(AppConfig):
    name = 'website'
    
    
    def ready(self):
        if not {"runserver", "shell"}.intersection(sys.argv):
            return
        
        Theme = apps.get_model("admin_interface", "Theme")  # noqa
        kwargs = {
            "name":                                     "ISLRN",
            "active":                                   True,
            "title":                                    "ISLRN Administration",
            "title_color":                              settings.COLOR_PALETTE["theme_on_primary"],
            "title_visible":                            True,
            "logo":                                     "",
            "logo_color":                               "#FFFFFF",
            "logo_visible":                             False,
            "css_header_background_color":              settings.COLOR_PALETTE["theme_primary"],
            "css_header_text_color":                    settings.COLOR_PALETTE["theme_on_primary"],
            "css_header_link_color":                    settings.COLOR_PALETTE["theme_on_primary_lighter"],
            "css_header_link_hover_color":              settings.COLOR_PALETTE["theme_on_primary_darker"],
            "css_module_background_color":              settings.COLOR_PALETTE["theme_secondary"],
            "css_module_text_color":                    settings.COLOR_PALETTE["theme_on_secondary"],
            "css_module_link_color":                    settings.COLOR_PALETTE["theme_on_secondary_lighter"],
            "css_module_link_hover_color":              settings.COLOR_PALETTE["theme_on_secondary_darker"],
            "css_module_rounded_corners":               True,
            "css_generic_link_color":                   settings.COLOR_PALETTE["theme_on_default_lighter"],
            "css_generic_link_hover_color":             settings.COLOR_PALETTE["theme_on_default_darker"],
            "css_save_button_background_color":         settings.COLOR_PALETTE["theme_success"],
            "css_save_button_background_hover_color":   settings.COLOR_PALETTE["theme_success"],
            "css_save_button_text_color":               settings.COLOR_PALETTE["theme_on_success"],
            "css_delete_button_background_color":       settings.COLOR_PALETTE["theme_error"],
            "css_delete_button_background_hover_color": settings.COLOR_PALETTE["theme_error"],
            "css_delete_button_text_color":             settings.COLOR_PALETTE["theme_on_error"],
            "css":                                      "",
            "related_modal_active":                     True,
            "related_modal_background_color":           settings.COLOR_PALETTE["theme_default"],
            "related_modal_background_opacity":         0.2,
            "related_modal_rounded_corners":            True,
            "list_filter_dropdown":                     False,
            "recent_actions_visible":                   True
        }
        
        try:
            theme = Theme.objects.get(name="ISLRN")
            for k, a in kwargs.items():
                setattr(theme, k, a)
            theme.save()
        except Theme.DoesNotExist:
            Theme.objects.create(**kwargs)
        Theme.get_active_theme()

Expected behavior
I expected the created Theme to be applied immediately since it's the only Theme with active set to True.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions