Пример #1
0
def newTeam():
    if 'username' not in login_session:
        return redirect('/login')
    games = session.query(Game)
    if request.method == "POST":
        file = request.files['logo']
        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_logo.jpg'
        strdate = request.form['start_year'].rsplit('/', 1)
        dateObj = datetime.datetime.strptime(strdate[1], "%Y").date()
        newTeam = Team(
            name=request.form['name'],
            locallity=request.form['locallity'],
            logo=filename,
            start_year=dateObj,
            game_id=request.form['game_id'],
            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(newTeam)
        session.commit()
        flash('New Team %s Successfully Created' % newTeam.name)
        return redirect(url_for('showTeams'))
    else:
        return render_template('teams/newteam.html', games=games)
Пример #2
0
def newTeam():
    if request.method == 'POST':
        newTeam = Team(name=request.form['name'],
                       city=request.form['city'],
                       state=request.form['state'],
                       conference=request.form['conference'],
                       user_id=login_session['user_id'])
        session.add(newTeam)
        session.commit()
        return redirect(url_for('showTeams'))
    else:
        return render_template('newTeam.html')
Пример #3
0
def newTeam():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newTeam = Team(
            name=request.form['name'], user_id=login_session['user_id'])
        session.add(newTeam)
        flash('New Team %s Successfully Created' % newTeam.name)
        session.commit()
        return redirect(url_for('showTeams'))
    else:
        return render_template('newTeam.html')
Пример #4
0
def newTeam():
    """Create a new team"""
    if not checkLogin(login_session):
	flash('You must login to create a team')
	return redirect(url_for('showTeams'))

    if request.method == 'POST':
	newTeam = Team(name=request.form['name'],description=request.form['description'],user_id=login_session.get('user_id'))
	session.add(newTeam)
	flash('New Team %s Successfully Created' % newTeam.name)
	session.commit()
	return redirect(url_for('showTeams'))
    else:
	return render_template('newTeam.html',login_session=login_session)
Пример #5
0
def newTeam():
    authenticated = 'username' in login_session
    if not authenticated:
        return redirect(url_for('showLogin'))

    if request.method == 'POST':
        new_team = Team(name=request.form['title'],
                        user_id=login_session['user_id'],
                        info=request.form['info'], league_id=int(
            request.form['league']))
        session.add(new_team)
        session.commit()
        return redirect(url_for('mainPage'))
    else:
        leagues = session.query(League).all()
        return render_template('new_team.html', leagues=leagues)
Пример #6
0
def newTeamPage():
    # Ensure user is signed in
    if 'username' not in login_session:
        return redirect('/login')
    # If GET, serve form; If POST receive data, commit new team to db
    if request.method == 'POST':
        newTeam = Team(
                       city=request.form['city'],
                       name=request.form['name'],
                       conference=request.form['conference'],
                       division=request.form['division'],
                       user_id=login_session['user_id'])
        session.add(newTeam)
        session.commit()
        flash("New Team Created!")
        return redirect(url_for('mainPage'))
    else:
        return render_template('newTeam.html')
Пример #7
0
def newTeam():
    countries = session.query(Country).all()
    try:
        user = login_session['username']
    except KeyError:
        user = None
    if request.method == 'POST':
        name = request.form['name']
        if nameExists(name):
            flash("Please enter a different team. Team " +
                  name + " already exists.")
            return redirect(url_for('newItem'))
        user_id = get_user(login_session['username'])
        newTeam = Team(name,
                       request.form['description'],
                       request.form['country_id'],
                       user_id)
        session.add(newTeam)
        session.commit()
        return redirect(url_for('getIndex'))
    else:
        return render_template(
            'create.html',  countries=countries, user=user
        )
Пример #8
0
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Teams for Atlantic Division
toronto = Team(city="Toronto",
               name="Maple Leafs",
               conference="Eastern",
               division="Atlantic",
               user_id="1")
session.add(toronto)
session.commit()

montreal = Team(city="Montreal",
                name="Canadiens",
                conference="Eastern",
                division="Atlantic",
                user_id="1")
session.add(montreal)
session.commit()

ottawa = Team(city="Ottawa",
              name="Senators",
Пример #9
0
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

# Create dummy user
User1 = User(name="Rakan", email="*****@*****.**",picture='')
session.add(User1)
session.commit()


# Team 1 >> Al-Hilal FC
team1 = Team(user_id=1, name = "Al-Hilal FC ")

session.add(team1)
session.commit()


menuPlayer1 = MenuPlayer(user_id=1, name = "Carlos Eduardo", Nationality = "Brazil", number = "3", position = "Midfielder", team = team1)

session.add(menuPlayer1)
session.commit()

menuPlayer2 = MenuPlayer(user_id=1, name = "Abdulmalek Al-Khaibri", Nationality = "Saudi Arabia", number = "6", position = "Midfielder", team = team1)

session.add(menuPlayer2)
session.commit()
Пример #10
0
from database_setup import Player, Team, Base, User

engine = create_engine('sqlite:///itemcatalogwithuser.db')
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

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',
# Bind the engine to the metadata of the Base class so that the
# declaratives can be accessed through a DBSession instance
Base.metadata.bind = engine

DBSession = sessionmaker(bind=engine)
# A DBSession() instance establishes all conversations with the database
# and represents a "staging zone" for all the objects loaded into the
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
session = DBSession()

#Team Maple Leafs
team1 = Team(name="Toronto Maple Leafs")

session.add(team1)
session.commit()

playerItem1 = PlayerItem(
    name="Tyler Bozak",
    description=
    "Tyler Bozak is a Canadian professional ice hockey centre having played 400 games in the NHL",
    number="42",
    position="Centre",
    team=team1)

session.add(playerItem1)
session.commit()
Пример #12
0
# database session object. Any change made against the objects in the
# session won't be persisted into the database until you call
# session.commit(). If you're not happy about the changes, you can
# revert all of them back to the last commit by calling
# session.rollback()
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)
Пример #13
0
sample_countries = [
    'Belarus', 'Croatia', 'Spain', 'Germany', 'Hungary', 'France', 'Poland', 
    'Sweden', 'Denmark', 'Turkey', 'Portugal', 'Macedonia', 'Norway', 'Romania', 
    'Austria', 'Iceland', 'Switzerland', 'Slovenia', 'Russia', 'Ukraine'
]

for country_name in sample_countries:
    country = Country(country_name)
    session.add(country)
session.commit()

sample_teams = {
    'HC Meshkov Brest': 1, 'RK Zagreb': 2, 'Aalborg Handbold': 9,
    'HBC Nantes': 6, 'Paris Saint-Germain': 6, 'SG Flensburg-Handewitt': 4,
    'THW Kiel': 4, 'Rhein-Neckar Lowen': 4, 'Pick Szeged': 5,
    'Veszprem KSE ': 5, 'RK Vardar': 12, 'Vive Kielce': 7,
    'Wisla Plock': 7, 'RK Celje': 18, 'Barcelona': 3, 'IFK Kristianstad': 8,
    'Skjern Handbold': 9, 'Montpellier Handball': 6,
    'RK Metalutg Skopje': 12, 'Elverum Handball': 13,
    'Dinamo Bucarest': 14, 'Chekhovskiye Medvedi': 19,
    'RK Gorenje Velenje': 18, 'CB Ademar Leon': 3,
    'Kadetten Schaffhausen': 17, 'Besiktas': 10,
    'HC Motor Zaporozhye': 20, 'Alpla Hard': 15, 'Riihimaki Cocks': 16,
    'Sporting CP ': 11
}

for team_name, team_country in sample_teams.iteritems():
    team = Team(team_name, "Sample description", team_country, 1)
    session.add(team)
session.commit()
Пример #14
0
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from database_setup import Base, Team, Player, PlayerStats, Game, User

engine = create_engine('sqlite:///sports.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()

# Default NBA Teams
team1 = Team(name='Hawks',
             city='Atlanta',
             state='Georgia',
             conference='East',
             division='Southeast',
             league='NBA')
session.add(team1)
team2 = Team(name='Celtics',
             city='Boston',
             state='Massachusetts',
             conference='East',
             division='Atlantic',
             league='NBA')
session.add(team2)
team3 = Team(name='Nets',
             city='Brooklyn',
             state='New York',
             conference='East',
             division='Atlantic',
             league='NBA')
Пример #15
0
    name="Judy Wei",
    email="*****@*****.**",
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)
session.add(user1)
session.commit()

user2 = User(name="Grace Wei", email="*****@*****.**")
session.add(user2)
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()