Jelajahi Sumber

Fix timesince_last_update for naive datetimes (USE_TZ=False)

Fixes #6345
Matt Westcott 4 tahun lalu
induk
melakukan
e3bbccd814

+ 1 - 0
CHANGELOG.txt

@@ -21,6 +21,7 @@ Changelog
  * Fix: Prevent page audit log views from failing for user models without a `username` field (Vyacheslav Matyukhin)
  * Fix: Fix icon alignment on menu items (Coen van der Kamp)
  * Fix: Page editor header bar now correctly shows 'Published' or 'Draft' status when no revisions exist (Matt Westcott)
+ * Fix: Prevent page editor from failing when `USE_TZ` is false (Matt Westcott)
 
 
 2.10 (11.08.2020)

+ 1 - 0
docs/releases/2.10.1.rst

@@ -17,3 +17,4 @@ Bug fixes
  * Prevent page audit log views from failing for user models without a ``username`` field (Vyacheslav Matyukhin)
  * Fix icon alignment on menu items (Coen van der Kamp)
  * Page editor header bar now correctly shows 'Published' or 'Draft' status when no revisions exist (Matt Westcott)
+ * Prevent page editor from failing when ``USE_TZ`` is false (Matt Westcott)

+ 5 - 1
wagtail/admin/templatetags/wagtailadmin_tags.py

@@ -584,7 +584,11 @@ def timesince_last_update(last_update, time_prefix='', use_shorthand=True):
            but can return the full string if needed
     """
     if last_update.date() == datetime.today().date():
-        time_str = timezone.localtime(last_update).strftime("%H:%M")
+        if timezone.is_aware(last_update):
+            time_str = timezone.localtime(last_update).strftime("%H:%M")
+        else:
+            time_str = last_update.strftime("%H:%M")
+
         return time_str if not time_prefix else '%(prefix)s %(formatted_time)s' % {
             'prefix': time_prefix, 'formatted_time': time_str
         }