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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
"""
Location class for MURSAT1 Mission Dashboard
"""
import hashlib
from cgi import parse_qs, escape
from MmdDb import Db
def checkLonLat (lonlat):
if type (lonlat) != type (0.0):
lonlat = float (lonlat)
if lonlat < 0.0 or lonlat > 360.0:
return False
return lonlat
class Location:
def __init__ (self, location_id = False):
self.db = Db ()
if location_id:
self.location_id = location_id
self.load ()
else:
self.name = 'Graz/Austria'
self.longitude = 15.44226
self.latitude = 47.06576
def create (self, name, longitude, latitude, is_default, user_id):
self.name = name
self.is_default = is_default
self.longitude = checkLonLat (longitude)
self.latitude = checkLonLat (latitude)
if not self.longitude:
self.longitude = 15.44226
if not self.latitude:
self.latitude = 47.06576
self.location_id = hashlib.sha1 ('{0}{1}{2}'.format (user_id, self.longitude, self.latitude)).hexdigest ()
return self.db.locationCreate (self.location_id, self.name, self.longitude, self.latitude, user_id, self.is_default)
def findUserId (self, user_id):
l = self.db.locationFindUserId (user_id)
if not l:
return False
self.name = l['name']
self.longitude = float (l['longitude'])
self.latitude = float (l['latitude'])
self.is_default = l['is_default']
self.location_id = l['id']
def load (self, location_id = False):
if location_id:
self.location_id = location_id
l = self.db.locationFindId (self.location_id)
if not l:
return False
self.name = l['name']
self.longitude = float (l['longitude'])
self.latitude = float (l['latitude'])
self.is_default = l['is_default']
self.user_id = l['user_id']
return True
def delete (self, location_id = False):
if location_id:
self.location_id = location_id
self.db.locationDeleteId (self.location_id)
if __name__ == "__main__":
pass
# vim: tw=0 ts=2 expandtab
# EOF
|