Opened 6 years ago

Closed 6 years ago

#15263 closed New feature (fixed)

Make "now" templatetag accept locale formats.

Reported by: Daniel Roseman Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords:
Cc: creecode@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX:

Description

The documentation on the now tag claims that it acts like the date filter in accepting "DATE_FORMAT" as a shortcut to the locale's current date format. However, this is not the case:

>>> t=Template("""{% now "DATE_FORMAT" %}""")
>>> t.render(Context())
u'WedPMGMTE_February+0000RFebPMGMT'

Clearly the string is being interpreted as a literal format, instead of being translated to the locale's date format.

Attached patch fixes this by using the same logic as the date filter, including a regression test, and slightly tweaks the awkward wording in the docs.

Attachments (2)

now_tag.diff (2.9 KB) - added by Daniel Roseman 6 years ago.
15263_now_tag.diff (2.7 KB) - added by dmclain 6 years ago.
Sackcloth and ashes tour: Updated docs to fix patch errors and reflect new feature.

Download all attachments as: .zip

Change History (14)

Changed 6 years ago by Daniel Roseman

Attachment: now_tag.diff added

comment:1 Changed 6 years ago by ersame

Triage Stage: UnreviewedAccepted

The patch looks OK.

comment:2 Changed 6 years ago by creecode@…

Cc: creecode@… added
Has patch: unset

comment:3 Changed 6 years ago by creecode@…

Has patch: set

comment:4 Changed 6 years ago by Ramiro Morales

Triage Stage: AcceptedDesign decision needed

We introduced that extra paragraph about that non-existent interaction of the now tag with locale-dependent output formats in r14013 (fixes #13188) when moving the table of format specifiers from there to the date filter section.

We need to decide if we want to change the behavior of the tag to match the documentation (in which case the proposed patch can be reviewed, I haven't yet) or simply decide such change isn't worth or sensible and then treat this ticket as documentation bug.

Last edited 6 years ago by Ramiro Morales (previous) (diff)

comment:5 Changed 6 years ago by Ramiro Morales

In [15678]:

Reverted 'now' template tag documentation changes so it describes the real code implementation regarding (lack of) interaction with L10N machinery. Refs #15263. Thanks danielr for the report.

comment:6 Changed 6 years ago by Ramiro Morales

In [15679]:

[1.2.X] Reverted 'now' template tag documentation changes so it describes the real code implementation regarding (lack of) interaction with L10N machinery. Refs #15263. Thanks danielr for the report.

Backport of [15678] from trunk.

comment:7 Changed 6 years ago by Ramiro Morales

Triage Stage: Design decision neededAccepted

comment:8 Changed 6 years ago by Łukasz Rekucki

Severity: Normal
Summary: "now" templatetag doesn't accept locale formats, as docs claimMake "now" templatetag accept locale formats.
Type: New feature

With the change in the docs, it's now a feature request.

comment:9 Changed 6 years ago by patchhammer

Easy pickings: unset
Patch needs improvement: set

now_tag.diff fails to apply cleanly on to trunk

Changed 6 years ago by dmclain

Attachment: 15263_now_tag.diff added

Sackcloth and ashes tour: Updated docs to fix patch errors and reflect new feature.

comment:10 Changed 6 years ago by dmclain

Patch needs improvement: unset

comment:11 Changed 6 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

Other than adding a '.. versionadded:: 1.4' note for the docs this looks good to me.

comment:12 Changed 6 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [16172]:

Fixed #15263 -- Added support for format localization to the now template tag. Thanks to danielr and dmclain.

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