Skip to content

Commit 6316427

Browse files
authored
feat: environment title prefix (#1081)
1 parent 610e4fd commit 6316427

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

docs/configuration/settings.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ UNFOLD = {
5050
"SHOW_HISTORY": True, # show/hide "History" button, default: True
5151
"SHOW_VIEW_ON_SITE": True, # show/hide "View on site" button, default: True
5252
"SHOW_BACK_BUTTON": False, # show/hide "Back" button on changeform in header, default: False
53-
"ENVIRONMENT": "sample_app.environment_callback",
53+
"ENVIRONMENT": "sample_app.environment_callback", # environment name in header
54+
"ENVIRONMENT_TITLE_PREFIX": "sample_app.environment_title_prefix_callback", # environment name prefix in title tag
5455
"DASHBOARD_CALLBACK": "sample_app.dashboard_callback",
5556
"THEME": "dark", # Force theme: "dark" or "light". Will disable theme switcher
5657
"LOGIN": {

src/unfold/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
},
5555
"DASHBOARD_CALLBACK": None,
5656
"ENVIRONMENT": None,
57+
"ENVIRONMENT_TITLE_PREFIX": None,
5758
"STYLES": [],
5859
"SCRIPTS": [],
5960
"SIDEBAR": {

src/unfold/sites.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ def each_context(self, request: HttpRequest) -> dict[str, Any]:
8888
"border_radius": self._get_config("BORDER_RADIUS", request),
8989
"colors": self._get_colors("COLORS", request),
9090
"environment": self._get_config("ENVIRONMENT", request),
91+
"environment_title_prefix": self._get_config(
92+
"ENVIRONMENT_TITLE_PREFIX", request
93+
),
9194
"tab_list": self.get_tabs_list(request),
9295
"styles": self._get_list("STYLES", request),
9396
"scripts": self._get_list("SCRIPTS", request),

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
<!DOCTYPE html>
1616
<html lang="{{ LANGUAGE_CODE|default:"en-us" }}" dir="{{ LANGUAGE_BIDI|yesno:"rtl,ltr,auto" }}" {% if theme %}class="{{ theme }}"{% endif %} x-data="{ adminTheme: {% if theme %}'{{ theme }}'{% else %}$persist('auto').as('adminTheme'){% endif %} }" x-bind:class="{'dark': adminTheme === 'dark' || (adminTheme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches)}" x-cloak>
17-
1817
<head>
19-
<title>{% block title %}{% endblock %}</title>
18+
<title>{{ environment_title_prefix|default:"" }} {% block title %}{% endblock %}</title>
2019

2120
<link href="{% static "unfold/fonts/inter/styles.css" %}" rel="stylesheet">
2221
<link href="{% static "unfold/fonts/material-symbols/styles.css" %}" rel="stylesheet">

tests/test_environment.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ def environment_callback(request):
1010
return ["Testing Environment", "warning"]
1111

1212

13+
def environment_title_prefix_callback(request):
14+
return "[TEST]"
15+
16+
1317
@override_settings(UNFOLD={**CONFIG_DEFAULTS})
1418
def test_environment_empty_environment_callback():
1519
admin_site = UnfoldAdminSite()
@@ -55,3 +59,20 @@ def test_environment_correct_environment_callback():
5559
context = admin_site.each_context(request)
5660
assert "environment" in context
5761
assert context["environment"] == ["Testing Environment", "warning"]
62+
63+
64+
@override_settings(
65+
UNFOLD={
66+
**CONFIG_DEFAULTS,
67+
**{
68+
"ENVIRONMENT_TITLE_PREFIX": "tests.test_environment.environment_title_prefix_callback",
69+
},
70+
}
71+
)
72+
def test_environment_title_prefix_correct_environment_callback():
73+
admin_site = UnfoldAdminSite()
74+
request = RequestFactory().get("/rand")
75+
request.user = AnonymousUser()
76+
context = admin_site.each_context(request)
77+
assert "environment_title_prefix" in context
78+
assert context["environment_title_prefix"] == "[TEST]"

0 commit comments

Comments
 (0)