def new_sheet_request(): form = request.form tid = form.get("tid").lstrip("0") mid = form.get("mid").strip().upper() alliance = form.get("alliance") if not validate_match(mid): # Match id does not match the regex raise WebException("Invalid match id.") _match = match.get_match(mid=mid).first() if _match is None: # Match does not exist yet, so create one match.add_match(mid) _team = team.get_team(tid=tid).first() if _team is None: # Team does not exist yet, so create one team.add_team(tid) sheet = get_sheet(tid=tid, mid=mid, alliance=alliance).first() if sheet is not None: # Duplicate sheet exists, so alert the user raise WebException("Sheet already exists.") # Create a new sheet new_sheet(tid, mid, alliance) return {"success": 1, "message": "Sheet created."}
def update_sheet_request(): form = request.form sid = form.get("sid") mid = form.get("mid").strip().upper() tid = form.get("tid").lstrip("0") alliance = form.get("alliance") if not validate_match(mid): # Match id does not match the regex raise WebException("Invalid match id.") _match = match.get_match(mid=mid).first() if _match is None: # Match does not exist yet, so create one match.add_match(mid) _team = team.get_team(tid=tid).first() if _team is None: # Team does not exist yet, so create one team.add_team(tid) update_sheet(sid, mid, tid, alliance) return {"success": 1, "message": "Sheet updated."}