Commit 398a28b447cfd4411a3480644f118fea04d4a624
1 parent
27a66add
Exists in
master
and in
39 other branches
Adding app to detect user's timezone
Showing
5 changed files
with
33 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | + | |
| 2 | +import pytz | |
| 3 | + | |
| 4 | +from django.utils import timezone | |
| 5 | + | |
| 6 | + | |
| 7 | +class TimezoneMiddleware(object): | |
| 8 | + def process_request(self, request): | |
| 9 | + offset = request.COOKIES.get('utc_offset', 0) | |
| 10 | + | |
| 11 | + try: | |
| 12 | + offset = int(offset) * -1 | |
| 13 | + except ValueError: | |
| 14 | + offset = 0 | |
| 15 | + | |
| 16 | + if offset: | |
| 17 | + tz = pytz.FixedOffset(offset) | |
| 18 | + timezone.activate(tz) | |
| 19 | + else: | |
| 20 | + timezone.deactivate() | ... | ... |