def newSports(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newSports = Sports(name=request.form['name'], user_id=login_session['user_id']) session.add(newSports) flash('New Sports %s Successfully Created' % newSports.name) session.commit() return redirect(url_for('showSports')) else: return render_template('newSports.html', login_session=login_session)
def addsports(): # If user has not logged in, redirect him to login.html if 'username' not in login_session: return render_template("login.html") elif request.method == "GET": return render_template("addnewsports.html") else: newSports = Sports(name=request.form['newsports'], user_id=login_session['user_id']) session.add(newSports) session.commit() return redirect(url_for('itemHome'))
def newSports(): """This def will check the user and create a new sport under the username""" if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newSports = Sports(name=request.form['name'], user_id=login_session['user_id']) session.add(newSports) flash('New Sport %s Successfully Created' % newSports.name) session.commit() return redirect(url_for('showSports')) else: return render_template(TEMPLATE_PATH + 'newSports.html')
engine = create_engine('sqlite:///itemcatalog.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() User1 = User(name='zhijun kong', email='*****@*****.**') session.add(User1) session.commit() sports1 = Sports(user_id=1, name='Ping Pong') session.add(sports1) session.commit() equipment1 = Equipment(user_id=1, name='Paddle', description='''Players are equipped with a laminated wooden racket covered with rubber on one or two sides depending on the grip of the player. The ITTF uses the term "racket", though "bat" is common in Britain, and "paddle" in the U.S. The wooden portion of the racket, often referred to as the "blade", commonly features anywhere between one and seven plies of wood, though cork, glass fiber, carbon fiber, aluminum fiber, and Kevlar are sometimes used. According to the ITTF regulations, at least 85% of the blade by thickness shall be of natural wood. Common wood types include balsa, limba, and cypress or "hinoki," which is popular in Japan. The average size of the blade is about 6.5 inches (17 cm) long and 6 inches (15 cm) wide. Although the official restrictions only focus on the flatness and rigidness of the blade itself, these dimensions are optimal for most play styles.\nTable tennis regulations allow different surfaces on each side of the racket. Various types of surfaces provide various levels of spin or speed, and in some cases they nullify spin. For example, a player may have a rubber that provides much spin on one side of his racket, and one that provides no spin on the other. By flipping the racket in play, different types of returns are possible. To help a player distinguish between the rubber used by his opposing player, international rules specify that one side must be red while the other side must be black. The player has the right to inspect his opponent's racket before a match to see the type of rubber used and what colour it is. Despite high speed play and rapid exchanges, a player can see clearly what side of the racket was used to hit the ball. Current rules state that, unless damaged in play, the racket cannot be exchanged for another racket at any time during a match.''', sports=sports1) session.add(equipment1) session.commit() equipment2 = Equipment(user_id=1, name='Ball', description='The international rules specify that the game is played with a sphere having a mass of 2.7 grams (0.095 oz) and a diameter of 40 millimetres (1.57 in).The rules say that the ball shall bounce up 24-26 cm (9.4-10.2 in) when dropped from a height of 30.5 cm (12.0 in) onto a standard steel block thereby having a coefficient of restitution of 0.89 to 0.92. The ball is made of celluloid or similar plastic material, colored white or orange, with a matte finish. The choice of ball color is made according to the table color and its surroundings. For example, a white ball is easier to see on a green or blue table than it is on a grey table. Manufacturers often indicate the quality of the ball with a star rating system, usually from one to three, three being the highest grade. As this system is not standard across manufacturers, the only way a ball may be used in official competition is upon ITTF approval (the ITTF approval can be seen printed on the ball). \nThe 40 mm ball was introduced after the 2000 Summer Olympics. However, this created some controversy at the time as the Chinese National Team argued that this was merely to give non-Chinese players a better chance of winning since the new type of ball has a slower speed (a 40 mm table tennis ball is slower and spins less than the original 38 mm one, and at that time, most Chinese players were playing with fast attack and smashes). China won all four Olympic gold medals and three silvers in 2000, and have continued to dominate.', sports=sports1) session.add(equipment2) session.commit()
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() games = [ "Soccer", "Basketball", "Baseball", "Frisbee", "Snowboarding", "Rock Climbing", "Foosball", "Skating", "Hockey" ] # Menu for UrbanBurger for game in games: sport1 = Sports(name=game) session.add(sport1) session.commit() def sports_names(): menu = session.query(Sports).all() for value in menu: print value.name sports_names()
from database_setup import Sports, User, Base, SportsPlayer engine = create_engine('sqlite:///sports.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # Create dummy user User1 = User(name="Saurabh Jain", email="*****@*****.**", picture='https://pbs.twimg.com/profile_images/86150240' '4952567810/FRwmKg6R_400x400.jpg') session.add(User1) session.commit() # Sports Badminton sports1 = Sports(user_id=1, name="Badminton") session.add(sports1) session.commit() sportsplayer1 = SportsPlayer(user_id=1, name="Viktor AXELSEN", description="Viktor Axelsen " "(born January 4, 1994) is " "a Danish badminton player and the current" " men's singles world champion. He was the 2010" " World Junior Champion, beating " "Korea's Kang Ji-wook in the " "final to become the first ever European player" "to hold the title. In 2011, he lost the world " "junior title to Malaysia's Zulfadli Zulkiffli," "coming in second place. In "