Startegická: Krokování uživateli
This commit is contained in:
parent
121927c51e
commit
5eff62d9e6
2 changed files with 49 additions and 0 deletions
|
@ -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",
|
||||
})
|
||||
|
|
|
@ -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/<int:game_id>/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/<int:game_id>/view", methods=['GET'])
|
||||
@app.route("/game/<int:game_id>/view/<int:team_id>", methods=['GET'])
|
||||
def web_game_view(game_id, team_id=None):
|
||||
|
|
Loading…
Reference in a new issue