Пример #1
0
def newPlayer(team_id):
    if 'username' not in login_session:
        return redirect('/login')
    team = session.query(Team).filter_by(id=team_id).one()
    if login_session['user_id'] != team.user_id:
        return "<script>function myFunction() {alert('You are not authorized \
                to add players to this team. Please create your own team in \
                order to add players.');}</script><body onload='myFunction()'>"
    if request.method == 'POST':
        if not request.form['name']:
	    flash('Please add player name')
            return redirect(url_for('newPlayer', team_id=team_id))

        playerPosition = request.form.get("position","")
        if playerPosition == "":
            flash('Please select player position')
            return redirect(url_for('newPlayer', team_id=team_id))
            
        if not request.form['games_played']:
	    flash('Please enter games played')
            return redirect(url_for('newPlayer', team_id=team_id))
        
        newItem = Player(
                name=request.form['name'], position=request.form['position'],
                            games_played=request.form['games_played'],
                            team_id=team_id, user_id=team.user_id)
        session.add(newItem)
        session.commit()
        flash('New Player %s Successfully added to roster' % (newItem.name))
        return redirect(url_for('showRoster', team_id=team_id))
    else:
        return render_template('newplayer.html', team_id=team_id)
Пример #2
0
def newPlayer(sport_id):
    if 'username' not in login_session:
        return redirect(url_for('sports', sport_id=sport_id))

    if request.method == 'POST':
        file = request.files['photo']
        if file:
            photo = file.filename
            file.save(os.path.join('static/img/', photo))
        else:
            photo = None

        player = Player(name=request.form['name'],
                        dob=datetime.strptime(request.form['dob'],
                                              '%Y-%m-%d').date(),
                        photo=photo,
                        sport_id=sport_id,
                        user_id=login_session['user_id'])
        session.add(player)
        session.commit()
        return redirect(url_for('sports', sport_id=sport_id))
    else:
        profile_picture = login_session['picture']
        sport = session.query(Sport).filter_by(id=sport_id).one()
        return render_template('newPlayer.html',
                               sport=sport,
                               sport_id=sport_id,
                               profile_picture=profile_picture)
Пример #3
0
def addNewPlayer(team_ID):
    """Add a new player to team"""
    if not checkLogin(login_session):
	flash('You must login to add a new player')
	return redirect(url_for('showTeams'))
    if request.method=='POST':
	newPlayer=Player(name=request.form['name'],
			description = request.form['description'], 
			user_id = login_session.get('user_id'), 
			salary = request.form['salary'], 
			team_id = team_ID)
	session.add(newPlayer)
	session.commit()
	flash('New Player %s has been successfully Created' % newPlayer.name)
	return redirect(url_for('showTeams', team_ID=team_ID))
    else:
	return render_template('newPlayer.html',team_ID=team_ID,login_session=login_session)
Пример #4
0
def newPlayer(club_id):
    if 'username' not in login_session:
        return redirect('/login')
    club = session.query(Club).filter_by(id=club_id).one()
    if login_session['user_id'] != club.user_id:
        return "<script>function myFunction() {alert('You are not authorized to add player items to this Club. Please create your own Club in order to add items.');}</script><body onload='myFunction()'>"
    if request.method == 'POST':
        newPlayer = Player(name=request.form['name'],
                           position=request.form['position'],
                           market_value=request.form['market_value'],
                           age=request.form['age'],
                           nationality=request.form['nationality'],
                           club_id=club_id,
                           user_id=club.user_id)
        session.add(newPlayer)
        session.commit()
        flash('New Player %s Item Successfully Created' % (newPlayer.name))
        return redirect(url_for('showClub', club_id=club_id))
    else:
        return render_template('newPlayer.html', club_id=club_id)
