示例#1
0
def schedule(league_id):
    league = dao.read_league_by_id(league_id)
    cities = dao.read_city()
    clubs = dao.read_club_by_league_id(league_id)
    check_date = dao.check_date_end_league(league.date_end)
    date_now = datetime.now()
    msg = ""

    if request.method == "POST":
        if not league.has_scheduled:
            dao.create_balanced_round_robin(league_id=league_id, clubs=clubs)
            dao.update_league(league_id=league.id,
                              name=league.name,
                              address=league.address,
                              image=league.image,
                              gender_id=league.gender_id,
                              city_id=league.city_id,
                              date_begin=league.date_begin,
                              date_end=(date_now - timedelta(days=1)),
                              user_id=league.user_id,
                              has_scheduled=True,
                              win_point=league.win_point,
                              draw_point=league.draw_point,
                              lose_point=league.lose_point)

            return redirect(url_for('schedule', league_id=league_id))
        else:
            msg = "Giải đấu đã có lịch thi đấu !"

    return render_template('schedule.html',
                           league=league,
                           cities=cities,
                           check_date=check_date,
                           msg=msg,
                           date_now=date_now.strftime("%Y-%m-%d"))
示例#2
0
def rules(league_id):
    league = dao.read_league_by_id(league_id)
    rules = dao.get_rules_by_league_id(league_id)
    cities = dao.read_city()
    check_date = dao.check_date_end_league(league.date_end)
    msg = ""

    if request.method == "POST":
        min_age = request.form.get("min_age")
        max_age = request.form.get("max_age")
        min_player = request.form.get("min_player")
        max_player = request.form.get("max_player")
        max_foreign_player = request.form.get("max_foreign_player")

        dao.update_rule(min_age=int(min_age),
                        max_age=int(max_age),
                        min_player=int(min_player),
                        max_player=int(max_player),
                        max_foreign_player=int(max_foreign_player),
                        league_id=int(league_id))

        msg = "Cập nhật quy định giải đấu thành công !!!"

    return render_template('rules.html',
                           league=league,
                           rules=rules,
                           cities=cities,
                           check_date=check_date,
                           msg=msg)
