def post(self, community): if 'teams' not in request.json: return { "message" : "missing required dict: teams"}, 400 teams = request.json['teams'] if not isinstance(teams, list): return { "message" : "missing required dict: teams"}, 400 if len(teams) != 2: return { "message" : "incorrect number of teams"}, 400 team0 = TeamService.find_or_create(community, teams[0]) if team0 is None: return { "message" : "teams[0]: not found"}, 400 team1 = TeamService.find_or_create(community, teams[1]) if team1 is None: return { "message" : "teams[1]: not found"}, 400 if team0.id == team1.id: return { "message" : "teams are the same"}, 400 match = Match.create(community, team0, team1) db.session.add(match) db.session.commit() return match.serialize
def get_group_info(num, group): group['ranking'] = num group['section'] = group['wins'] + group['draws'] + group['loses'] team_info = TeamService.get_one(group['team_id']) if team_info: group['team_name'] = team_info['name'] group['team_badge'] = team_info['badge'] return group
def get_info(num, scorer): if scorer['player_id']: player = PlayerService.get_one(scorer['player_id']) scorer['player_photo'] = player['photo'] scorer['player_name'] = player['name'] team_info = TeamPlayerService.get_filter_one(scorer['player_id']) if team_info: scorer['team_id'] = team_info['team_id'] team = TeamService.get_one(team_info['team_id']) if team: scorer['team_name'] = team['name'] scorer['ranking'] = num return scorer
def add_schedule(): teams = TeamService.get_all() if request.method == 'GET': return render_template('admin/event/add_schedule.html', teams=teams) event_id = int(request.args.get('event_id')) schedule_dict = request.form.to_dict() schedule_dict['event_id'] = event_id MatchService.add(schedule_dict) return redirect(url_for('admin.list_match_schedules', event_id=event_id))
def edit_schedule(schedule_id): event_id = request.args.get('event_id', 0) event_id = int(event_id) match = MatchService.get_one(schedule_id) teams = TeamService.get_all() default_tm = request.args.get('date') if request.method == 'GET': return render_template('admin/event/edit_schedule.html', match=match, teams=teams) schedule_dict = request.form.to_dict() MatchService.edit(schedule_id, schedule_dict) return redirect( url_for('admin.list_match_schedules', event_id=event_id, date=default_tm))
def get_team_info(group): team_info = TeamService.get_one(group['team_id']) if team_info: group['team_name'] = team_info['name'] group['team_badge'] = team_info['badge'] score = ScoreboardService.get_filter_one(group['event_id'], group['team_id']) if score: group['id'] = score['id'] group['wins'] = score['wins'] group['draws'] = score['draws'] group['loses'] = score['loses'] group['goals_differential'] = score['goals_differential'] group['points'] = score['points'] group['section'] = group['wins'] + group['draws'] + group['loses'] return group
def post(self, community): """Method to create new team in the community. Required data: - team name ('name') - forward username ('forward') - goalkeeper username ('goalkeeper') If one of those fields is missed error will be returned. """ if 'name' not in request.json: return { "message": "missing required field: name" } name = request.json['name'].lower() if is_not_valid_entity_name(name): return { "message": "invalid name" } q = Team.query.filter_by(community_id=community.id, name=name) if q.count() != 0: return { "message": "team with this name already exists" }, 400 if 'forward' not in request.json: return { "message" : "missing required field: forward" } forward = PlayerService.find_by_username(community, request.json['forward']) if forward is None: return { "message": "forward not found" } if 'goalkeeper' not in request.json: return { "message" : "missing required field: forward" } goalkeeper = PlayerService.find_by_username(community, request.json['goalkeeper']) if goalkeeper is None: return { "message": "goalkeeper not found" } team = TeamService.create(community, name, goalkeeper, forward) return team.serialize
def get_selected_team(group): team_info = TeamService.get_one(group['team_id']) if team_info: group['name'] = team_info['name'] return group
def get_team_info(team): team = TeamService.get_one(team['team_id']) team['name'] = team['name'] return team
def list_player_teams(): teams = TeamService.get_all() return jsonify_with_data(APIError.OK, teams=teams)