コード例 #1
0
    def add_archer(self, competition_name: str):
        if competition_name in self.competitions:
            request_data = request.get_json()

            if request_data:
                competition = self.competitions[competition_name]

                name = request_data["name"]
                bow_type = request_data["bow"]
                archer_class = request_data["class"]
                archer_club = request_data["club"]

                competition.add_archer(name, bow_type, archer_class, archer_club)

                log.info("Added new archer (name: {0}, bow: {1}, class: {2}".format(name, bow_type, archer_class))

                return jsonify({
                    "status": "SUCCESS"
                })
        else:
            log.error("No competition with name {0} loaded".format(competition_name))

            return jsonify({
                "status": "ERROR",
                "error_message": "UNKNOWN_COMPETITION"
            })
コード例 #2
0
    def load_competition(self, competition_name: str):
        if competition_name not in self.competitions:
            try:
                competition = Competition.load_competition(self.db_folder + competition_name)
                self.competitions.update({competition_name: competition})

                return jsonify({
                    "status": "SUCCESS",
                    "competition_name": competition_name,
                    "new": False
                })
            except OSError:
                log.error("Could not find config for competition {0}".format(competition_name))

                return jsonify({
                    "status": "ERROR",
                    "error_message": "ALREADY_LOADED",
                    "competition_name": competition_name,
                    "new": False
                })

            except Exception as exc:
                log.info("Could not find config for competition {0} \n Exception: {1}".format(competition_name, exc))

                return jsonify({
                    "status": "ERROR",
                    "error_message": "CONFIG_LOADING_ERROR",
                    "competition_name": competition_name,
                    "new": False
                })

        elif competition_name in self.competitions:
            return jsonify({
                "status": "ERROR",
                "error_message": "ALREADY_LOADED"
                })