-
-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathtimezone.py
More file actions
30 lines (24 loc) · 947 Bytes
/
timezone.py
File metadata and controls
30 lines (24 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# VulnerableCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import zoneinfo
from django.utils import timezone
class UserTimezoneMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
try:
# Activate local timezone for user using cookies
tzname = request.COOKIES.get("user_timezone")
if tzname:
timezone.activate(zoneinfo.ZoneInfo(tzname))
else:
timezone.deactivate()
except Exception as e:
timezone.deactivate()
return self.get_response(request)