Code

Opened 6 years ago

Last modified 19 months ago

#9762 new Bug

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

Reported by: amele Owned by: kgrandis
Component: Template system Version: master
Severity: Normal Keywords: date template filter
Cc: mmitar@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
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 5 years ago.
corrected rfc2822 implementation and added tests
rfc2822.2.diff (3.0 KB) - added by kgrandis 5 years ago.
updated tests to unit tests and fixed an issue with tzinfo
rfc2822.2.2.diff (2.9 KB) - added by kgrandis 5 years ago.
updated tests to unit tests and fixed an issue with tzinfo
rfc2822.3.diff (3.2 KB) - added by kgrandis 5 years ago.
restored system settings.LANGUAGE_CODE after monkeying around

Download all attachments as: .zip

Change History (19)

comment:1 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:2 Changed 5 years ago by jacob

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

comment:3 Changed 5 years ago by draxus

Same problem here. Any solution?

comment:4 Changed 5 years ago by kgrandis

  • Owner changed from nobody to kgrandis
  • Status changed from new to assigned

Changed 5 years ago by kgrandis

corrected rfc2822 implementation and added tests

comment:5 Changed 5 years ago by kgrandis

  • 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 Changed 5 years ago by kgrandis

  • Owner changed from kgrandis to kmtracey
  • Status changed from assigned to new

comment:7 Changed 5 years ago by kmtracey

  • Owner changed from kmtracey to kgrandis

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

Changed 5 years ago by kgrandis

updated tests to unit tests and fixed an issue with tzinfo

Changed 5 years ago by kgrandis

updated tests to unit tests and fixed an issue with tzinfo

comment:8 Changed 5 years ago by kgrandis

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

Changed 5 years ago by kgrandis

restored system settings.LANGUAGE_CODE after monkeying around

comment:9 Changed 3 years ago by ramiro

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

  • Easy pickings unset
  • Patch needs improvement set
  • Severity set to Normal
  • Type set to Uncategorized

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

comment:11 Changed 3 years ago by lukeplant

  • Type changed from Uncategorized to Bug

comment:12 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:13 Changed 2 years ago by anonymous

this is still a problem

comment:14 Changed 23 months ago by mitar

  • Cc mmitar@… added

comment:15 Changed 19 months ago by anonymous

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from kgrandis to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.