mirror of
https://github.com/wagtail/wagtail.git
synced 2024-12-01 11:41:20 +01:00
Convert time zone preferences into a settings panel
This commit is contained in:
parent
64f0543df6
commit
662bb6e2c3
@ -1,20 +0,0 @@
|
||||
{% extends "wagtailadmin/base.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block titletag %}{% trans "Set Time Zone" %}{% endblock %}
|
||||
{% block content %}
|
||||
{% trans "Set Time Zone" as prefs_str %}
|
||||
{% include "wagtailadmin/shared/header.html" with title=prefs_str %}
|
||||
|
||||
<div class="nice-padding">
|
||||
<form action="{% url 'wagtailadmin_account_current_time_zone' %}" method="POST" novalidate>
|
||||
{% csrf_token %}
|
||||
<ul class="fields">
|
||||
{% for field in form %}
|
||||
{% include "wagtailadmin/shared/field_as_li.html" with field=field %}
|
||||
{% endfor %}
|
||||
<li class="submit"><input type="submit" value="{% trans 'Update' %}" class="button" /></li>
|
||||
</ul>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
@ -198,6 +198,7 @@ class TestAccountSectionUtilsMixin:
|
||||
'notifications-rejected_notifications': 'true',
|
||||
'notifications-updated_comments_notifications': 'true',
|
||||
'language-preferred_language': 'es',
|
||||
'time-zone-current_time_zone': 'Europe/London',
|
||||
}
|
||||
post_data.update(extra_post_data)
|
||||
return self.client.post(reverse('wagtailadmin_account'), post_data)
|
||||
@ -225,6 +226,7 @@ class TestAccountSection(TestCase, WagtailTestUtils, TestAccountSectionUtilsMixi
|
||||
self.assertPanelActive(response, 'email')
|
||||
self.assertPanelActive(response, 'notifications')
|
||||
self.assertPanelActive(response, 'language')
|
||||
self.assertPanelActive(response, 'time-zone')
|
||||
|
||||
# Page should contain a 'Change password' option
|
||||
self.assertContains(response, "Change password")
|
||||
@ -424,50 +426,30 @@ class TestAccountSection(TestCase, WagtailTestUtils, TestAccountSectionUtilsMixi
|
||||
response = self.client.get(reverse('wagtailadmin_account'))
|
||||
self.assertPanelNotActive(response, 'language')
|
||||
|
||||
def test_current_time_zone_view(self):
|
||||
"""
|
||||
This tests that the current time zone view responds with an index page
|
||||
"""
|
||||
# Get account page
|
||||
response = self.client.get(reverse('wagtailadmin_account_current_time_zone'))
|
||||
|
||||
# Check that the user received an account page
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertTemplateUsed(response, 'wagtailadmin/account/current_time_zone.html')
|
||||
|
||||
# Page should contain a 'Set Time Zone' title
|
||||
self.assertContains(response, "Set Time Zone")
|
||||
|
||||
def test_current_time_zone_view_post(self):
|
||||
"""
|
||||
This posts to the current time zone view and checks that the
|
||||
user profile is updated
|
||||
"""
|
||||
# Post new values to the current time zone page
|
||||
post_data = {
|
||||
'current_time_zone': 'Pacific/Fiji'
|
||||
}
|
||||
response = self.client.post(reverse('wagtailadmin_account_current_time_zone'), post_data)
|
||||
def test_change_current_time_zone(self):
|
||||
response = self.post_form({
|
||||
'time-zone-current_time_zone': 'Pacific/Fiji',
|
||||
})
|
||||
|
||||
# Check that the user was redirected to the account page
|
||||
self.assertRedirects(response, reverse('wagtailadmin_account'))
|
||||
|
||||
profile = UserProfile.get_for_user(get_user_model().objects.get(pk=self.user.pk))
|
||||
profile = UserProfile.get_for_user(self.user)
|
||||
profile.refresh_from_db()
|
||||
|
||||
# Check that the current time zone is stored
|
||||
self.assertEqual(profile.current_time_zone, 'Pacific/Fiji')
|
||||
|
||||
def test_unset_current_time_zone(self):
|
||||
# Post new values to the current time zone page
|
||||
post_data = {
|
||||
'current_time_zone': ''
|
||||
}
|
||||
response = self.client.post(reverse('wagtailadmin_account_current_time_zone'), post_data)
|
||||
response = self.post_form({
|
||||
'time-zone-current_time_zone': '',
|
||||
})
|
||||
|
||||
# Check that the user was redirected to the account page
|
||||
self.assertRedirects(response, reverse('wagtailadmin_account'))
|
||||
|
||||
profile = UserProfile.get_for_user(get_user_model().objects.get(pk=self.user.pk))
|
||||
profile = UserProfile.get_for_user(self.user)
|
||||
profile.refresh_from_db()
|
||||
|
||||
# Check that the current time zone are stored
|
||||
self.assertEqual(profile.current_time_zone, '')
|
||||
@ -483,7 +465,7 @@ class TestAccountSection(TestCase, WagtailTestUtils, TestAccountSectionUtilsMixi
|
||||
@override_settings(WAGTAIL_USER_TIME_ZONES=['Europe/London'])
|
||||
def test_not_show_options_if_only_one_time_zone_is_permitted(self):
|
||||
response = self.client.get(reverse('wagtailadmin_account'))
|
||||
self.assertNotContains(response, 'Set Time Zone')
|
||||
self.assertPanelNotActive(response, 'time-zone')
|
||||
|
||||
|
||||
class TestAccountUploadAvatar(TestCase, WagtailTestUtils, TestAccountSectionUtilsMixin):
|
||||
|
@ -54,11 +54,6 @@ urlpatterns = [
|
||||
|
||||
path('account/', account.account, name='wagtailadmin_account'),
|
||||
path('account/change_password/', account.change_password, name='wagtailadmin_account_change_password'),
|
||||
path(
|
||||
'account/current_time_zone/',
|
||||
account.current_time_zone,
|
||||
name='wagtailadmin_account_current_time_zone'
|
||||
),
|
||||
path('logout/', account.LogoutView.as_view(), name='wagtailadmin_logout'),
|
||||
]
|
||||
|
||||
|
@ -14,7 +14,7 @@ from django.utils.translation import gettext_lazy, override
|
||||
from django.views.decorators.debug import sensitive_post_parameters
|
||||
|
||||
from wagtail.admin.forms.auth import LoginForm, PasswordResetForm
|
||||
from wagtail.admin.localization import get_available_admin_languages
|
||||
from wagtail.admin.localization import get_available_admin_languages, get_available_admin_time_zones
|
||||
from wagtail.core import hooks
|
||||
from wagtail.core.models import UserPagePermissionsProxy
|
||||
from wagtail.users.forms import (
|
||||
@ -152,6 +152,17 @@ class LanguageSettingsPanel(BaseSettingsPanel):
|
||||
return len(get_available_admin_languages()) > 1
|
||||
|
||||
|
||||
class TimeZoneSettingsPanel(BaseSettingsPanel):
|
||||
name = 'time-zone'
|
||||
title = gettext_lazy('Time Zone')
|
||||
order = 500
|
||||
form_class = CurrentTimeZoneForm
|
||||
form_object = 'profile'
|
||||
|
||||
def is_active(self):
|
||||
return len(get_available_admin_time_zones()) > 1
|
||||
|
||||
|
||||
# Views
|
||||
|
||||
def account(request):
|
||||
@ -167,6 +178,7 @@ def account(request):
|
||||
AvatarSettingsPanel(request, user, profile),
|
||||
NotificationsSettingsPanel(request, user, profile),
|
||||
LanguageSettingsPanel(request, user, profile),
|
||||
TimeZoneSettingsPanel(request, user, profile),
|
||||
]
|
||||
for fn in hooks.get_hooks('register_account_settings_panel'):
|
||||
panel = fn(request, user, profile)
|
||||
@ -267,22 +279,6 @@ class PasswordResetCompleteView(PasswordResetEnabledViewMixin, auth_views.Passwo
|
||||
template_name = 'wagtailadmin/account/password_reset/complete.html'
|
||||
|
||||
|
||||
def current_time_zone(request):
|
||||
if request.method == 'POST':
|
||||
form = CurrentTimeZoneForm(request.POST, instance=UserProfile.get_for_user(request.user))
|
||||
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
messages.success(request, _("Your preferences have been updated."))
|
||||
return redirect('wagtailadmin_account')
|
||||
else:
|
||||
form = CurrentTimeZoneForm(instance=UserProfile.get_for_user(request.user))
|
||||
|
||||
return TemplateResponse(request, 'wagtailadmin/account/current_time_zone.html', {
|
||||
'form': form,
|
||||
})
|
||||
|
||||
|
||||
class LoginView(auth_views.LoginView):
|
||||
template_name = 'wagtailadmin/login.html'
|
||||
|
||||
|
@ -8,7 +8,6 @@ from draftjs_exporter.dom import DOM
|
||||
import wagtail.admin.rich_text.editors.draftail.features as draftail_features
|
||||
|
||||
from wagtail.admin.auth import user_has_any_page_permission
|
||||
from wagtail.admin.localization import get_available_admin_time_zones
|
||||
from wagtail.admin.menu import MenuItem, SubmenuMenuItem, reports_menu, settings_menu
|
||||
from wagtail.admin.navigation import get_explorable_root_page
|
||||
from wagtail.admin.rich_text import (
|
||||
@ -258,16 +257,6 @@ def register_account_change_password(request):
|
||||
}
|
||||
|
||||
|
||||
@hooks.register('register_account_menu_item')
|
||||
def register_account_current_time_zone(request):
|
||||
if len(get_available_admin_time_zones()) > 1:
|
||||
return {
|
||||
'url': reverse('wagtailadmin_account_current_time_zone'),
|
||||
'label': _('Current Time Zone'),
|
||||
'help_text': _('Choose your current time zone.'),
|
||||
}
|
||||
|
||||
|
||||
@hooks.register('register_rich_text_features')
|
||||
def register_core_features(features):
|
||||
# Hallo.js
|
||||
|
Loading…
Reference in New Issue
Block a user