示例#3
0
def settings(league_id):
    cities = dao.read_city()
    genders = dao.read_gender()
    league = dao.read_league_by_id(league_id)
    date_now = (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d')
    check_date = dao.check_date_end_league(league.date_end)

    err_msg = ""
    msg = ""

    if request.method == "POST":
        if request.form.get("name") and request.form.get("address") and \
                request.form.get("gender_id") and request.form.get("city_id"):
            name = request.form.get("name")
            address = request.form.get("address")
            image = ""
            gender_id = request.form.get("gender_id")
            city_id = request.form.get("city_id")
            date_begin = league.date_begin
            date_end = league.date_end
            user_id = current_user.id
            has_scheduled = True
            win_point = request.form.get("win_point")
            draw_point = request.form.get("draw_point")
            lose_point = request.form.get("lose_point")

            if dao.check_point_win_draw_lose(win_point=int(win_point),
                                             draw_point=int(draw_point),
                                             lose_point=int(lose_point)):
                dao.update_league(league_id=league_id,
                                  name=name,
                                  address=address,
                                  image=image,
                                  gender_id=int(gender_id),
                                  city_id=int(city_id),
                                  date_begin=date_begin,
                                  date_end=date_end,
                                  user_id=int(user_id),
                                  has_scheduled=has_scheduled,
                                  win_point=int(win_point),
                                  draw_point=int(draw_point),
                                  lose_point=int(lose_point))

            msg = "Cập nhật thông tin của giải đấu thành công !"

    return render_template('settings.html',
                           league=league,
                           cities=cities,
                           genders=genders,
                           msg=msg,
                           err_msg=err_msg,
                           date_now=date_now,
                           check_date=check_date)
示例#4
0
def clubs_league(league_id):
    cities = dao.read_city()
    league = dao.read_league_by_id(league_id)
    check_date = dao.check_date_end_league(league.date_end)

    league_club = dao.read_league_club_by_league_id(league_id=league_id)

    return render_template('clubs-league.html',
                           league=league,
                           cities=cities,
                           check_date=check_date,
                           league_club=league_club)
示例#5
0
def register_league(league_id):
    rule = dao.get_rules_by_league_id(league_id)
    cities = dao.read_city()
    msg = ""

    if request.method == "POST":
        league_id = league_id
        club_id = request.form.get("club_id")
        status_id = 1

        total_player = dao.get_total_player_by_club_id(int(club_id))
        if rule.min_player <= total_player <= rule.max_player:
            dao.create_league_club(league_id=league_id,
                                   club_id=int(club_id),
                                   status_id=status_id)
            msg = {
                "alert_type": "success",
                "content": "Đăng ký đội bóng thành công !!!"
            }
        else:
            msg = {
                "alert_type":
                "warning",
                "content":
                "Số lượng cầu thủ tối thiểu của đội là " +
                str(rule.min_player) + " và tối đa là " + str(rule.max_player)
            }

    league = dao.read_league_by_id(league_id)
    league_club = dao.get_club_id_in_league_club_by_league_id(league_id)

    check_date = False
    date_now = (datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d')
    date_end = (league.date_end + timedelta(days=1)).strftime('%Y-%m-%d')

    if date_now <= date_end:
        check_date = True

    return render_template('register-league.html',
                           league=league,
                           rule=rule,
                           cities=cities,
                           date_now=date_now,
                           date_end=date_end,
                           check_date=check_date,
                           league_club=league_club,
                           msg=msg)
示例#6
0
def get_round_by_round_name(round_name, league_id):
    league = dao.read_league_by_id(league_id)
    round_name = int(round_name)
    matches = []

    for idx, round in enumerate(league.rounds):
        if round_name == idx + 1:
            for match in round.matches:
                m = {
                    'match_id':
                    match.id,
                    'home':
                    dao.read_club_name_by_club_id(match.home),
                    'home_id':
                    match.home,
                    'home_score':
                    dao.get_score_by_league_club_match(league_id=league_id,
                                                       match_id=match.id,
                                                       club_id=match.home),
                    'away':
                    dao.read_club_name_by_club_id(match.away),
                    'away_id':
                    match.away,
                    'away_score':
                    dao.get_score_by_league_club_match(league_id=league_id,
                                                       match_id=match.id,
                                                       club_id=match.away),
                    'date':
                    match.date,
                    'time':
                    str(match.time),
                    'is_ended':
                    match.is_ended
                }
                matches.append(m)
            break
    return jsonify({
        'user_id': league.user_id,
        'round': round_name,
        'matches': matches
    })
示例#7
0
def create_rule(league_id):
    league = dao.read_league_by_id(league_id)
    if request.method == "POST":
        min_age = request.form.get("min_age")
        max_age = request.form.get("max_age")
        min_player = request.form.get("min_player")
        max_player = request.form.get("max_player")
        max_foreign_player = request.form.get("max_foreign_player")

        rule = dao.create_rule(min_age=int(min_age),
                               max_age=int(max_age),
                               min_player=int(min_player),
                               max_player=int(max_player),
                               max_foreign_player=int(max_foreign_player),
                               league_id=int(league_id))

        return render_template('register-league.html',
                               league_id=league_id,
                               league=league,
                               rule=rule)

    return render_template('create-rule.html', league_id=league_id)
示例#8
0
def list_register(league_id):
    league = dao.read_league_by_id(league_id)
    cities = dao.read_city()
    status = dao.read_status()
    check_date = dao.check_date_end_league(league.date_end)

    league_club = dao.read_league_club_by_league_id(league_id=league_id)

    if request.args.get('status_id') and request.args.get('club_id'):
        status_id = request.args.get('status_id')
        club_id = request.args.get('club_id')

        dao.update_status_club_in_league_club(league_id=league_id,
                                              club_id=int(club_id),
                                              status_id=int(status_id))

        return redirect(url_for('list_register', league_id=league_id))

    return render_template('list-register.html',
                           league=league,
                           cities=cities,
                           status=status,
                           check_date=check_date,
                           league_club=league_club)