Skip to content

Commit

Permalink
add: automatic timezone detection
Browse files Browse the repository at this point in the history
  • Loading branch information
saemideluxe committed Dec 20, 2023
1 parent 8e4823c commit ae8a290
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions basxbread/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __call__(self, request):

# load the preferred language for a user and change translation system
# and language cookie if required
tz = None
if request.user and hasattr(request.user, "preferences"):
lang = request.user.preferences.get("general__preferred_language")
if lang and lang != get_language():
Expand All @@ -45,6 +46,12 @@ def __call__(self, request):
timezone.activate(zoneinfo.ZoneInfo(tz))
else:
timezone.deactivate()
if not tz and "basxbread-timezone" in request.session["basxbread-cookies"]:
timezone.activate(
zoneinfo.ZoneInfo(
request.session["basxbread-cookies"]["basxbread-timezone"]
)
)

return self.get_response(request)

Expand Down
2 changes: 1 addition & 1 deletion basxbread/static/js/basxbread.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions basxbread/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ function basxbread_load_elements() {
$$(
"[onload]:not(body):not(frame):not(iframe):not(img):not(link):not(script):not(style)"
)._.fire("load");

setBasxBreadCookie("timezone", Intl.DateTimeFormat().resolvedOptions().timeZone);
}

// make sure to display content from faild ajax requests
Expand Down Expand Up @@ -195,3 +197,4 @@ function searchMatchRank(searchTerms, value) {
}
return score;
}

0 comments on commit ae8a290

Please sign in to comment.