-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98ca4b3
commit badb964
Showing
9 changed files
with
210 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,19 @@ | ||
{% load i18n %} | ||
|
||
{% if icon %} | ||
{% if site_icon %} | ||
<a href="{% url "admin:index" %}"> | ||
<img src="{{ icon }}" class="h-8 mr-4" alt="{% trans "Home" %}"/> | ||
{% if site_icon.light and site_icon.dark %} | ||
<img src="{{ site_icon.dark }}" alt="{% trans 'Home' %}" class="h-8 hidden mr-4 dark:block"/> | ||
|
||
<img src="{{ site_icon.light }}" alt="{% trans 'Home' %}" class="block h-8 mr-4 dark:hidden" /> | ||
{% else %} | ||
<img src="{{ site_icon }}" class="h-8 mr-4" alt="{% trans 'Home' %}" /> | ||
{% endif %} | ||
</a> | ||
{% else %} | ||
<a href="{% url "admin:index" %}" class="bg-primary-600 flex h-8 items-center justify-center rounded-md mr-4 text-white text-xs w-8"> | ||
<span class="material-symbols-outlined md-18">{% if symbol %}{{ symbol }}{% else %}settings{% endif %}</span> | ||
<span class="material-symbols-outlined md-18">{% if site_symbol %}{{ site_symbol }}{% else %}settings{% endif %}</span> | ||
</a> | ||
{% endif %} | ||
|
||
{{ branding }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% load i18n %} | ||
|
||
<a href="{% url "admin:index" %}"> | ||
{% if site_logo.light and site_logo.dark %} | ||
<img src="{{ site_logo.dark }}" alt="{% trans 'Home' %}" class="h-8 hidden mr-4 dark:block"/> | ||
|
||
<img src="{{ site_logo.light }}" alt="{% trans 'Home' %}" class="block h-8 mr-4 dark:hidden" /> | ||
{% else %} | ||
<img src="{{ site_logo }}" class="h-8 mr-4" alt="{% trans 'Home' %}" /> | ||
{% endif %} | ||
</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
from django.contrib.auth.models import AnonymousUser | ||
from django.templatetags.static import static | ||
from django.test import TestCase | ||
from django.test.client import RequestFactory | ||
from django.test.utils import override_settings | ||
from unfold.settings import CONFIG_DEFAULTS, get_config | ||
from unfold.sites import UnfoldAdminSite | ||
|
||
|
||
class SiteBrandingTestCase(TestCase): | ||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"SITE_ICON": lambda request: static("icon.svg"), | ||
}, | ||
} | ||
) | ||
def test_correct_callback_site_icon(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
request.user = AnonymousUser() | ||
context = admin_site.each_context(request) | ||
self.assertEqual(context["site_icon"], "icon.svg") | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"SITE_ICON": "hardcoded-icon.svg", | ||
}, | ||
} | ||
) | ||
def test_correct_string_site_icon(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
request.user = AnonymousUser() | ||
context = admin_site.each_context(request) | ||
self.assertEqual(context["site_icon"], "hardcoded-icon.svg") | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"SITE_ICON": { | ||
"light": lambda request: static("icon-light.svg"), | ||
"dark": lambda request: static("icon-dark.svg"), | ||
} | ||
}, | ||
} | ||
) | ||
def test_correct_mode_site_icon(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
request.user = AnonymousUser() | ||
context = admin_site.each_context(request) | ||
self.assertDictEqual( | ||
context["site_icon"], {"light": "icon-light.svg", "dark": "icon-dark.svg"} | ||
) | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"SITE_ICON": { | ||
"light": lambda request: static("icon.svg"), | ||
} | ||
}, | ||
} | ||
) | ||
def test_incorrect_mode_site_icon(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
request.user = AnonymousUser() | ||
context = admin_site.each_context(request) | ||
self.assertIsNone(context["site_icon"]) | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"SITE_LOGO": lambda request: static("logo.svg"), | ||
}, | ||
} | ||
) | ||
def test_correct_callback_site_logo(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
request.user = AnonymousUser() | ||
context = admin_site.each_context(request) | ||
self.assertEqual(context["site_logo"], "logo.svg") | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"SITE_LOGO": "hardcoded-logo.svg", | ||
}, | ||
} | ||
) | ||
def test_correct_string_site_logo(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
request.user = AnonymousUser() | ||
context = admin_site.each_context(request) | ||
self.assertEqual(context["site_logo"], "hardcoded-logo.svg") | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"SITE_LOGO": { | ||
"light": lambda request: static("logo-light.svg"), | ||
"dark": lambda request: static("logo-dark.svg"), | ||
} | ||
}, | ||
} | ||
) | ||
def test_correct_mode_site_logo(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
request.user = AnonymousUser() | ||
context = admin_site.each_context(request) | ||
self.assertDictEqual( | ||
context["site_logo"], {"light": "logo-light.svg", "dark": "logo-dark.svg"} | ||
) | ||
get_config.cache_clear() | ||
|
||
@override_settings( | ||
UNFOLD={ | ||
**CONFIG_DEFAULTS, | ||
**{ | ||
"SITE_LOGO": { | ||
"light": lambda request: static("logo.svg"), | ||
} | ||
}, | ||
} | ||
) | ||
def test_incorrect_mode_site_logo(self): | ||
admin_site = UnfoldAdminSite() | ||
request = RequestFactory().get("/rand") | ||
request.user = AnonymousUser() | ||
context = admin_site.each_context(request) | ||
self.assertIsNone(context["site_logo"]) | ||
get_config.cache_clear() |