From a47943e5f92a9366df4d271a47f021d68c0ef3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Cuevas?= Date: Tue, 4 Jun 2013 01:40:53 +0200 Subject: [PATCH] Queries implemented --- app.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/app.py b/app.py index 5ee6a33..f2d9dcc 100644 --- a/app.py +++ b/app.py @@ -26,6 +26,7 @@ urls = ( '/app/player_edit/(.+)', 'edit_player', '/app/config', 'config', '/app/config/', 'config', + '/query/(.+)', 'query', ) # Forms used by the app @@ -354,5 +355,37 @@ class config(object): return "Ooops! Something went wrong." +class query(object): + def GET(self, uuid): + for p in db.select('players', where = 'code = $uuid', vars = locals()): + player = p + + name = player.name + + stats = [] + for stat in db.select('stats'): + default_value = stat.default_value + stat_name = stat.name + stat_id = stat.id + sheet_stat = None + query = db.select('sheet', + where = 'stat_id = $stat_id AND player_name = $name', + vars = locals()) + + for elem in query: + sheet_stat = elem + + if sheet_stat is not None: + stat_value = sheet_stat.value + + else: + stat_value = default_value + + stats.append(stat_name + ":" + str(stat_value)) + + result = name + "--" + ",".join(stats) + return result + + if __name__ == "__main__": app.run()