Пример #5
0
def newPlayer(team_id):
    if 'username' not in login_session:
        return redirect('/login')
    team = session.query(Team).filter_by(id=team_id).one()
    if login_session['user_id'] != team.user_id:
        return ("<script>function myFunction() {alert('You are not authorized"
                " to add players to this team. Please create your own team in"
                " order to add different players.');}</script><body "
                "onload='myFunction()'>")
    if request.method == 'POST':
        newPlayer = Player(name=request.form['name'],
                           yr_strtd=request.form['yr_strtd'],
                           origin=request.form['origin'],
                           position=request.form['position'],
                           team_id=team_id, user_id=team.user_id)
        session.add(newPlayer)
        session.commit()
        flash('New Player %s Successfully Created' % (newPlayer.name))
        return redirect(url_for('showPlayer', team_id=team_id))
    else:
        return render_template('newplayer.html', team_id=team_id)
Пример #6
0
def newPlayer(team_id):
    teamUserId = session.query(Team).filter_by(team_id).one()
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST' and 'username' in login_session and \
            login_session['user_id'] == teamUserId.user_id:
        newPlayer = Player(name=request.form['name'],
                           position=request.form['pos'],
                           number=request.form['jerseynumber'],
                           dob=request.form['dob'],
                           nationality=request.form['nationality'],
                           contract=request.form['contract'],
                           marketvalue=request.form['value'],
                           team_id=team_id,
                           user_id=login_session['user_id'])
        session.add(newPlayer)
        session.commit()
        flash('New Player %s Successfully Created' % (newPlayer.name))
        return redirect(url_for('showCompetetion'))
    else:
        return render_template('newPlayeritem.html', team_id=team_id)
Пример #7
0
def newPlayer(team_id):
    """ Renders html page for creating new player in db """
    if 'username' not in login_session:
        return redirect('/login')
    team = session.query(Team).filter_by(id=team_id).one()
    if login_session['user_id'] != team.user_id:
        return "<script>function myFunction() {alert('You are not authorized \
        to add players to this team. Please create your own team in order to \
        add players.');}</script><body onload='myFunction()''>"
    if request.method == 'POST':
        newItem = Player(
            name=request.form['name'],
            description=request.form['description'],
            team_id=team_id,
            user_id=team.user_id
        )
        session.add(newItem)
        session.commit()
        flash('New Player %s Successfully Created' % (newItem.name))
        return redirect(url_for('showPlayer', team_id=team_id))
    else:
        return render_template('newplayer.html', team_id=team_id)
Пример #8
0
def newPlayer(team_id):
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == "POST":
        file = request.files['picture']
        if file and helper.allowed_file(file.filename):
            extension = file.filename.rsplit('.', 1)
            filename = secure_filename(file.filename)
            filename = helper.hash_filename(filename) + "." + extension[1]
            # saves file in file system
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        else:
            filename = 'no_picture.jpg'
        newPlayer = Player(
            name=request.form['name'],
            email=request.form['email'],
            phone=request.form['phone'],
            skill_level=request.form['skill_level'],
            picture=filename,
            summary=request.form['summary'],
            team_id=team_id,
            share_contact=request.form['share_contact'],
            created_on=datetime.datetime.strptime(
                strftime("%Y-%m-%d %H:%M:%S", localtime()),
                "%Y-%m-%d %H:%M:%S"),
            created_by=login_session['user_id'],
            is_active='1' if request.form['status'] == 'Active' else '0',
            is_delete='0',
        )
        session.add(newPlayer)
        session.commit()
        flash('New Player %s Successfully Created' % newPlayer.name)
        return redirect(url_for('showPlayers', team_id=team_id))
    else:
        skill_levels = ['Beginner', 'Intermediate', 'Advanced']
        return render_template('players/newplayer.html',
                               skill_levels=skill_levels)
Пример #9
0
def newPlayerPage(team_id):
    # Ensure user is signed in
    if 'username' not in login_session:
        return redirect('/login')
    # If GET, serve form; If POST receive data, commit new player to db
    if request.method == 'POST':
        newPlayer = Player(firstName=request.form['firstName'],
                           lastName=request.form['lastName'],
                           position=request.form['position'],
                           height=request.form['height'],
                           weight=request.form['weight'],
                           birthdate=request.form['birthdate'],
                           birthCity=request.form['birthCity'],
                           birthLocation=request.form['birthLocation'],
                           birthNation=request.form['birthNation'],
                           bio=request.form['bio'],
                           user_id=login_session['user_id'],
                           team_id=team_id)
        session.add(newPlayer)
        session.commit()
        flash("New Player Created!")
        return redirect(url_for('teamPage', team_id=team_id))
    else:
        return render_template('newPlayer.html', team_id=team_id)
