diff options
author | Jogi Hofmüller <jogi@mur.at> | 2011-08-03 11:19:44 +0000 |
---|---|---|
committer | Jogi Hofmüller <jogi@mur.at> | 2011-08-03 11:19:44 +0000 |
commit | 502b6a813a6f90c2e7adb5781b1beecd559014d9 (patch) | |
tree | 6c46b328e6a106bc770ad77650c0b6a14fb525e5 /tools/mmd/MmdLocation.py | |
parent | cleanup (diff) |
- added functionality for location
- user's default location is save
- map centers on user's location iff available
git-svn-id: https://svn.spreadspace.org/mur.sat@96 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'tools/mmd/MmdLocation.py')
-rw-r--r-- | tools/mmd/MmdLocation.py | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/tools/mmd/MmdLocation.py b/tools/mmd/MmdLocation.py index 67a1a74..e3212bb 100644 --- a/tools/mmd/MmdLocation.py +++ b/tools/mmd/MmdLocation.py @@ -14,8 +14,15 @@ def checkLonLat (lonlat): class Location: - def __init__ (self): + 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 @@ -36,19 +43,31 @@ class Location: if not l: return False self.name = l['name'] - self.longitude = int (l['longitude']) - self.latitude = int (l['latitude']) + 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__": - l = Location () - try: - assert l, 'Location instantiation failed' - assert l.create ('Graz', '14.5', '47.3', 'yes', '1'), 'Location create failed' - assert l.findUserId (1), 'Location find user by id failed' - except AssertionError as e: - print 'Test failed: {0}'.format (e) + pass # vim: tw=0 ts=2 expandtab # EOF |