"Current" timezone in admin

2,049 views
Skip to first unread message

Danny W. Adair

unread,
Jan 15, 2012, 4:10:23 AM1/15/12
to Django developers
Hi,
With 1.4 timezone support I was wondering if/how django admin supports
the current user's timezone.
There's no corresponding HTTP header like "Accept-Language" so I guess
the timezone must be set in the session (looked up from a profile or
whatever).

Is there a hook that allows the "current" timezone to be set for
admin, so that it uses it for datetime display/submission? Maybe a
middleware that expects a session variable configured/named in
settings?

With full timezone support I also think it may be worth adding
timezone to the standard User model, with a default None that falls
back to settings.TIME_ZONE (and probably another hook to override the
default choices).

Cheers,
Danny

Aymeric Augustin

unread,
Jan 27, 2012, 3:49:48 PM1/27/12
to django-d...@googlegroups.com
Hello Danny,

On 15 janv. 2012, at 10:10, Danny W. Adair wrote:
> Is there a hook that allows the "current" timezone to be set for
> admin, so that it uses it for datetime display/submission? Maybe a
> middleware that expects a session variable configured/named in
> settings?

Currently, there's no built-in UI for timezone selection. However, I've described some ideas, along with sample code, in the documentation:
https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#selecting-the-current-time-zone

There's also a sample app here: https://bitbucket.org/aaugustin/django-tz-demo

> With full timezone support I also think it may be worth adding
> timezone to the standard User model, with a default None that falls
> back to settings.TIME_ZONE (and probably another hook to override the
> default choices).


As long as Django doesn't have a schema alteration API, it's difficult to change the User model.

There's also the question of how to store timezones in the database. If we implemented this feature, we'd have to bless a timezone implementation. pytz is pretty much the standard, and it's highly recommended, but it's possible to use another implementation of tzinfo classes if you desire.


For these reasons, I think it's better to leave the field open and see what emerges. I don't want to bless an implementation of "per-user time zone selection" now, because I don't believe we can come up with a sufficiently generic one at this point. Maybe when we have more hindsight...

Best regards,

--
Aymeric Augustin.


Danny Adair

unread,
Jan 28, 2012, 11:17:11 PM1/28/12
to django-d...@googlegroups.com
Thanks Aymeric,

On Sat, Jan 28, 2012 at 09:49, Aymeric Augustin
<aymeric....@polytechnique.org> wrote:
>[...]


> Currently, there's no built-in UI for timezone selection. However, I've described some ideas, along with sample code, in the documentation:
> https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#selecting-the-current-time-zone
>
> There's also a sample app here: https://bitbucket.org/aaugustin/django-tz-demo

Yeah I saw that. So that's basically the battery compartment, and
admin currently doesn't bring timezone batteries.
Would be nice if there were some optional batteries, maybe packed
separately (django.contrib) but then comes the question of storage...

>[...]


> As long as Django doesn't have a schema alteration API, it's difficult to change the User model.
>
> There's also the question of how to store timezones in the database. If we implemented this feature, we'd have to bless a timezone implementation. pytz is pretty much the standard, and it's highly recommended, but it's possible to use another implementation of tzinfo classes if you desire.
>
> For these reasons, I think it's better to leave the field open and see what emerges. I don't want to bless an implementation of "per-user time zone selection" now, because I don't believe we can come up with a sufficiently generic one at this point. Maybe when we have more hindsight...

That makes sense, thank you.
I was personally dreaming of a pytz-based optional app where each
relevant component could be replaced. Maybe a thirdparty app will
provide this and mature until it gets added.

Cheers,
Danny

Reply all
Reply to author
Forward
0 new messages