Пример #10
0
def newPlayers(team_id):
    team = session.query(Team).filter_by(id=team_id).one()
    if login_session['user_id'] != team.user_id:
        return "<script>function myFunction() " \
               "{alert('You can only add players to teams you have created.');}" \
               "</script><body onload='myFunction()'>"
    if request.method == 'POST':
        newPlayer = Player(
            firstName=request.form['firstName'],
            lastName=request.form['lastName'],
            position=request.form['position'],
            playerNum=request.form['playerNum'],
            height=request.form['height'],
            weight=request.form['weight'],
            age=request.form['age'],
            birthplace=request.form['birthplace'],
            college=request.form['college'],
            role=request.form['role'],
            team_id=team_id)
        session.add(newPlayer)
        session.commit()
        return redirect(url_for('showPlayers', team_id=team_id))
    else:
        return render_template('newplayers.html', team_id=team_id)
Пример #11
0
player1 = Player(firstName="Dylan",
                 lastName="Larkin",
                 position="C",
                 team=detroit,
                 height="""6' 1" """,
                 weight="198 lb",
                 birthdate="July 30, 1996",
                 birthCity="Waterford",
                 birthLocation="Michigan",
                 birthNation="USA",
                 user_id="1",
                 bio=""" The moment was duly noted and set down for
                 posterity by all those
    who hold the Detroit Red Wings near and dear to their heart.
     Only 20 seconds into the second period of Larkin's NHL debut, Oct. 9,
     2015, the phenom from Waterford, Mich., took a pass from Henrik
     Zetterberg and snapped a laser of a shot top-shelf past
     Toronto Maple Leafs goaltender Jonathan Bernier. Larkin also
     added an assist in the 4-0 victory.
     The 19-year-old Larkin, selected in the first round (No. 15) of the
     2014 NHL Draft, became the first teenager to start a season on the
     Red Wings roster since Jiri Fischer in 1999. Then again, so much about
     Larkin's rise has been meteoric.
     He made the leap to the NHL after one season at the University of
     Michigan, where his 47 points led Big Ten rookies and placed him second
     in the nation among freshmen. Foregoing his final three years of college
     eligibility and signing a three-year entry-level contract, Larkin began
     his pro career with Grand Rapids just in time for the American Hockey
     League playoffs, where he scored three goals and five points in six games.
     In 2015-16, Larkin became the sixth rookie in Red Wings history to lead
     the team in goals (23), the first since Dale McCourt in 1979-80.
     He also had a plus-11 rating, scored five game-winning goals and
     took 221 shots on goal.
     Larkin became the first teenager since former Red Wing Steve
     Yzerman in 1984-85 to score goals in four consecutive games
     (Nov. 16-21), and he finished the month with seven goals
     and 10 points in 13 games and was named NHL Rookie of the Month.
     Invited to play at the NHL All-Star Game, Larkin participated in the
     Fastest Skater competition during All-Star Weekend and had a time of
     13.172 seconds, breaking Mike Gartner's record of 13.386.
     Gartner set the record in 1996, six months before Larkin was born. """)
Пример #12
0
rugby = Sport(name="Rugby")
session.add(rugby)

cricket = Sport(name="Cricket")
session.add(cricket)

golf = Sport(name="Golf")
session.add(golf)

tennis = Sport(name="Tennis")
session.add(tennis)

session.commit()

session.add(Player(name="Bryan Habana", dob=datetime.date(1982,1,4), sport=rugby, user=cj, photo='bryan.jpg'))
session.add(Player(name="Handre Pollard", dob=datetime.date(1982,1,4), sport=rugby, user=cj, photo='handre.jpg'))
session.add(Player(name="Duane Vermeulen", dob=datetime.date(1982,1,4), sport=rugby, user=cj, photo='duane.jpg'))

