Skip to content

Commit f1e4dd0

Browse files
authored
feat: force design theme (#308)
1 parent 9ae600b commit f1e4dd0

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ UNFOLD = {
175175
"SHOW_VIEW_ON_SITE": True, # show/hide "View on site" button, default: True
176176
"ENVIRONMENT": "sample_app.environment_callback",
177177
"DASHBOARD_CALLBACK": "sample_app.dashboard_callback",
178+
"THEME": "dark", # Force theme: "dark" or "light". Will disable theme switcher
178179
"LOGIN": {
179180
"image": lambda request: static("sample/login-bg.jpg"),
180181
"redirect_after": lambda request: reverse_lazy("admin:APP_MODEL_changelist"),

src/unfold/sites.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def each_context(self, request: HttpRequest) -> Dict[str, Any]:
7878
self._get_value(style, request)
7979
for style in get_config(self.settings_name)["STYLES"]
8080
],
81+
"theme": get_config(self.settings_name).get("THEME"),
8182
"scripts": [
8283
self._get_value(script, request)
8384
for script in get_config(self.settings_name)["SCRIPTS"]

src/unfold/templates/unfold/helpers/userlinks.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
{% include "unfold/helpers/label.html" with text=environment.0 type=environment.1 %}
88
{% endif %}
99

10-
{% include "unfold/helpers/theme_switch.html" %}
10+
{% if not theme %}
11+
{% include "unfold/helpers/theme_switch.html" %}
12+
{% endif %}
1113

1214
{% include "unfold/helpers/account_links.html" %}
1315
</div>

src/unfold/templates/unfold/layouts/skeleton.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{% capture as actions_items silent %}{% block actions-items %}{% endblock %}{% endcapture %}
1313

1414
<!DOCTYPE html>
15-
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" dir="{{ LANGUAGE_BIDI|yesno:"rtl,ltr,auto" }}" x-data="{ adminTheme: $persist('auto').as('adminTheme') }" x-bind:class="{'dark': adminTheme === 'dark' || (adminTheme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches)}" x-cloak>
15+
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" dir="{{ LANGUAGE_BIDI|yesno:"rtl,ltr,auto" }}" {% if theme %}class="{{ theme }}"{% else %}x-data="{ adminTheme: $persist('auto').as('adminTheme') }" x-bind:class="{'dark': adminTheme === 'dark' || (adminTheme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches)}" x-cloak{% endif %}>
1616

1717
<head>
1818
<title>{% block title %}{% endblock %}</title>

0 commit comments

Comments
 (0)