Commit
398a28b447cfd4411a3480644f118fea04d4a624
Exists in
master
and in
39 other branches
1.12.x, add_requests_as_dep, celery_service, change-passwd-signal, check-port, colab-signals, colab-vcard, colab_search, colab_tag, colab_tag_merge, community_association, detach_super_archives, fix-dashboard, fix-message-preview, fix_app_label, fix_cache_count_spb, fix_header, fixed_gitlab_import, go_to_profile_panel, header_footer, layout-fix, mobile_user_scalable, move_out_plugins, paginate-threads, profile_integration, refactor-data-import, remove-gitlab-plugin, removing_namespace, search_block, search_filters, spb-release/3.0, split_screen, stable, startplugin, timestamp_plugins, translation_review, user_regex, validate-passwd, workin_whoosh_temp
Adding app to detect user's timezone
|
| @@ -0,0 +1,20 @@ |
| @@ -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() |
|
| @@ -0,0 +1,4 @@ |
| @@ -0,0 +1,4 @@ |
|
| |
1
| +<script type="text/javascript"> |
|
| |
2
| + var date = new Date(); |
|
| |
3
| + $.cookie('utc_offset', getTimezoneOffset()); |
|
| |
4
| +</script> |
|
| @@ -0,0 +1,9 @@ |
| @@ -0,0 +1,9 @@ |
|
| |
1
| + |
|
| |
2
| +from django import template |
|
| |
3
| + |
|
| |
4
| +register = template.Library() |
|
| |
5
| + |
|
| |
6
| + |
|
| |
7
| +@register.inclusion_tag('tz/set_utc_offset.html') |
|
| |
8
| +def utc_offset_cookie(): |
|
| |
9
| + return |