kopia lustrzana https://github.com/wagtail/wagtail
Add theme class to HTML root based on user profile
rodzic
42600f8bec
commit
5f050ec84b
|
@ -2,7 +2,7 @@
|
|||
{% load wagtailadmin_tags i18n %}
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
{% get_current_language_bidi as LANGUAGE_BIDI %}
|
||||
<html lang="{{ LANGUAGE_CODE }}" dir="{% if LANGUAGE_BIDI %}rtl{% else %}ltr{% endif %}">
|
||||
<html lang="{{ LANGUAGE_CODE }}" dir="{% if LANGUAGE_BIDI %}rtl{% else %}ltr{% endif %}" class="w-theme-{% admin_theme_name %}">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>{% block titletag %}{% endblock %} - {% block branding_title %}Wagtail{% endblock %}</title>
|
||||
|
|
|
@ -720,6 +720,19 @@ def avatar_url(user, size=50, gravatar_only=False):
|
|||
return versioned_static_func("wagtailadmin/images/default-user-avatar.png")
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def admin_theme_name(context):
|
||||
"""
|
||||
Retrieves the theme name for the current user.
|
||||
"""
|
||||
user = context["request"].user
|
||||
return (
|
||||
user.wagtail_userprofile.theme
|
||||
if hasattr(user, "wagtail_userprofile")
|
||||
else "system"
|
||||
)
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def js_translation_strings():
|
||||
return mark_safe(json.dumps(get_js_translation_strings()))
|
||||
|
|
|
@ -436,7 +436,7 @@ class TestAccountSection(WagtailTestUtils, TestCase, TestAccountSectionUtilsMixi
|
|||
|
||||
# check that the updated language preference is now indicated in HTML header
|
||||
response = self.client.get(reverse("wagtailadmin_home"))
|
||||
self.assertContains(response, '<html lang="es" dir="ltr">')
|
||||
self.assertContains(response, '<html lang="es" dir="ltr" class="w-theme-dark">')
|
||||
|
||||
def test_unset_language_preferences(self):
|
||||
profile = UserProfile.get_for_user(self.user)
|
||||
|
|
|
@ -106,8 +106,8 @@ class TestAuditLogAdmin(WagtailTestUtils, TestCase):
|
|||
)
|
||||
|
||||
self.assertContains(
|
||||
response, "system", 2
|
||||
) # create without a user + remove restriction
|
||||
response, "system", 3
|
||||
) # create without a user + remove restriction + 1 from unrelated admin color theme
|
||||
self.assertContains(
|
||||
response, "the_editor", 9
|
||||
) # 7 entries by editor + 1 in sidebar menu + 1 in filter
|
||||
|
|
|
@ -69,12 +69,16 @@ class TestLoginView(WagtailTestUtils, TestCase):
|
|||
@override_settings(LANGUAGE_CODE="de")
|
||||
def test_language_code(self):
|
||||
response = self.client.get(reverse("wagtailadmin_login"))
|
||||
self.assertContains(response, '<html lang="de" dir="ltr">')
|
||||
self.assertContains(
|
||||
response, '<html lang="de" dir="ltr" class="w-theme-system">'
|
||||
)
|
||||
|
||||
@override_settings(LANGUAGE_CODE="he")
|
||||
def test_bidi_language_changes_dir_attribute(self):
|
||||
response = self.client.get(reverse("wagtailadmin_login"))
|
||||
self.assertContains(response, '<html lang="he" dir="rtl">')
|
||||
self.assertContains(
|
||||
response, '<html lang="he" dir="rtl" class="w-theme-system">'
|
||||
)
|
||||
|
||||
@override_settings(
|
||||
WAGTAILADMIN_USER_LOGIN_FORM="wagtail.admin.tests.test_forms.CustomLoginForm"
|
||||
|
|
Ładowanie…
Reference in New Issue