Pārlūkot izejas kodu

Replace pytz.common_timezones with zoneinfo.available_timezones

and remove pytz dependency
Sage Abdullah 1 gadu atpakaļ
vecāks
revīzija
dfe9638e7d

+ 1 - 1
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.
 

+ 0 - 1
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",

+ 4 - 2
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())
+    )

+ 5 - 2
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"])