Skip to content

Fix not using localized formats in human_readable_date template tag #13219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

SebCorbin
Copy link
Contributor

@SebCorbin SebCorbin changed the title Fix not using localized formats in template tag Fix not using localized formats in human_readable_date template tag Jul 9, 2025
@SebCorbin SebCorbin requested a review from Copilot July 9, 2025 12:18
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the human_readable_date template tag to use Django’s localized date and datetime formats instead of the raw settings values.

  • Imported get_format from django.utils.formats
  • Replaced direct settings.DATETIME_FORMAT and settings.DATE_FORMAT lookups with get_format(... ) or fallback
  • Maintains existing fallback patterns if no localized format is defined
Comments suppressed due to low confidence (2)

wagtail/admin/templatetags/wagtailadmin_tags.py:1355

  • Add unit tests to verify that human_readable_date correctly falls back to the default format and uses locale-specific formats returned by get_format.
        tooltip_format = get_format("DATETIME_FORMAT") or "N j, Y, P"

wagtail/admin/templatetags/wagtailadmin_tags.py:1353

  • [nitpick] Consider adding a short docstring for human_readable_date to explain its behavior with localized formats and fallback logic.
def human_readable_date(date, description=None, placement="top"):

@lb- lb- added component:UI localization l10n & i18n for admin interface only status:Needs Review labels Jul 13, 2025
- Ensure the `human_readable_date` template tag, the formats are not taken directly from django.conf.settings.
- Instead, use instead the format localization getter `django.utils.formats.get_format`.
- Fixes wagtail#13217
Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for noticing this and putting up the fix.

@lb- lb- force-pushed the 13217-human_readable_date-should-use-localized-formats branch from 60f832d to 94d7987 Compare July 13, 2025 10:35
@lb- lb- merged commit 377b862 into wagtail:main Jul 13, 2025
19 checks passed
@SebCorbin SebCorbin deleted the 13217-human_readable_date-should-use-localized-formats branch July 15, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:UI localization l10n & i18n for admin interface only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants