Opened 2 weeks ago

Last modified 6 days ago

#36145 assigned Bug

FIRST_DAY_OF_WEEK setting not changing the Admin calendar widget

Reported by: Phil Gyford Owned by: Ryan Heo
Component: contrib.admin Version: 5.1
Severity: Normal Keywords:
Cc: Claude Paroz, Carlton Gibson, Ryan Heo Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The docs for the FIRST_DAY_OF_WEEK setting (https://docs.djangoproject.com/en/5.1/ref/settings/#first-day-of-week ) say:

A number representing the first day of the week. This is especially useful when displaying a calendar. This value is only used when not using format internationalization, or when a format cannot be found for the current locale.

But if I set mine to FIRST_DAY_OF_WEEK = 1 (Monday) then the calendar widgets in Admin still start on the default, Sunday.

I've tried with USE_I18N set to both True and False, with no change.

I posted this query in the Django Forum but we were stumped as to whether the documentation or the code was wrong in some way https://forum.djangoproject.com/t/django-admin-date-pickers-ignoring-first-day-of-week/38170/2

Change History (4)

comment:1 by Sarah Boyce, 2 weeks ago

Cc: Claude Paroz Carlton Gibson added
Triage Stage: UnreviewedAccepted

Thank you for the ticket!

It appears that it used to be possible to update FIRST_DAY_OF_WEEK to update the admin date picker (used in django/contrib/admin/static/admin/js/calendar.js), and now this is much harder.

I don't think this is by design, and I think it's fair to say this is an unintended consequence/bug from #32873 (note that we tried to improve the docs in #35306).

It's possible a wider discussion might be needed in general for these settings (see also #35990).

comment:2 by Carlton Gibson, 2 weeks ago

It appears that it used to be possible to update FIRST_DAY_OF_WEEK to update the admin date picker (used in django/contrib/admin/static/admin/js/calendar.js), and now this is much harder.

I'd need to dig in to see exactly why this is failing but it looks like this should still work... calendar.js both fetches and uses FIRST_DAY_OF_WEEK, and there are some tests (at least) in test_i18n.py that suggest it's still getting to the page. (Current status: 🤔)

comment:3 by Ryan Heo, 6 days ago

        """
        The active locale's formats take precedence over the default settings
        even if they would be interpreted as False in a conditional test
        (e.g. 0 or empty string) (#16938).
        """

I found the test code for the FIRST_DAY_OF_WEEK attribute in tests>i18n>tests.py line 697.
It says that locale's formats take precedence over the default settings.
When I checked with several locale's formats files, I found that some of them have the FIRST_DAY_OF_WEEK attribute while others don't have it.
Since the locale's formats take precedence, you can't change the FIRST_DAY_OF_WEEK attribute if the locale's file has it.
If it doesn't have the attribute such as LANGUAGE_CODE='ko', you can simply change it in the settings.py.

Now I have found a bug. On the documentation, it says the following.

FIRST_DAY_OF_WEEK
A number representing the first day of the week. This is especially useful when displaying a calendar. This value is only used when not using format internationalization, or when a format cannot be found for the current locale.

When I used USE_I18N=False, I couldn't use the FIRST_DAY_OF_WEEK as I wanted.
I think this is because USE_L10N was removed from v5.0 but is still used in the 'get_format' function in django>utils>formats.py rather than use_i18n.
I will keep working on this issue to remove the use_l10n part from the get_format and follow the current documentation.

Last edited 6 days ago by Ryan Heo (previous) (diff)

comment:4 by Ryan Heo, 6 days ago

Cc: Ryan Heo added
Owner: set to Ryan Heo
Status: newassigned
Note: See TracTickets for help on using tickets.
Back to Top