Django

Code

Ticket #2203 (reopened)

Opened 2 years ago

Last modified 1 month ago

TIME_FORMAT, DATE_FORMAT and DATETIME_FORMAT are ignored

Reported by: marcink@elksoft.pl Assigned to: nobody
Milestone: post-1.0 Component: Internationalization
Version: SVN Keywords: i18n-rf
Cc: Triage Stage: Design decision needed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Contrary to the docs at http://www.djangoproject.com/documentation/settings/, changing TIME_FORMAT, DATE_FORMAT and DATETIME_FORMAT does not influence admin pages in any way.

These were added in [1115] but apparently got lost during magic-removal.

Attachments

settings.py (2.7 kB) - added by bahamut@macstorm.org on 07/11/06 01:17:57.
Settings file for my application. Date and time formats are not respected in admin site.

Change History

06/20/06 14:38:54 changed by ramiro

Hi,

What SVN revision are you using?. What behavior are you observing?.

Does the translated catalog you are using (pl.po?) specify these technical IDs (TIME_FORMAT, DATE_FORMAT and DATETIME_FORMAT)?

This should be working, the code that appears in contrib/admin/views/main.py in the [1115] patchset now lives in contrib/admin/templatetags/admin_list.py and calls the utils/translation.py:get_date_formats() function. That function uses the fomat strings specified in your xx.po if any and fallback to the values specified in global-settings.py/your settings.py.

Seee also [3055]

07/07/06 17:28:03 changed by adrian

  • status changed from new to closed.
  • resolution set to worksforme.

Looks like it's a problem with your translation catalog.

07/11/06 00:03:58 changed by bahamut@macstorm.org

  • status changed from closed to reopened.
  • version set to SVN.
  • resolution deleted.

This is broken as of r3327 trunk, for the English locale. Indeed, it seems to export or define time and date formats, which completely overwrites any project settings. This means there's no way to switch to 24 hours time, etc.

07/11/06 00:10:38 changed by adrian

bahamut: Would you perhaps be importing django.utils.translation in your settings file? See #2309 for discussion.

07/11/06 01:16:03 changed by bahamut@macstorm.org

I am not. I'm attaching my settings file.

07/11/06 01:17:57 changed by bahamut@macstorm.org

  • attachment settings.py added.

Settings file for my application. Date and time formats are not respected in admin site.

07/11/06 01:27:14 changed by bahamut@macstorm.org

I'm not sure how it can work intuitively -- that is, the date and time format settings applying to the admin site and other translated areas properly.

For example, taking the code from the admin site.

source:trunk/django/contrib/admin/templatetags/admin_list.py line 138

elif isinstance(f, models.DateField) or isinstance(f, models.TimeField):
                if field_val:
                    (date_format, datetime_format, time_format) = get_date_formats()
                    if isinstance(f, models.DateTimeField):
                        result_repr = capfirst(dateformat.format(field_val, datetime_format))
                    elif isinstance(f, models.TimeField):
                        result_repr = capfirst(dateformat.time_format(field_val, time_format))
                    else:
                        result_repr = capfirst(dateformat.format(field_val, date_format))

If we look at get_date_formats:

source:trunk/django/utils/translation/trans_real.py line 355

def get_date_formats():
    """
    This function checks whether translation files provide a translation for some
    technical message ID to store date and time formats. If it doesn't contain
    one, the formats provided in the settings will be used.
    """
    from django.conf import settings
    date_format = _('DATE_FORMAT')
    datetime_format = _('DATETIME_FORMAT')
    time_format = _('TIME_FORMAT')
    if date_format == 'DATE_FORMAT':
        date_format = settings.DATE_FORMAT
    if datetime_format == 'DATETIME_FORMAT':
        datetime_format = settings.DATETIME_FORMAT
    if time_format == 'TIME_FORMAT':
        time_format = settings.TIME_FORMAT
    return date_format, datetime_format, time_format

It would seem we'll always get the format from the translation files, not from the settings.

07/11/06 01:30:38 changed by bahamut@macstorm.org

Might have wanted to preview that entry first :|

Correct source links are

07/11/06 01:35:19 changed by bahamut@macstorm.org

I should also mention that, as of r3327, setting USE_I18N to False in your settings file will happily blow up the admin site, with the following exception being generated:

Exception Type: AttributeError? Exception Value: 'module' object has no attribute 'get_language_bidi' Exception Location: /opt/local/lib/python2.4/site-packages/django/core/context_processors.py in i18n, line 41

This might be worth posting as a new ticket. However, this is a separate issue and I believe date and time formats should be configurable outside the scope or control of the localization files. There are arguably legitimate reasons for this (e.g. an application for the US military might require to use the 24 hours time format, while the locale would stil be en-us).

07/11/06 01:38:03 changed by anonymous

*sigh* I really need to start using the preview button...

Un-wikified exception details:

Exception Type:        AttributeError
Exception Value:       'module' object has no attribute 'get_language_bidi'
Exception Location:    /opt/local/lib/python2.4/site-packages/django/core/context_processors.py in i18n, line 41

07/11/06 09:08:42 changed by adrian

(In [3329]) Added get_language_bidi to django.utils.translation.trans_nuill. Refs #2203

02/21/07 14:54:05 changed by SmileyChris

  • stage changed from Unreviewed to Accepted.

Looks valid to me.

Bahamut mentioned "It would seem we'll always get the format from the translation files, not from the settings." so could someone write up a patch to fix this?

02/22/07 02:41:54 changed by mtredinnick

  • stage changed from Accepted to Design decision needed.

On one level, we *should* be getting the format from the translation files, in almost all cases. This is because the developer/designer of the original presentation is not going to be up to speed on all the subtleties and traditions of time presentation in all the locales, whereas the translator will know how times are normally presented in their particular language (and the translator and designer should be working together on the tricky cases).

So there is a design problem here: allowing control of time presentation information via the settings file does not interact well with localisation. I'm not sure what a solution is to this one yet, since I only just noticed this ticket. But it's not a clear bug, to my mind, at the moment. Needs some more thought.

The example of wanting to force time to always be in military time, for example, is a case where the timezone presentation in each case should be translated to use the 24-hour presentation. However, that is a separate issue in any case (since it enters the realm of project-wide translation files overriding core translations, which is something we cannot handle at the moment). So let's not have any more discussion of that in this ticket, please.

06/27/08 09:31:49 changed by garcia_marc

  • keywords set to i18n-rf.

07/09/08 05:19:05 changed by garcia_marc

  • component changed from Admin interface to Internationalization.
  • milestone set to post-1.0.

08/24/08 15:51:11 changed by lakin@structuredabstraction.com

In my mind this is a bug. My reasoning is as follows: In every language there are many different (but correct) ways in which to display a date. Although one way may be considered a default, surely there are many ways that are valid. In order to change the default date display on one app, I have to provide a custom translation?


Add/Change #2203 (TIME_FORMAT, DATE_FORMAT and DATETIME_FORMAT are ignored)




Change Properties
Action