session.add(Player(name="AB de Villiers", dob=datetime.date(1982,1,4), sport=cricket, user=cj, photo='ab.jpg'))
session.add(Player(name="Hashim Amla", dob=datetime.date(1982,1,4), sport=cricket, user=cj, photo='hashim.jpg'))
session.add(Player(name="Dale Steyn", dob=datetime.date(1982,1,4), sport=cricket, user=cj, photo='dale.jpg'))
session.add(Player(name="Quinton de Kock", dob=datetime.date(1982,1,4), sport=cricket, user=cj, photo='quinton.jpg'))

session.add(Player(name="Ernie Else", dob=datetime.date(1982,1,4), sport=golf, user=cj, photo='ernie.jpg'))
session.add(Player(name="Louis Oosthuizen", dob=datetime.date(1982,1,4), sport=golf, user=cj, photo='louis.jpg'))

session.add(Player(name="Kevin Anderson", dob=datetime.date(1982,1,4), sport=tennis, user=cj, photo='kevin.jpg'))

session.commit()
Пример #13
0
DBSession = sessionmaker(bind=engine)
session = DBSession()

User1 = User(name="Andy Dusanowsky", email="*****@*****.**")
session.add(User1)
session.commit()

# Tottenham Hotspur Team
team1 = Team(name='Tottenham Hotspur', user_id=1)
session.add(team1)
session.commit()

player1 = Player(user_id=1,
                 name='Harry Kane',
                 origin='England',
                 yr_strtd='2004',
                 position='Forward',
                 team=team1)
session.add(player1)
session.commit()

player2 = Player(user_id=1,
                 name='Dele Alli',
                 origin='England',
                 yr_strtd='2015',
                 position='Mid Field',
                 team=team1)
session.add(player2)
session.commit()

player3 = Player(user_id=1,
Пример #14
0
session = DBSession()


# Create dummy user
User1 = User(name="Dennis", email="*****@*****.**",
             picture='https://lh3.googleusercontent.com/-dwDzFhtRIjU/U0imUbjLOKI/AAAAAAAABjM/pFxCccg_Nu4YZ79WzQCtEE-PRswAxgR1wCEwYBhgL/w140-h140-p/208037_1023666605893_8276_n.jpg')
session.add(User1)
session.commit()

# Reds team
team1 = Team(user_id=1, name="Reds")

session.add(team1)
session.commit()

player1 = Player(user_id=1, name="Roy Hobbs", position="Outfield",
                     games_played="145",  team=team1)

session.add(player1)
session.commit()


player2 = Player(user_id=1, name="Jake Taylor", position="Catcher",
                     games_played="115", team=team1)

session.add(player2)
session.commit()

player3 = Player(user_id=1, name="Reggie Byrd", position="Shortstop",
                     games_played="162", team=team1)

session.add(player3)
Пример #15
0
session.add(team29)
team30 = Team(name='Wizards',
              city='Washington',
              state='Washington, D.C.',
              conference='East',
              division='Southeast',
              league='NBA')
session.add(team30)
session.commit()

player1 = Player(firstName="James",
                 lastName="Harden",
                 jersey="13",
                 position="G",
                 height="6'5",
                 weight="220",
                 age="29",
                 college="Arizona State",
                 birthplace="Compton, California",
                 role="Starter",
                 team=team11)
session.add(player1)

player2 = Player(firstName="Chris",
                 lastName="Paul",
                 jersey="3",
                 position="G",
                 height="6'0",
                 weight="175",
                 age="33",
                 college="Wake Forest",
Пример #16
0
session.commit()

# Players for Golden State Warriors
team1 = Team(
    user_id=user1.id,
    name="Golden State Warriors",
    description=
    "The Golden State Warriors are an American professional basketball team based in Oakland, California"
)

session.add(team1)
session.commit()

player1 = Player(user_id=user1.id,
                 name="Stephen Curry",
                 description="Point guard",
                 salary=1137,
                 team=team1,
                 number=30)

session.add(player1)
session.commit()

player2 = Player(user_id=user1.id,
                 name="Klay Thompson",
                 description="Shooting guard",
                 salary=1550,
                 team=team1,
                 number=11)

session.add(player2)
session.commit()