Opened 5 months ago
Last modified 3 months ago
#36307 assigned New feature
Support passing depth to naturaltime, timesince and timeuntil filters
Reported by: | Giannis Terzopoulos | Owned by: | Giannis Terzopoulos |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I propose extending these filters to accept an optional depth
argument that gets passed downstream:
timesince
would pass depth todjango.utils.timesince.timesince()
timeuntil
would pass depth todjango.utils.timesince.timeuntil()
naturaltime
would pass depth toNaturalTimeFormatter.string_for()
, which would then pass it to the underlyingtimesince
/timeuntil
calls
Example:
For a datetime object dt
representing 38 days in the past:
{{ dt|naturaltime:"1" }}
would return "1 month ago", instead of the current depth=2 output: "1 month, 1 week ago"
Change History (2)
comment:1 by , 5 months ago
Component: | Uncategorized → Template system |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | → dev |
comment:2 by , 3 months ago
This is less simple than it appears at first.
The timesince and timeuntil filters can already take an optional argument, a variable containing the date to use as the comparison point. Since filters can only take one optional argument there is no room for depth. I've thought about overloading it, but I've concluded it's a bad thing to do.
If people need this functionality in their projects, I think it is okay that they can create their own simple_tag for the job.
The naturaltime filter does not have any arguments, you could add it there, but the justification Sarah used about timesince and timeuntil functions being updated is a little more of a stretch if it is only this filter from humanize that is being updated.
I'd suggest this should be changed to wontfix.
Since the depth parameter was added to timesince and timeuntil within #31623, I believe this is a logical follow up