django-tz-detect icon indicating copy to clipboard operation
django-tz-detect copied to clipboard

Timezone awareness on first view

Open LlamaSurprise opened this issue 2 years ago • 1 comments

According to the readme:

Django's timezone awareness will not be available on the first page view

Is there a specific reason this library does not attempt this?

Where we're using this library, we're getting a specific issue where when we show the site in an iFrame, it will never show the correct time zone, because of aggressive browser policies against storing cookies.

LlamaSurprise avatar Aug 17 '22 08:08 LlamaSurprise

A workaround would be to add a new filter for templates that allows javascript to replace every time-zone aware field with the local time-zone equivalent, for the first view.

Or else the middleware could return a javascript redirection page to self that sets the timezone:

  1. The user requests the first page, "index"
  2. The middleware looks in the session if the timezone is present
  3. If it is, the first page is timezone aware
  4. If it's not, it replaces the page with a redirect that initially sets the timezone and then returns the right page but timezone aware

ldeluigi avatar Feb 11 '23 21:02 ldeluigi