Opened 8 years ago

Closed 8 years ago

#27296 closed New feature (needsinfo)

Can't use custom formats with new language-independent LogEntry's messages in Django 1.10

Reported by: Ivan Tsouvarev Owned by: nobody
Component: contrib.admin Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Say, you have some model, which __str__ uses django.utils.formats.date_format with custom format string.

settings.FORMAT_MODULE_PATH contains module, in which this string is defined.

So, when you create object of this model via admin interface, the following things happen:

  1. Django calls construct_change_message to create LogEntry, which is decorated with @translation_override(None), which will deactivate current language
  2. To write object representation with custom format in change message, django.utils.formats.get_format will be called
  3. get_format will try to find custom format, but it can't be done when active language is None, so original string will be returned as-is
  4. django.utils.dateformat.format will interpret custom format string literally, which may not fail with exception, but will be totally wrong anyway

Change History (4)

comment:1 by Tim Graham, 8 years ago

Component: Uncategorizedcontrib.admin

Do you have any suggestions about how to fix that?

comment:2 by Ivan Tsouvarev, 8 years ago

Hard to say. May be there is a way to avoid translation without deactivating current language?

comment:3 by Claude Paroz, 8 years ago

I don't see a proper solution yet, apart from providing some default yourself by comparing the get_format return value.

comment:4 by Tim Graham, 8 years ago

Resolution: needsinfo
Status: newclosed
Type: UncategorizedNew feature

Feel free to reopen if someone thinks of a proposal of how Django could facilitate this use case.

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