Opened 2 years ago

Last modified 13 months ago

#35333 assigned Bug

Template tag `unlocalize` does not work with `date` and `time` filters.

Reported by: Natalia Bidart Owned by: Ahmed Nassar
Component: Template system Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Following #35306, it was noticed that using the date or time template filters would not honor the unlocalize template tag. See regression tests:

  • tests/i18n/tests.py

    diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
    index 355505a10d..90cf4630bf 100644
    a b class FormattingTests(SimpleTestCase):  
    13511351                self.assertEqual(template2.render(context), output2)
    13521352                self.assertEqual(template3.render(context), output3)
    13531353
     1354
     1355
     1356
     1357
     1358
     1359
     1360
     1361
     1362
     1363
     1364
     1365
     1366
     1367
     1368
     1369
     1370
     1371
     1372
     1373
     1374
     1375
     1376
     1377
     1378
     1379
     1380
     1381
     1382
     1383
     1384
     1385
     1386
     1387
     1388
     1389
     1390
     1391
     1392
     1393
     1394
     1395
     1396
     1397
     1398
     1399
    13541400    def test_localized_off_numbers(self):
    13551401        """A string representation is returned for unlocalized numbers."""
    13561402        template = Template(

Change History (6)

comment:1 by Claude Paroz, 2 years ago

I'm not yet sure if this can be resolved in the code, or if we should rather complement the template filter docs, telling that if you apply an l10n-sensible filter inside an unlocalized section, you should specify an explicit format argument. The problem being that the way filters are currently implemented, it's not possible to transmit any context. That explains for example that floatformat gained an u parameter to force unlocalization (see #30086).

So in your example in the tests above, you should use |date:settings.DATE_FORMAT and not just DATE_FORMAT. Thoughts?

comment:2 by Claude Paroz, 2 years ago

Owner: Claude Paroz removed
Status: assignednew

comment:3 by Ahmed Nassar, 15 months ago

Owner: set to Ahmed Nassar
Status: newassigned

comment:4 by Ahmed Nassar, 15 months ago

I'd like to work on this issue if it's still available. Could you confirm if it's unassigned? If so, I will start by reviewing the expected behavior and checking the existing implementation of date and time filters.

Looking forward to contributing!

comment:5 by Ahmed Nassar, 14 months ago

Has patch: set

comment:6 by Sarah Boyce, 13 months ago

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top