diff --git a/README.md b/README.md
index bfa44b34..c80d0d13 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,7 @@ Unfold is theme for Django admin incorporating most common practises for buildin
- **Tabs:** define custom tab navigations for models
- **Colors:** possibility to override default color scheme
- **Third party packages:** default support for multiple popular applications
+- **Environment label**: distinguish between environments by displaying a label
## Table of contents
@@ -155,10 +156,11 @@ UNFOLD = {
"SITE_URL": "/",
"SITE_ICON": lambda request: static("logo.svg"),
"SITE_SYMBOL": "speed", # symbol from icon set
+ "ENVIRONMENT": "sample_app.environment_callback",
"DASHBOARD_CALLBACK": "sample_app.dashboard_callback",
"LOGIN": {
- "image": lambda r: static("sample/login-bg.jpg"),
- "redirect_after": lambda r: reverse_lazy("admin:APP_MODEL_changelist"),
+ "image": lambda request: static("sample/login-bg.jpg"),
+ "redirect_after": lambda request: reverse_lazy("admin:APP_MODEL_changelist"),
},
"STYLES": [
lambda request: static("css/style.css"),
@@ -244,6 +246,14 @@ def dashboard_callback(request, context):
return context
+def environment_callback(request):
+ """
+ Callback has to return a list of two values represeting text value and the color
+ type of the label displayed in top right corner.
+ """
+ return ["Production", "danger"] # info, danger, warning, success
+
+
def badge_callback(request):
return 3
@@ -808,12 +818,6 @@ Below you can find a more complex example which is using multiple components and
```html+django
{% load i18n %}
-{% block content_before %}
- {% component "unfold/components/header.html" %}
- {% trans "Unfold Dashboard" %}
- {% endcomponent %}
-{% endblock %}
-
{% block content %}
{% component "unfold/components/container.html" %}
{% component "unfold/components/flex.html" with class="gap-4"%}
@@ -851,7 +855,6 @@ Below you can find a more complex example which is using multiple components and
| unfold/components/card.html | Card component | class, title, footer, label |
| unfold/components/container.html | Wrapper for settings max width | class |
| unfold/components/flex.html | Flex items | class, col |
-| unfold/components/header.html | Page header, user links | class |
| unfold/components/navigation.html | List of navigation links | class, items |
| unfold/components/progress.html | Percentual progress bar | class, value, title, description |
| unfold/components/separator.html | Separator, horizontal rule | class |
diff --git a/src/unfold/settings.py b/src/unfold/settings.py
index 75551e6f..7d8bd932 100644
--- a/src/unfold/settings.py
+++ b/src/unfold/settings.py
@@ -24,6 +24,7 @@
},
},
"DASHBOARD_CALLBACK": None,
+ "ENVIRONMENT": None,
"STYLES": [],
"SCRIPTS": [],
"SIDEBAR": {
diff --git a/src/unfold/sites.py b/src/unfold/sites.py
index 3ae7ef31..b74d0afc 100644
--- a/src/unfold/sites.py
+++ b/src/unfold/sites.py
@@ -86,6 +86,15 @@ def each_context(self, request: HttpRequest) -> Dict[str, Any]:
}
)
+ environment = get_config(self.settings_name)["ENVIRONMENT"]
+
+ if environment and isinstance(environment, str):
+ try:
+ callback = import_string(environment)
+ context.update({"environment": callback(request)})
+ except ImportError:
+ pass
+
return context
def index(
diff --git a/src/unfold/templates/admin/base.html b/src/unfold/templates/admin/base.html
index bb8c7a16..27fbec17 100644
--- a/src/unfold/templates/admin/base.html
+++ b/src/unfold/templates/admin/base.html
@@ -11,29 +11,7 @@
{% endif %}
- {% if not is_popup %}
- {% block header %}
-
- {% endblock %}
- {% endif %}
+ {% include "unfold/helpers/header.html" %}
{% if not is_popup %}
{% spaceless %}
diff --git a/src/unfold/templates/unfold/components/container.html b/src/unfold/templates/unfold/components/container.html
index 74fceb4a..d46664f4 100644
--- a/src/unfold/templates/unfold/components/container.html
+++ b/src/unfold/templates/unfold/components/container.html
@@ -1,3 +1,3 @@
-
- {{ children }}
+
+ {{ children }}
diff --git a/src/unfold/templates/unfold/components/header.html b/src/unfold/templates/unfold/components/header.html
deleted file mode 100644
index f71f76bb..00000000
--- a/src/unfold/templates/unfold/components/header.html
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
- {{ children }}
-
-
-
- {% include "unfold/helpers/theme_switch.html" %}
-
- {% include "unfold/helpers/account_links.html" %}
-
-
-
-
-
diff --git a/src/unfold/templates/unfold/helpers/field.html b/src/unfold/templates/unfold/helpers/field.html
index 1ff07fc4..ffc6cc72 100644
--- a/src/unfold/templates/unfold/helpers/field.html
+++ b/src/unfold/templates/unfold/helpers/field.html
@@ -1,5 +1,5 @@
- {% include "unfold/helpers/label.html" with field=field %}
+ {% include "unfold/helpers/form_label.html" with field=field %}
{{ field }}
diff --git a/src/unfold/templates/unfold/helpers/form_label.html b/src/unfold/templates/unfold/helpers/form_label.html
new file mode 100644
index 00000000..1cc4893e
--- /dev/null
+++ b/src/unfold/templates/unfold/helpers/form_label.html
@@ -0,0 +1,7 @@
+
diff --git a/src/unfold/templates/unfold/helpers/header.html b/src/unfold/templates/unfold/helpers/header.html
new file mode 100644
index 00000000..650fd677
--- /dev/null
+++ b/src/unfold/templates/unfold/helpers/header.html
@@ -0,0 +1,23 @@
+{% if not is_popup %}
+ {% block header %}
+
+ {% endblock %}
+{% endif %}
diff --git a/src/unfold/templates/unfold/helpers/label.html b/src/unfold/templates/unfold/helpers/label.html
index 1cc4893e..47ba72c9 100644
--- a/src/unfold/templates/unfold/helpers/label.html
+++ b/src/unfold/templates/unfold/helpers/label.html
@@ -1,7 +1,15 @@
-