Opened 16 years ago

Closed 5 years ago

#9762 closed Bug (fixed)

template filter |date:"r" not valid RFC 2822 formatted when LANGUAGE_CODE different than english

Reported by: Antonio Melé Owned by: kgrandis
Component: Utilities Version: dev
Severity: Normal Keywords: date template filter
Cc: mmitar@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Documentation says template filter date with argument 'r' returns a valid RFC 2822 formatted date. But setting a LANGUAGE_CODE different than english makes the date returned not valid because the day abbreviation is translated into the LANGUAGE_CODE language. Perhaps there should be two arguments for this: one for valid RFC 2822 dates and another one for the actual 'r' argument (RFC 2822 translated).

Attachments (4)

rfc2822.diff (1.6 KB ) - added by kgrandis 16 years ago.
corrected rfc2822 implementation and added tests
rfc2822.2.diff (3.0 KB ) - added by kgrandis 15 years ago.
updated tests to unit tests and fixed an issue with tzinfo
rfc2822.2.2.diff (2.9 KB ) - added by kgrandis 15 years ago.
updated tests to unit tests and fixed an issue with tzinfo
rfc2822.3.diff (3.2 KB ) - added by kgrandis 15 years ago.
restored system settings.LANGUAGE_CODE after monkeying around

Download all attachments as: .zip

Change History (21)

comment:1 by (none), 16 years ago

milestone: post-1.0

Milestone post-1.0 deleted

comment:2 by Jacob, 16 years ago

Triage Stage: UnreviewedAccepted

comment:3 by draxus, 16 years ago

Same problem here. Any solution?

comment:4 by kgrandis, 16 years ago

Owner: changed from nobody to kgrandis
Status: newassigned

by kgrandis, 16 years ago

Attachment: rfc2822.diff added

corrected rfc2822 implementation and added tests

comment:5 by kgrandis, 16 years ago

Has patch: set

The attached patch makes the 'r' flag returns an RFC 2822 formatted date string even when LANGUAGE_CODE is set to something other than English. Added regression tests to reflect this issue.

There will be a simpler solution once Python implements a datetime-RFC 2822 export feature ( http://bugs.python.org/issue665194 ).

comment:6 by kgrandis, 15 years ago

Owner: changed from kgrandis to Karen Tracey
Status: assignednew

comment:7 by Karen Tracey, 15 years ago

Owner: changed from Karen Tracey to kgrandis

Tests in patch need updating -- that file has been converted to unit tests.

by kgrandis, 15 years ago

Attachment: rfc2822.2.diff added

updated tests to unit tests and fixed an issue with tzinfo

by kgrandis, 15 years ago

Attachment: rfc2822.2.2.diff added

updated tests to unit tests and fixed an issue with tzinfo

comment:8 by kgrandis, 15 years ago

The patch now includes new tests.

An existing unit test was modified to adhere to a common RFC 2822 standard. This patch generates the date string using Python's email.utils.formatdate (available in py2.4).

The above Python issue is still open, but its solution will allow for a much more straightforward solution. It looks to be slated for Python 2.7: http://bugs.python.org/issue665194

by kgrandis, 15 years ago

Attachment: rfc2822.3.diff added

restored system settings.LANGUAGE_CODE after monkeying around

comment:9 by Ramiro Morales, 14 years ago

Should this handle timezone infromation?, if the answer is no then this patch is on the right track, if the answer is yes then maybe we should handle things manually (and move the code to a helper function) instead of using email.utils (e.g. like we are douiing in the feed geenrator: http://code.djangoproject.com/browser/django/trunk/django/utils/feedgenerator.py?rev=15505#L39)

comment:10 by patchhammer, 14 years ago

Easy pickings: unset
Patch needs improvement: set
Severity: Normal
Type: Uncategorized

rfc2822.3.diff fails to apply cleanly on to trunk

comment:11 by Luke Plant, 14 years ago

Type: UncategorizedBug

comment:12 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:13 by anonymous, 12 years ago

this is still a problem

comment:14 by Mitar, 12 years ago

Cc: mmitar@… added

comment:15 by anonymous, 12 years ago

guys, this is really annoying...
a workaround is to import the rfc2822_date from django.utils.feedgenerator and just register it as an own filter.

comment:16 by Baptiste Mispelon, 5 years ago

Component: Template systemUtilities
Patch needs improvement: unset

comment:17 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: newclosed

In 8929afb:

Fixed #9762 -- Made DateFormat.r() locale-independent.

Thanks to Antonio Melé for the original report all those years ago
and to all the contributors who helped along the way.

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