コード例 #1
0
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)
コード例 #2
0
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
コード例 #3
0
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"))
    
コード例 #4
0
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)