def points_form(): form=PointForm(request.form) fighters=Fighter.query.all() fighter1_id=request.args.get('fighter1_id') fighter2_id=request.args.get('fighter2_id') fighter1= Fighter.find_fighter_names(fighter1_id, fighters) fighter2= Fighter.find_fighter_names(fighter2_id, fighters) match_id=request.args.get('match_id') return render_template("points/points.html", fighter1=fighter1, fighter2=fighter2, fighter1_id=fighter1_id, fighter2_id=fighter2_id ,match_id=match_id, form=form)
def matches_index(): filterform=FilterForm() filterform.by_club.choices=clubs=Fighter.get_clubs() matches= Match.query.order_by(Match.date.desc()).all() to_list=form_matchlist(matches) return render_template("matches/list.html", matches = to_list, searchform=SearchForm(), filterform=filterform)
def form_matchlist(matches): if len(matches)==0: return [] all_fighters=Fighter.query.all() to_list=[] for match in matches: fighters= Match.get_fighters(match.id) fighter1=fighters[0]["name"] belt1=set_belt_color(fighters[0]["belt"]) fighter2=fighters[1]["name"] belt2=set_belt_color(fighters[1]["belt"]) winner= Fighter.find_fighter_names(match.winner_id,all_fighters) if match.winning_category=='Pistevoitto': p=Points.get_points(match.id) points= "{:d} | {:d} | {:d} -- {:d} | {:d} | {:d}".format(p[0]["points"], p[0]["penalties"], p[0]["advantage"], p[1]["points"], p[1]["penalties"], p[1]["advantage"]) to_list.append({"id": match.id, "date":match.date, "place": match.place, "winner_id":match.winner_id, "winner":winner, "fighter1":fighter1,"belt1":belt1, "fighter2":fighter2,"belt2":belt2, "winning_category": match.winning_category, "comment":match.comment, "points":points}) else: to_list.append({"id": match.id, "place": match.place, "date":match.date, "winner_id":match.winner_id, "winner":winner, "fighter1":fighter1, "belt1":belt1, "fighter2":fighter2, "belt2":belt2, "winning_category": match.winning_category, "comment":match.comment}) return to_list
def fighters_index(): filterform=FilterForm() filterform.by_club.choices=Fighter.get_clubs() belt_filter= dict(filterform.by_belt.choices).get(filterform.by_belt.data) club_filter= dict(filterform.by_club.choices).get(filterform.by_club.data) return render_template("fighters/list.html", fighters= Fighter.query.all(), searchform=SearchForm(), filterform=filterform)
def fighters_filter(): filterform=FilterForm(request.form) clubs=Fighter.get_clubs() filterform.by_club.choices=clubs belt = request.args.get('by_belt') club = request.args.get('by_club') if (belt != '-1' or club != '-1'): fighters=Fighter.filter_fighters(belt, club, clubs) return render_template("fighters/list.html", fighters=fighters, searchform=SearchForm(), filterform=filterform) else: return redirect(url_for("fighters_index"))
def fighters_index(): filterform = FilterForm() filterform.by_club.choices = Fighter.get_clubs() return render_template("fighters/list.html", fighters=Fighter.query.order_by(Fighter.name).all(), searchform=SearchForm(), filterform=filterform)
def fighter_info(fighter_id): fighter = Fighter.query.get_or_404(fighter_id) history = Fighter.get_match_history(fighter_id) return render_template("fighters/fighter.html", fighter=fighter, history=history)
def add_points(): form=PointForm(request.form) fighter1_id=request.args.get('fighter1_id') fighter2_id=request.args.get('fighter2_id') match_id=request.args.get('match_id') fighters=Fighter.query.all() fighter1= Fighter.find_fighter_names(fighter1_id, fighters) fighter2= Fighter.find_fighter_names(fighter2_id, fighters) if not form.validate(): return render_template("points/points.html", error='Luvut eivät kelpaa', form = form, fighter1=fighter1, fighter2=fighter2, fighter1_id=fighter1_id, fighter2_id=fighter2_id, match_id=match_id) match=Match.query.get(match_id) points=form.fighter1_points.data penalties= form.fighter1_penalties.data advantage=form.fighter1_advantages.data points_fighter1= Points(points, penalties, advantage, fighter1_id) db.session().add(points_fighter1) db.session().commit() points=form.fighter2_points.data penalties= form.fighter2_penalties.data advantage=form.fighter2_advantages.data points_fighter2= Points(points, penalties, advantage, fighter2_id) db.session().add(points_fighter2) db.session().commit() match.points.append(points_fighter1) db.session().commit() match.points.append(points_fighter2) db.session().commit() return redirect(url_for("matches_index"))
def fighters_search(): filterform=FilterForm() filterform.by_club.choices=clubs=Fighter.get_clubs() search_by =request.args.get('searchword') if len(search_by)==0: return redirect(url_for("fighters_index")) qry = db.session().query(Fighter).filter( Fighter.name.contains(search_by)) results= qry.all() return render_template("fighters/list.html", fighters= results, searchform=SearchForm(), filterform=filterform)
def matches_filter(): filterform=FilterForm(request.form) clubs=Fighter.get_clubs() filterform.by_club.choices=clubs belt = request.args.get('by_belt') club = request.args.get('by_club') winning_category= request.args.get('by_winning_category') if (belt != '-1' or club != '-1' or winning_category != '-1'): matches =Match.filter_matches(belt, club, clubs, winning_category) to_list=form_matchlist(matches) return render_template("matches/list.html", matches=to_list, searchform=SearchForm(), filterform=filterform) else: return redirect(url_for("matches_index"))
def fighters_create(): form = FighterForm(request.form) if not form.validate(): return render_template("fighters/new.html", form = form) name=form.name.data born=form.born.data belt = dict(form.belt.choices).get(form.belt.data) club= form.club.data weight=form.weight.data creator_id= current_user.id f= Fighter(name, born, belt, club, weight, creator_id) db.session().add(f) db.session().commit() return redirect(url_for("fighters_index"))
def matches_search(): filterform=FilterForm() filterform.by_club.choices=clubs=Fighter.get_clubs() search_by =request.args.get('searchword') if len(search_by)==0: return redirect(url_for("matches_index")) qry = db.session().query(Fighter).filter( Fighter.name.contains(search_by)) fighters= qry.all() if len(fighters)==0: to_list=[] else: matches = Match.get_matches_by_fighter(fighters) to_list=form_matchlist(matches) return render_template("matches/list.html", matches = to_list, searchform=SearchForm(), filterform=filterform)
def matches_index(): matches = Match.query.all() all_fighters=Fighter.query.all() to_list=[] for match in matches: fighters= Match.get_fighters(match.id) fighter1=fighters[0]["name"] fighter2=fighters[1]["name"] winner= Fighter.find_fighter_names(match.winner_id,all_fighters) if match.winning_category=='Pistevoitto': p=Points.get_points(match.id) points= "{:d}|{:d}|{:d} - {:d}|{:d}|{:d}".format(p[0]["points"], p[0]["penalties"], p[0]["advantage"], p[1]["points"], p[1]["penalties"], p[1]["advantage"]) to_list.append({"id": match.id, "date":match.date, "place": match.place, "winner_id":match.winner_id, "winner":winner, "fighter1":fighter1, "fighter2":fighter2, "winning_category": match.winning_category, "comment":match.comment, "points":points}) else: to_list.append({"id": match.id, "place": match.place, "date":match.date, "winner_id":match.winner_id, "winner":winner, "fighter1":fighter1, "fighter2":fighter2, "winning_category": match.winning_category, "comment":match.comment}) return render_template("matches/list.html", matches = to_list)