-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change view to handle timezones from script instead of offsets.
- Loading branch information
Bryan
committed
Feb 11, 2014
1 parent
64ebe5e
commit 2795751
Showing
2 changed files
with
16 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from django.conf.urls import patterns, url | ||
|
||
from views import SetOffsetView | ||
from views import SetTimezoneView | ||
|
||
urlpatterns = patterns('', | ||
url(r'^set/$', SetOffsetView.as_view(), name="timezone_detect__set"), | ||
) | ||
url(r'^set/$', SetTimezoneView.as_view(), name="timezone_detect__set"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
from django.http import HttpResponse | ||
from django.views.generic import View | ||
from pytz import timezone as tz | ||
from django.conf import settings | ||
|
||
|
||
class SetOffsetView(View): | ||
class SetTimezoneView(View): | ||
http_method_names = ['post'] | ||
|
||
@staticmethod | ||
def post(request, *args, **kwargs): | ||
offset = request.POST.get('offset', None) | ||
if not offset: | ||
return HttpResponse("No 'offset' parameter provided", status=400) | ||
timezone = request.POST.get('timezone', None) | ||
if not timezone: | ||
return HttpResponse("No 'timezone' parameter provided", status=400) | ||
|
||
try: | ||
offset = int(offset) | ||
except ValueError: | ||
return HttpResponse("Invalid 'offset' value provided", status=400) | ||
if "None" in str(timezone).lower(): | ||
timezone = tz(settings.TIME_ZONE) | ||
else: | ||
timezone = tz(str(timezone)) | ||
except: | ||
return HttpResponse("Invalid 'timezone' value provided", status=400) | ||
|
||
tz = offset_to_timezone(int(offset)) | ||
print tz | ||
request.session['detected_tz'] = tz | ||
request.session['detected_timezone'] = tz | ||
|
||
return HttpResponse("OK") |