Opened 7 years ago

Closed 7 years ago

#28544 closed Bug (fixed)

unlocalize template filter not consistent with "localize off" for datetimes - does not honor DATETIME_FORMAT

Reported by: Beda Kosata Owned by: nobody
Component: Internationalization Version: 1.11
Severity: Normal Keywords: l10n
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

according to the documentation, using {% localize off %}{{ variable }}{% endlocalize %} should be equivalent to {{ variable|unlocalize }}. However, for datetimes the former formats the variable according to DATETIME_FORMAT setting, while the latter does not and uses some default ISO based formatting.

To make a suggestion, I think that the source for the ulocalize filter should be:

@register.filter(is_safe=False)
def unlocalize(value):
    """
    Forces a value to be rendered as a non-localized value,
    regardless of the value of ``settings.USE_L10N``.
    """
    return force_text(formats.localize(value, use_l10n=False))

instead of

@register.filter(is_safe=False)
def unlocalize(value):
    """
    Forces a value to be rendered as a non-localized value,
    regardless of the value of ``settings.USE_L10N``.
    """
    return force_text(value)

Best regards

Beda

Attachments (1)

28544.test.diff (2.3 KB ) - added by Claude Paroz 7 years ago.
Failing test

Download all attachments as: .zip

Change History (5)

by Claude Paroz, 7 years ago

Attachment: 28544.test.diff added

Failing test

comment:1 by Claude Paroz, 7 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Claude Paroz, 7 years ago

Has patch: set

comment:3 by Tim Graham, 7 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Claude Paroz <claude@…>, 7 years ago

Resolution: fixed
Status: newclosed

In 1b7780ea:

Fixed #28544 -- Made unlocalize template filter behave like {% localize off %} tag

Thanks Beda Kosata for the report and Tim Graham for the review.

Note: See TracTickets for help on using tickets.
Back to Top