Skip to content
Browse files

Docs updates.

  • Loading branch information...
1 parent 9af0a03 commit 9022891e739633124c352a956be9b239d784dc51 @paluh committed Nov 6, 2010
Showing with 11 additions and 12 deletions.
  1. +9 −10 README.textile
  2. +2 −2 django_tz/middleware.py
View
19 README.textile
@@ -10,8 +10,9 @@ django-tz manages timezones transitions in a manner similar to how django implem
* It defines TimeZoneField which is taken from django-timezones (I've added default value guessing based on language code).
* It provides global (per thread) timezone cache which can be easily updated by custom middleware.
-* It defines LocalizedDateTimeField (+ some additional form fields) - which makes automatically transitions: settings.TIME_ZONE <-> current timezone.
+* It defines LocalizedDateTimeField (+ some additional form fields) - which makes automatically transitions: settings.TIME_ZONE <--> current timezone.
* It implements template filter to localize datetime values according to cache.
+* It defines set_timezone view which stores given timezone in session or cookie.
h2. HOW IT WORKS
@@ -46,20 +47,18 @@ Now we want to switch timezone according to user settings for every request. Thi
<pre>
<code>
-class TimezoneMiddleware(object):
- def _get_timezone_from_request(self, request):
+from django_tz.middleware import GlobalTimezoneMiddleware, get_
+
+class ProfileTimezoneMiddleware(GlobalTimezoneMiddleware):
+ def get_tz(sefl, request):
if hasattr(request, 'user') and request.user.is_authenticated():
profile = request.user.get_profile()
return profile.timezone
- return pytz.timezone(settings.TIME_ZONE)
- def process_request(self, request):
- tz = self._get_timezone_from_request(request)
- global_tz.activate(tz)
+ #try current session timezone setting at first
+ tz = get_tz_from_request(request)
+ return tz
- def process_response(self, request, response):
- global_tz.deactivate()
- return response
</code>
</pre>
View
4 django_tz/middleware.py
@@ -23,7 +23,7 @@ def get_tz_from_request(request):
return None
-class TimezoneMiddleware(object):
+class GlobalTimezoneMiddleware(object):
"""
This middleware guesses timezone from language and sets it in current
thread global cache.
@@ -40,7 +40,7 @@ def process_response(self, request, response):
global_tz.deactivate()
return response
-class TimezoneFromLangMiddleware(TimezoneMiddleware):
+class TimezoneFromLangMiddleware(GlobalTimezoneMiddleware):
"""
Not very smart middelware which guesses timezone from request lang setting.
"""

0 comments on commit 9022891

Please sign in to comment.
Something went wrong with that request. Please try again.