From 115a8a7da59c68356471eba1070958c818d0aa08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Cuevas?= Date: Mon, 3 Jun 2013 11:44:35 +0200 Subject: [PATCH] Added possibility to edit stats --- app.py | 34 +++++++++++++++++++++++++++++----- views/edit_stat.html | 3 ++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 82106bf..93c6c29 100644 --- a/app.py +++ b/app.py @@ -105,22 +105,46 @@ class remove_stat(object): db.delete('stats', where = 'id = $index', vars = locals()) raise web.seeother('/app/config') + class edit_stat(object): def GET(self, index_to_remove): game_name = "My Game" try: index = int(index_to_remove) + for s in db.select('stats', where = 'id = $index', vars = locals()): + stat_info = s + + edit_form = add_stat() + edit_stat_form = edit_form.render() + edit_stat = render.edit_stat(stat_info, edit_stat_form) + + return render_web(game_name, edit_stat) + except Exception as e: return "Ooops! Wrong index!" - for s in db.select('stats', where = 'id = $index', vars = locals()): - stat_info = s + def POST(self, index_to_edit): + try: + if "/" in index_to_edit: + final_index = index_to_edit.split("/")[-1] + + else: + final_index = index_to_edit - edit_stat_form = add_stat.render() - edit_stat = render.edit_stat(stat_info, edit_stat_form) + index = int(final_index) + form = add_stat() + if form.validates(): + db.update('stats', + where = 'id = $index', + name = form.d.stat_name, + default_value = form.d.default_value, + vars = locals()) - return render_web(game_name, edit_stat) + raise web.seeother('/app/config') + + except Exception as e: + return "Ooops! Wrong index! %s" % str(e) diff --git a/views/edit_stat.html b/views/edit_stat.html index 6e39508..bdcf0ec 100644 --- a/views/edit_stat.html +++ b/views/edit_stat.html @@ -1,7 +1,8 @@ $def with (stat_info, edit_stat_form)

Editing $stat_info.name stat

+

Stat current default value: $stat_info.default_value

-
+ $:edit_stat_form