forked from avh4/khan-academy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
knowledgemap.py
55 lines (39 loc) · 1.29 KB
/
knowledgemap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from google.appengine.api import users
import util
import request_handler
from models import UserData
class SaveExpandedAllExercises(request_handler.RequestHandler):
def post(self):
user_data = UserData.current()
if user_data:
expanded = self.request_bool("expanded")
user_data.expanded_all_exercises = expanded
user_data.put()
class SaveMapCoords(request_handler.RequestHandler):
def get(self):
return
def post(self):
user_data = UserData.current()
if user_data:
try:
lat = self.request_float("lat")
lng = self.request_float("lng")
zoom = self.request_int("zoom")
except ValueError:
# If any of the above values aren't present in request, don't try to save.
return
user_data.map_coords = serializeMapCoords(lat, lng, zoom)
user_data.put()
def serializeMapCoords(lat, lng, zoom):
return "%s:%s:%s" % (lat, lng, zoom)
def deserializeMapCoords(s):
if (not s):
return (0, 0, 0)
try:
rg = s.split(":")
lat = float(rg[0])
lng = float(rg[1])
zoom = int(rg[2])
except ValueError:
return (0, 0, 0)
return (lat, lng, zoom)