def get_competition_data(self, competition_name: str): if competition_name in self.competitions: return jsonify({ "description": self.competitions[competition_name].description, "date": self.competitions[competition_name].date, "bows": self.competitions[competition_name].bow_types, "classes": self.competitions[competition_name].archer_classes }) else: log.warn("Competition {0} not loaded couldn't update".format(competition_name))
def update_competition_info(self, competition_name: str): if competition_name in self.competitions: try: self.competitions[competition_name].set_name(request.json["name"]) self.competitions[competition_name].set_date(request.json["date"]) self.competitions[competition_name].set_description(request.json["description"]) return jsonify({ "status": "SUCCESS" }) except KeyError: log.warn("Received invalid request for updating competition {0}".format(competition_name)) else: log.warn("Competition {0} not loaded couldn't update".format(competition_name))
def save_competition(self, competition_name: str): if competition_name not in self.competitions: log.warn("Competition not loaded, can not save competition!") return jsonify({ "status": "ERROR", "error_message": "COMPETITION_NOT_LOADED" }) else: self.competitions[competition_name].save() return jsonify({ "status": "SUCCESS" })
def import_archers(self, competition_name: str): if competition_name not in self.competitions: log.warn("Competition not loaded, can not import archers!") return if request.method == "POST": if "file" not in request.files: log.warn("No file in request") else: file = request.files["file"] path = self.app.config["UPLOAD_FOLDER"] file.save(os.path.join(path, competition_name + "_archers")) self.competitions[competition_name].import_archers(path + "/{0}_archers".format(competition_name)) return jsonify({ "status": "SUCCESS", "new_archers": len(self.competitions[competition_name].archers) })
def new_competition(self): try: competition = Competition(request.json["name"], self.db_folder + request.json["name"]) competition.set_date(request.json["date"]) competition.set_description(request.json["description"]) competition.save() log.info("Created competition {0}".format(request.json["name"])) self.competitions.update({request.json["name"]: competition}) return jsonify({ "status": "SUCCESS" }) except KeyError: log.warn("Received invalid request for creating competition") return jsonify({ "status": "ERROR" })
def add_archer(self, name: str, bow_type: str, archer_class: str, club: str): if name not in self.archers: if bow_type in self.bow_types: if archer_class in self.archer_classes: new_archer = Archer(name, bow_type, archer_class, club) self.archers.append(new_archer) else: log.warn("Class {0} does not exists!".format(archer_class)) else: log.warn("Bow {0} does not exists!".format(bow_type)) else: log.warn("Archer {0} already exists!".format(name))
def remove_class(self, name: str): if name in self.archer_classes: self.archer_classes.remove(name) else: log.warn("Class {0} does not exist!".format(name))
def add_class(self, name: str): if not name in self.archer_classes: self.archer_classes.append(name) else: log.warn("Class {0} already exists!".format(name))
def remove_bow(self, name: str): if name in self.bow_types: self.bow_types.remove(name) else: log.warn("Bow {0} does not exist!".format(name))
def add_bow(self, name: str): if name not in self.bow_types: self.bow_types.append(name) else: log.warn("Bow {0} already exists!".format(name))