def editSportItem(sport_item): if 'username' not in login_session: return redirect(url_for('showLogin')) sportItemToEdit = session.query(SportItem).filter_by(name=sport_item).one() if sportItemToEdit.user_id != login_session['user_id']: return "You are not authorized to edit" else: items = session.query(SportItem).filter_by(name=sport_item).one() editedSportItem = session.query(SportItem).\ filter_by(name=sport_item).one() if request.method == 'POST': if request.form['name']: editedSportItem.name = request.form['name'] if request.form['description']: editedSportItem.description = request.form['description'] if request.form['sport']: editedSportItem.sport = Sport(name=request.form['sport']) session.add(editedSportItem) session.commit() flash('Sport Item Successfully Edited %s' % editedSportItem.name) return redirect(url_for('showSports')) else: return render_template('editSportItem.html', items=items, item=editedSportItem, sport_item=sport_item)
def newSport(): if request.method == 'POST': newSport = Sport(name=request.form['name'], description=request.form[ 'description'], user_id = login_session['user_id']) session.add(newSport) session.commit() return redirect(url_for('showSports')) else: return render_template('newsport.html')
def newSport(category_name=None): if request.method == 'POST': category = None if request.form.get('sportCategory'): category = session.query(Category).filter_by( id=request.form['sportCategory'].lower()).first() if not category: category = session.query(Category).filter_by(id=1).first() if not request.form.get('sportName'): return "sportName required" sport = Sport(name=request.form.get('sportName').strip().lower(), description=request.form.get('sportDescription'), category_id=category.id, user_id=login_session['user_id']) # check if the post request has the file part # Image upload is optional if 'sportImage' not in request.files: file = None else: file = request.files['sportImage'] # if user does not select file, browser also # submit an empty part without filename if file and allowed_file(file.filename) and file.filename != '': filename = secure_filename("".join( [str(uuid.uuid4()), "_", file.filename])) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) sport.image = filename if file and file.filename == '': sport.image = '' try: session.add(sport) session.commit() except exc.IntegrityError: session.rollback() flash(u'Sport %s already exists' % sport.name, 'danger') return redirect(url_for('newSport')) flash(u'Sport %s successfully added' % sport.name, 'success') return redirect( url_for('categories', category_name=sport.category.name)) categories = session.query(Category).filter(Category.id != 1).all() return render_template('newsport.html', categories=categories, category_name=category_name, STATE=login_session.get('state'))
def newSport(): if 'username' not in login_session: return redirect('/login/') if request.method == 'POST': newSport = Sport(name=request.form['name'], user_id=login_session['user_id']) session.add(newSport) session.commit() return redirect(url_for('showSports')) else: return render_template('createSport.html')
def newSport(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newSport = Sport(name=request.form['name'], user_id=login_session['user_id']) session.add(newSport) flash('New Sport %s Successfully Created' % newSport.name) session.commit() return redirect(url_for('showSport')) else: return render_template('newSport.html')
def newSportItem(): creator = getUserInfo(Sport.user_id) if 'username' not in login_session: return redirect(url_for('showLogin')) if request.method == 'POST': # new Sport Item is added to the database newSportItem = SportItem(name=request.form['name'], description=request.form['description'], sport=Sport(name=request.form['sport']), user_id=login_session['user_id']) session.add(newSportItem) flash('New Sport Item %s Successfully Created' % newSportItem.name) session.commit() return redirect(url_for('showSports')) else: return render_template('newSportItem.html')
def newSport(): engine = create_engine('sqlite:///sportscatalog.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newSport = Sport(name=request.form['name'], username=login_session['username']) session.add(newSport) flash('New Sport %s Successfully Created' % newSport.name) session.commit() return redirect(url_for('showSports')) else: return render_template('newSport.html')
session = DBSession() # Create dummy user User1 = User( name="Robo Barista", email="*****@*****.**", picture= 'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png' ) session.add(User1) session.commit() # create categories # hi sport1 = Sport(user_id=1, name="Soccer") session.add(sport1) session.commit() item1 = Item( user_id=1, name="Ball", description="each 11 players work on shooting it into the opposite team ", sport=sport1) item1 = Latest( user_id=1, name="Ball", description="each 11 players work on shooting it into the opposite team ", sport=sport1)
Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # Create dummy user User1 = User( name="Robo Barista", email="*****@*****.**", picture='https://pbs.twimg.com/profile_images/2671170543/18debd694829e\ d78203a5a36dd364160_400x400.png') session.add(User1) session.commit() sport1 = Sport(user_id=1, name="Soccer") session.add(sport1) session.commit() menuItem1 = MenuItem( user_id=1, name="Soccer Shoes & Cleats", description=( "Firm Ground cleats are defined as cleats that are made " "typicallyfor use on natural surfaces such as dirt and grass. These " "cleats are equipped with large studs on the bottom of the " "shoe to assist in gripping the surface and preventing sliding and " "assisting in rapid directional changes."), price="$22.50", sport_item="shoe",
# revert all of them back to the last commit by calling # session.rollback() session = DBSession() # Create dummy user User1 = User( name="Savneet Singh", email="*****@*****.**", picture= 'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png' ) # noqa session.add(User1) session.commit() # Menu for Football sport1 = Sport(user_id=User1.id, name="Football") session.add(sport1) session.commit() sportItem1 = SportItem(user_id=User1.id, name="Ball", description="Leather ball, one per game.", sport=sport1) session.add(sportItem1) session.commit() sportItem2 = SportItem(user_id=User1.id, name="Gloves", description="Goalie uses gloves to protect hands.",
# 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() User1 = User(name="Adam Crenshaw", email="*****@*****.**", picture='static/blank_user.gif') session.add(User1) session.commit() # Gear for Football sport1 = Sport(user_id=1, name="Football") session.add(sport1) session.commit() gearItem1 = GearItem(user_id=1, name="Helmet", description="A piece of protective" "equipment used mainly in American football and Canadian" "football. It consists of a hard plastic shell with thick" "padding on the inside, a face mask made of one or more" "plastic-coated metal bars, and a chinstrap.", sport=sport1) session.add(gearItem1) session.commit()
# 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="Vivek Lingayat", email="*****@*****.**", picture='https://avatars1.githubusercontent.com/u/36252861') session.add(User1) session.commit() # Kit for Soccer sport1 = Sport(user_id=1, name="Soccer") session.add(sport1) session.commit() SportItem1 = SportItem( user_id=1, name="Two shinguards", description= "A shin guard or shin pad is a piece of equipment worn on the front of a player's shin to protect them from injury. These are commonly used in sports including association football, baseball, ice hockey, field hockey, lacrosse, cricket, and other sports. This is due to either being required by the rules/laws of the sport or worn voluntarily by the participants for protective measures.", sport=sport1) session.add(SportItem1) session.commit() SportItem2 = SportItem(
session.add(User1) session.commit() # Uncategorized Sports Category category0 = Category(user_id=1, name="Uncategorized") session.add(category0) session.commit() # Adventure Sports Category category1 = Category(user_id=1, name="Adventure Sports") session.add(category1) session.commit() sport1 = Sport(user_id=1, name='kayaking', description='Kayaking is the use of a kayak for moving across water. It is distinguished from canoeing by the sitting position of the paddler and the number of blades on the paddle.', image='kayaking.jpg', category=category1) session.add(sport1) session.commit() sport2 = Sport(user_id=1, name='surfing', description='Surfing is a surface water sport in which the wave rider, referred to as a surfer, rides on the forward or deep face of a moving wave, which usually carries the surfer towards the shore.', image='surfing.jpg', category=category1) session.add(sport2) session.commit() # Aquatic Sports Category category2 = Category(user_id=1, name="Aquatic Sports")
session = DBSession() session.query(Player).delete() session.commit() session.query(Sport).delete() session.commit() session.query(User).delete() session.commit() cj = User(name="CJ", email="*****@*****.**") session.add(cj) 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'))
# 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() # Create dummy user User1 = User(name="Robert Munch", email="*****@*****.**", picture='') session.add(User1) session.commit() # Whitewater kayaking sport1 = Sport(name='Whitewater Kayaking', picture='/static/img/whitewaterkayaking.jpg') session.add(sport1) session.commit() item1 = Item(sport=sport1, name='Whitewater Paddle', description=('A paddle used to propel and maneuver' ' whitewater kayaks. Primary use is for whitewater'), picture='/static/img/whitewaterpaddle.jpg', user_id=1) session.add(item1) session.commit() item2 = Item(sport=sport1,
session = DBSession() # Create dummy user User1 = User( name="Robo Barista", email="*****@*****.**", picture= 'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png' ) session.add(User1) session.commit() # Create sports equipment # SOCCER EQUIPMENT soccer = Sport(name="Soccer") session.add(soccer) session.commit() soccerCleats = Item(name="Soccer Cleats", sport=soccer, user=User1) session.add(soccerCleats) session.commit() shinguards = Item(name="Shinguards", sport=soccer, user=User1) session.add(shinguards) session.commit() soccerBall = Item(name="Soccer Ball", sport=soccer, user=User1) session.add(soccerBall) session.commit()
# 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() # SOCCER sport1 = Sport(name="Soccer") session.add(sport1) session.commit() soccer1 = Item(name="Soccer Ball", description="A ball used in the sport of Soccer or association football. The is spherical in shape and is stitched together with pentagon shaped patches of 24, 32, or 42 panels.", sport=sport1) session.add(soccer1) session.commit() soccer2 = Item(name="Shin Pads", description="Protection for your shins when playing soccer.", sport=sport1) session.add(soccer2) session.commit()