From 5eff62d9e6c5cd031114eef07039b936197777b9 Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda Date: Wed, 14 Sep 2022 18:16:36 +0200 Subject: [PATCH] =?UTF-8?q?Startegick=C3=A1:=20Krokov=C3=A1n=C3=AD=20u?= =?UTF-8?q?=C5=BEivateli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/hra/web/api.py | 15 +++++++++++++++ server/hra/web/pages.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/server/hra/web/api.py b/server/hra/web/api.py index 5eebe31..8e94a0b 100644 --- a/server/hra/web/api.py +++ b/server/hra/web/api.py @@ -6,6 +6,7 @@ import hra.config as config import hra.db as db from hra.web import app, NeedLoginError import hra.web.jinja_mac as jinja_mac +import hra.lib as lib def args_get(name, type, optional=False, default=None): v = request.args.get(name) @@ -100,3 +101,17 @@ def api_action(): return json.dumps({ "status": "ok", }) + + +@app.route("/api/step", methods=['POST']) +def api_step(): + team = get_context() + game = team.game + if game.step_mode != db.StepMode.user: + raise werkzeug.exceptions.Forbidden("Je zakázáno krokovat tuto hru") + + lib.game_step(game.game_id) + + return json.dumps({ + "status": "ok", + }) diff --git a/server/hra/web/pages.py b/server/hra/web/pages.py index 219e81b..df86115 100644 --- a/server/hra/web/pages.py +++ b/server/hra/web/pages.py @@ -99,6 +99,17 @@ def right_for_team(team): return team.user_id == g.user.id +def right_for_step(game): + if right_for_game(game): + if g.org: + if game.step_mode == db.StepMode.org: + return True + if game.step_mode == db.StepMode.user: + return True + return False + + + def game_link(game): b = html.Builder() with b.line(): @@ -226,6 +237,11 @@ def web_game(game_id): b = BasePage() b.h2("Hra ", game.print()) + with b.line().p("Aktuální kolo: "): + if game.working_on_next_state: + b.b()(game.current_round, "++") + else: + b(game.current_round) with b.p().table(_class="data full"): with b.thead(): b.line().th()("Id") @@ -242,8 +258,26 @@ def web_game(game_id): if g.org: b.a(_class="btn btn-xs btn-default", href=app.url_for(web_org_game_userchange.__name__, game_id=game.game_id, team_id=team.team_id))("Změnit uživatele") + with b.div(_class="btn-gruser_idoup", role="group"): + if right_for_step(game): + with b.form(method="POST", _class="btn-group", action=app.url_for(web_game_step.__name__, game_id=game_id)): + b.button(_class="btn btn-primary", type="submit", name="su", value="yes")("Krok") + return b.print_file() +@app.route("/game//step", methods=['POST']) +def web_game_step(game_id): + ses = db.get_session() + game = ses.query(db.Game).filter_by(game_id=game_id).one_or_none() + if game is None: + raise werkzeug.exceptions.NotFound() + if not right_for_step(game): + raise werkzeug.exceptions.Forbidden() + + lib.game_step(game_id) + + return redirect(app.url_for(web_game.__name__, game_id=game_id)) + @app.route("/game//view", methods=['GET']) @app.route("/game//view/", methods=['GET']) def web_game_view(game_id, team_id=None):