From dfe9638e7dec6263f4975dfcf1274e1cb26d53f2 Mon Sep 17 00:00:00 2001 From: Sage Abdullah Date: Fri, 22 Mar 2024 06:07:12 +0700 Subject: [PATCH] Replace pytz.common_timezones with zoneinfo.available_timezones and remove pytz dependency --- docs/reference/settings.md | 2 +- setup.py | 1 - wagtail/admin/localization.py | 6 ++++-- wagtail/admin/tests/test_account_management.py | 7 +++++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/reference/settings.md b/docs/reference/settings.md index b2ac511a48..e66cd943b7 100644 --- a/docs/reference/settings.md +++ b/docs/reference/settings.md @@ -589,7 +589,7 @@ If a user has not uploaded a profile picture, Wagtail will look for an avatar li Logged-in users can choose their current time zone for the admin interface in the account settings. If there is no time zone selected by the user, then `TIME_ZONE` will be used. (Note that time zones are only applied to datetime fields, not to plain time or date fields. This is a Django design decision.) -The list of time zones is by default the common_timezones list from pytz. +By default, this uses the set of timezones returned by `zoneinfo.available_timezones()`. It is possible to override this list via the `WAGTAIL_USER_TIME_ZONES` setting. If there is zero or one-time zone permitted, the account settings form will be hidden. diff --git a/setup.py b/setup.py index 4d0cdd620b..d43534c844 100755 --- a/setup.py +++ b/setup.py @@ -42,7 +42,6 @@ install_requires = [ testing_extras = [ # Required for running the tests "python-dateutil>=2.7", - "pytz>=2014.7", "Jinja2>=3.0,<3.2", "boto3>=1.28,<2", "freezegun>=0.3.8", diff --git a/wagtail/admin/localization.py b/wagtail/admin/localization.py index 0583f596af..5a6e5dd669 100644 --- a/wagtail/admin/localization.py +++ b/wagtail/admin/localization.py @@ -1,4 +1,4 @@ -import pytz +import zoneinfo from django.conf import settings from django.utils.dates import MONTHS, WEEKDAYS, WEEKDAYS_ABBR from django.utils.translation import gettext as _ @@ -106,4 +106,6 @@ def get_available_admin_time_zones(): if not settings.USE_TZ: return [] - return getattr(settings, "WAGTAIL_USER_TIME_ZONES", pytz.common_timezones) + return getattr( + settings, "WAGTAIL_USER_TIME_ZONES", sorted(zoneinfo.available_timezones()) + ) diff --git a/wagtail/admin/tests/test_account_management.py b/wagtail/admin/tests/test_account_management.py index 2a5ae41cd8..ec0f8858fa 100644 --- a/wagtail/admin/tests/test_account_management.py +++ b/wagtail/admin/tests/test_account_management.py @@ -1,6 +1,6 @@ import unittest -import pytz +import zoneinfo from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth import views as auth_views @@ -567,7 +567,10 @@ class TestAccountSection(WagtailTestUtils, TestCase, TestAccountSectionUtilsMixi @unittest.skipUnless(settings.USE_TZ, "Timezone support is disabled") def test_available_admin_time_zones_by_default(self): - self.assertListEqual(get_available_admin_time_zones(), pytz.common_timezones) + self.assertListEqual( + get_available_admin_time_zones(), + sorted(zoneinfo.available_timezones()), + ) @unittest.skipUnless(settings.USE_TZ, "Timezone support is disabled") @override_settings(WAGTAIL_USER_TIME_ZONES=["Europe/London"])