diff --git a/site_settings/context_processors.py b/site_settings/context_processors.py index 5bd44712..d2352314 100644 --- a/site_settings/context_processors.py +++ b/site_settings/context_processors.py @@ -1,28 +1,25 @@ +from django.core.exceptions import ObjectDoesNotExist + from site_settings.models import Theme +default_theme = { + 'primary_color': '#363636', + 'primary_hover_color': '#67a9ce', + 'secondary_color': '#ffffff', + 'border_radius': '1.5em', + 'box_shadow': 'elevation-1' +} -def theme(request): - theme_ls = Theme.objects.all() - - for theme_item in theme_ls: - if theme_item.is_default: - theme = { - 'primary_color': theme_item.primary_color, - 'primary_hover_color': theme_item.primary_hover_color, - 'secondary_color': theme_item.secondary_color, - 'border_radius': f"{theme_item.border_radius * 0.06}em", - 'box_shadow': f"elevation-{theme_item.box_shadow}", - } - - else: - theme = { - 'primary_color': '#363636', - 'primary_hover_color': '#67a9ce', - 'secondary_color': '#ffffff', - 'border_radius': '1.5em', - 'box_shadow': 'elevation-1' - } - - - return theme +def theme(request): + try: + theme = Theme.objects.get(is_default=True) + return { + 'primary_color': theme.primary_color, + 'primary_hover_color': theme.primary_hover_color, + 'secondary_color': theme.secondary_color, + 'border_radius': f"{theme.border_radius * 0.06}em", + 'box_shadow': f"elevation-{theme.box_shadow}", + } + except ObjectDoesNotExist: + return default_theme \ No newline at end of file