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"))
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)
def club_detail(club_id): cities = dao.read_city() genders = dao.read_gender() levels = dao.read_level() club = dao.read_club_by_club_id(club_id) msg = "" if request.method == "POST": name = request.form.get("name") phone = request.form.get("phone") address = request.form.get("address") image = "" gender_id = request.form.get("gender_id") level_id = request.form.get("level_id") user_id = current_user.id dao.update_club(club_id=club_id, name=name, phone=phone, address=address, image=image, gender_id=int(gender_id), level_id=int(level_id), user_id=int(user_id)) msg = "Cập nhật thông tin của đội bóng thành công !" return render_template('club-detail.html', levels=levels, cities=cities, genders=genders, club=club, msg=msg)
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)
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)
def league(): cities = dao.read_city() date_now = datetime.now() keyword = request.args["keyword"] if request.args.get("keyword") else "" city_id = request.args["city_id"] if request.args.get("city_id") else 0 leagues = dao.read_league(keyword=keyword, city_id=int(city_id)) return render_template("leagues.html", cities=cities, leagues=leagues, keyword=keyword, city_id=int(city_id), date_now=date_now)
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)
def create_league(): genders = dao.read_gender() cities = dao.read_city() date_now = (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d") msg = "" if request.method == "POST": 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 = datetime.now() date_end = request.form.get("date_end") user_id = current_user.id has_scheduled = False 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)): league = dao.create_league(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)) return redirect(url_for('create_rule', league_id=league.id)) else: msg = "Điểm thắng phải lớn hơn điểm hòa và điểm hòa phải lớn hơn điểm thua !!!" return render_template("create-league.html", genders=genders, cities=cities, date_now=date_now, msg=msg)
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)