Code

Opened 3 years ago

Closed 3 years ago

#15263 closed New feature (fixed)

Make "now" templatetag accept locale formats.

Reported by: danielr 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 danielr 3 years ago.
15263_now_tag.diff (2.7 KB) - added by dmclain 3 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 3 years ago by danielr

comment:1 Changed 3 years ago by ersame

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

The patch looks OK.

comment:2 Changed 3 years ago by creecode@…

  • Cc creecode@… added
  • Has patch unset

comment:3 Changed 3 years ago by creecode@…

  • Has patch set

comment:4 Changed 3 years ago by ramiro

  • Triage Stage changed from Accepted to Design 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 3 years ago by ramiro (previous) (diff)

comment:5 Changed 3 years ago by ramiro

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 3 years ago by ramiro

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 3 years ago by ramiro

  • Triage Stage changed from Design decision needed to Accepted

comment:8 Changed 3 years ago by lrekucki

  • Severity set to Normal
  • Summary changed from "now" templatetag doesn't accept locale formats, as docs claim to Make "now" templatetag accept locale formats.
  • Type set to New feature

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

comment:9 Changed 3 years ago by patchhammer

  • Easy pickings unset
  • Patch needs improvement set

now_tag.diff fails to apply cleanly on to trunk

Changed 3 years ago by dmclain

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

comment:10 Changed 3 years ago by dmclain

  • Patch needs improvement unset

comment:11 Changed 3 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

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

comment:12 Changed 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [16172]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.