Tutti is the simplest social network on internet. Here you can make friends, create communities, sell things, make surveys, comment and share stuff.
from django.utils import timezone def timezone_processor(request): # look for a cookie that we expect to have the timezone tz = request.COOKIES.get('local_timezone', None) if tz: tz_int = int(tz) # cast to int # here we decide what will prefix timezone number # the output of tz_str will be something like: # Etc/GMT+1, GMT+0, Etc/GMT-2 if tz_int >= 0: tz_str = 'Etc/GMT+'+tz else: tz_str = 'Etc/GMT'+tz # this forces timezone timezone.activate(tz_str) # Now we tell the template that we have a timezone return {'local_timezone': tz}
TEMPLATES = [ { ......... 'OPTIONS': { 'context_processors': [ ......... 'myapp.context_processors.timezone_processor', ], },
<!-- if django already knows timezone we will not run it again --> {% if not local_timezone %} <!-- getTimezoneOffset does the trick! --> <!-- it return minutes so we divide to get hours --> timezone = new Date().getTimezoneOffset() / 60; document.cookie = 'local_timezone=" + timezone; <!-- set a cookie with this value and we are done --> {% endif %}