def undo(button): valid, office = validateKey() if not valid: return invalidKey() if not validateButton(button): return invalidButton() data = None response = { "activeMatch": False, "matchId": None, "action": "undo", "button": button, "officeId": office.id, "officeName": "{}, {}".format(office.city, office.state) } match = matchService.selectActiveMatch(office.id) if match != None: response["activeMatch"] = True response["matchId"] = match.id matchType = MatchType(match) data = matchType.undo(match, button) socketio.emit("response-{}".format(office.id), data, broadcast=True) return Response(json.dumps(response), status=200, mimetype="application/json")
def undo(button): valid, office = validateKey() if not valid: return invalidKey() if not validateButton(button): return invalidButton() data = None response = { "activeMatch": False, "matchId": None, "action": "undo", "button": button, "officeId": office.id, "officeName": "{}, {}".format(office.city, office.state) } match = matchService.selectActiveMatch(office.id) if match != None: response["activeMatch"] = True response["matchId"] = match.id matchType = MatchType(match) data = matchType.undo(match, button) socketio.emit("response-{}".format(office.id), data, broadcast = True) return Response(json.dumps(response), status = 200, mimetype = "application/json")
def players(id): match = matchService.selectById(id) exists(match) matchType = MatchType(match) instance = matchType.getMatchType() players = playerService.selectActive(session["office"]["id"]) return render_template("matches/players.html", title = instance.label, matchType = instance, match = match, players = players)
def create(): hasErrors = matchForm.validateNew(request.form) if hasErrors: return new(), 400 match = matchService.create(session["office"]["id"], request.form["matchType"]) matchType = MatchType(match) if matchType.isNines(): return redirect(url_for("matchController.players", id = match.id)) return redirect(url_for("matchController.play_to", id = match.id))
def undo(id): match = matchService.selectById(id) exists(match) if match.ready or current_user.is_authenticated: matchType = MatchType(match) data = matchType.undo(match, None) if request.is_xhr: socketio.emit("response-{}".format(match.officeId), data, broadcast = True) return Response("", status = 200, mimetype = "application/json") else: return redirect(url_for("matchController.show", id = match.id))
def again(id): match = matchService.selectById(id) exists(match) matchType = MatchType(match) numOfGames = None randomize = True if "numOfGames" in request.form: numOfGames = int(request.form["numOfGames"]) if "randomize" in request.form: randomize = request.form["randomize"] == "true" newMatch = matchType.playAgain(match, numOfGames, randomize) return redirect(url_for("matchController.show", id = newMatch.id))
def show_json(id): match = matchService.selectById(id) exists(match) data = MatchType(match).matchData() return Response(json.dumps(data, default = util.jsonSerial), status = 200, mimetype = "application/json")
def show(id): match = matchService.selectById(id) exists(match) data = MatchType(match).matchData() return render_template(data["template"], data = data)
def index(): offices = officeService.selectWithSkypeChatId() matchData = None match = matchService.selectActiveMatch(session["office"]["id"]) if match != None: matchData = MatchType(match).matchData() return render_template("admin/index.html", matchData = matchData, offices = offices)
def score(button): valid, office = validateKey() if not valid: return invalidKey() if not validateButton(button): return invalidButton() data = None response = { "activeMatch": False, "matchId": None, "action": "score", "button": button, "officeId": office.id, "officeName": "{}, {}".format(office.city, office.state) } match = matchService.selectActiveMatch(office.id) if match != None: matchType = MatchType(match) data = matchType.score(match, button) response["activeMatch"] = True response["matchId"] = match.id else: latestMatch = matchService.selectLatestMatch(office.id) matchType = MatchType(latestMatch) if matchType.isNines(): newMatch = matchType.playAgain(latestMatch, None, True) response["matchId"] = newMatch.id data = { "matchType": "nines", "redirect": True, "matchId": newMatch.id } socketio.emit("response-{}".format(office.id), data, broadcast = True) return Response(json.dumps(response), status = 200, mimetype = "application/json")
def score(button): valid, office = validateKey() if not valid: return invalidKey() if not validateButton(button): return invalidButton() data = None response = { "activeMatch": False, "matchId": None, "action": "score", "button": button, "officeId": office.id, "officeName": "{}, {}".format(office.city, office.state) } match = matchService.selectActiveMatch(office.id) if match != None: matchType = MatchType(match) data = matchType.score(match, button) response["activeMatch"] = True response["matchId"] = match.id else: latestMatch = matchService.selectLatestMatch(office.id) matchType = MatchType(latestMatch) if matchType.isNines(): newMatch = matchType.playAgain(latestMatch, None, True) response["matchId"] = newMatch.id data = { "matchType": "nines", "redirect": True, "matchId": newMatch.id } socketio.emit("response-{}".format(office.id), data, broadcast=True) return Response(json.dumps(response), status=200, mimetype="application/json")
def players_create(id): match = matchService.selectById(id) exists(match) matchType = MatchType(match) hasErrors = matchPlayerForm.validate(matchType, request.form) if hasErrors: return players(id) else: if not match.hasTeams(): matchType.createTeams(match, request.form.getlist("playerId"), True) if not match.isReady(): matchType.play(match) return redirect(url_for("matchController.show", id = id))