def addStore(): if login_session.get('username') is None: flash("You have to be logged in order to create a store") login_session['url'] = url_for('addStore') return redirect(url_for('login')) if request.method == 'GET': if login_session.get('username') is not None: user_id = getUserId(login_session['email']) else: return redirect(url_for('login')) return render_template('addStore.html', user_id=user_id) else: user_id = getUserIdbyUsername(login_session['username']) picture = request.form['picture'] if picture == '': picture = request.form['pictureLocal'] newStore = Store(name=request.form['name'], user_id=user_id, picture=picture) if request.files is not None: upload(newStore) session.add(newStore) session.commit() return redirect(url_for('showStores'))
def addBeer(beer_name): beer = session.query(Beers).filter_by(name=beer_name).one() user = getUser(login_session['email']) local = session.query(Locals).filter_by(id=user.local_id).one() new_store = Store(beer_id=beer.id, local_id=local.id, available=True) session.add(new_store) session.commit() return showLocal(local.name)
def newStore(): if request.method == 'POST': newStore = Store(name=request.form['name'], user_id=login_session['user_id']) session.add(newStore) flash('New store %s Successfully Created' % newStore.name) session.commit() return redirect(url_for('showStores')) else: return render_template('newStore.html')
def do_POST(self): try: if self.path.endswith("/delete"): storeIDPath = self.path.split("/")[2] myStoreQuery = session.query(Store).filter_by( id=storeIDPath).first() if myStoreQuery != []: session.delete(myStoreQuery) session.commit() self.send_response(301) self.send_header('Content-type', 'text/html') self.send_header('Location', '/stores') self.end_headers() if self.path.endswith("/edit"): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) messagecontent = fields.get('newTvName') storeIDPath = self.path.split("/")[2] myStoreQuery = session.query(Store).filter_by( id=storeIDPath).one() if myStoreQuery != []: myStoreQuery.name = messagecontent[0] session.add(myStoreQuery) session.commit() self.send_response(301) self.send_header('Content-type', 'text/html') self.send_header('Location', '/stores') self.end_headers() if self.path.endswith("/stores/new"): ctype, pdict = cgi.parse_header( self.headers.getheader('content-type')) if ctype == 'multipart/form-data': fields = cgi.parse_multipart(self.rfile, pdict) messagecontent = fields.get('newStoreName') # Create new Store Object newStore = Store(name=messagecontent[0]) session.add(newStore) session.commit() self.send_response(301) self.send_header('Content-type', 'text/html') self.send_header('Location', '/stores') self.end_headers() except: pass
def newBeer(local_name): if 'email' not in login_session: return home() else: user = getUser(login_session['email']) local = session.query(Locals).filter_by(name=local_name).one_or_none() if local is None: return newLocal() print user.local_id print local.id if user.local_id == local.id: print local.name if request.method == 'POST': beers_list = session.query(Beers).all() new_beer_exists = False new_beer = Beers( name=request.form['name'], description=request.form['description'], price=request.form['price'], origin=request.form['origin'], logo=request.form['logo']) for beer in beers_list: if (new_beer.name.lower() == beer.name.lower()): new_beer_exists = True break if not new_beer_exists: session.add(new_beer) session.commit() this_beer = session.query(Beers)\ .filter_by(name=request.form['name']).one() this_local = session.query(Locals)\ .filter_by(name=local_name).one() new_store = Store( beer_id=this_beer.id, local_id=this_local.id, available=True) session.add(new_store) session.commit() return showLocal(local_name) else: return render_template('newBeer.html', local_name=local_name) else: return home()
def newStore(): session2 = DBSession() if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newStore = Store(name=request.form['name']) session2.add(newStore) session2.commit() session2.close() return redirect(url_for('showStores')) else: session2.close() return render_template('newStore.html')
def newStore(): if 'username' not in login_session: return redirect('/login') if request.method == 'POST': newStore = Store( name=request.form['name'], user_id=login_session['user_id']) session.add(newStore) flash('New Store %s has been created successfully' % newStore.name) session.commit() return redirect(url_for('home')) else: return render_template('newStore.html')
def newStore(brand_id): # Remove Oauth # if 'username' not in login_session: # return redirect('/login') brand = session.query(Brand).filter_by(id=brand_id).one() print(brand.name) if request.method == 'POST': newItem = Store(name=request.form['name'], description=request.form['description'], price=request.form['price'], brand_id=brand_id, user_id=brand.user_id) session.add(newItem) session.commit() print("new store item created!") flash("new store item created!") print() return redirect(url_for('brandMenu', brand_id=brand_id)) else: return render_template('newstore.html', brand_id=brand_id)
def newStore(): if 'username' not in login_session: return redirect('/') if request.method == 'POST': formPhoto = request.form['photo'] if formPhoto == "/static/shoe.jpg": formCategory = 'shoes' if formPhoto == "/static/sports.jpg": formCategory = 'sporting' if formPhoto == "/static/clothing.jpg": formCategory = 'clothing' newStore = Store(name=request.form['name'], user_id=login_session['user_id'], photo=formPhoto, category=formCategory) session.add(newStore) flash('New %s Store %s Successfully Created' % (newStore.category, newStore.name)) session.commit() return redirect(url_for('showStores')) else: return render_template('newStore.html')
# 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="Ollie", email="*****@*****.**", picture='https://media.licdn.com/mpr/mpr/\ shrinknp_400_400/AAEAAQAAAAAAAAe9AAAAJDY4Yjg\ 4ZjYwLTkxZTEtNDQzMi1hOWFiLTg2Y2I0YzlhODVlOQ.jpg') session.add(User1) session.commit() # Evo Gear Store store1 = Store(user_id=1, name="Evo Gear") session.add(store1) session.commit() product1 = Product(user_id=1, name="Slayer", description="Slay the mountain with the Slayer!", price="$750", size="158 - 170cm", category="boards", store=store1) session.add(product1) session.commit() product2 = Product(user_id=1, name="Genesis", description="Burton's Genesis the lightest bindings you can buy", price="$250", size="S - L", category="bindings", store=store1)
from database_setup import Store, Base, MenuItem, User engine = create_engine('sqlite:///onlinestore.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() # Create dummy user User1 = User(name="Raga", email="*****@*****.**", picture='') session.add(User1) session.commit() # Menu for UrbanBurger store1 = Store(user_id=1, name="ALL Groceries") session.add(store1) session.commit() menuItem2 = MenuItem(user_id=1, name="Roma Tomatoes", description="Fresh Red locally grown Tomatoes", price="$1.50 per lb", course="Vegetables", store=store1) session.add(menuItem2) session.commit() menuItem1 = MenuItem(user_id=1,
# 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() User1 = User(name="hema", email="*****@*****.**") store1 = Store(user_id=1, name="Joyalukas") session.add(store1) session.commit() ornament1 = Ornament(name="Gold chain", description="made with gold", price="$150", ornamenttype="Gold", store=store1) session.add(ornament1) session.commit() ornament2 = Ornament(name="Platinum Ring", description="with a letter design", price="$450",
engine = create_engine('sqlite:///itemCatalog.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) # 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() store1 = Store(name="Anna's Item Catalog") Item1 = Item( user_id=1, name="Jacket Transparent", description="Vinyl Transparent Jacket", price="$70.00", picture= "https://images-na.ssl-images-amazon.com/images/I/71XVeZYv5-L._UX679_.jpg", store=store1) session.add(Item1) session.commit() Item2 = Item( user_id=1,
# revert all of them back to the last commit by calling # session.rollback() 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() # Animals for PetCo store1 = Store(user_id=1, name="PetCo") session.add(store1) session.commit() petsItem1 = PetsItem(user_id=1, name="Johnson", description="Pomeranian", price="$2.99", pet_type="Dog", store=store1) session.add(petsItem1) session.commit() petsItem2 = PetsItem(user_id=1,
# session.rollback() session = DBSession() # Create dummy user User1 = User( name="Tim Target", email="*****@*****.**", picture= 'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png' ) session.add(User1) session.commit() # catalog for Tim's Target store1 = Store(user_id=1, name="Tim's Target", category="clothing", photo="/static/clothing.jpg") session.add(store1) session.commit() catalogItem1 = CatalogItem(user_id=1, name="Down Jacket", description="Built to stand the elements", price="$299", store=store1) session.add(catalogItem1) session.commit() catalogItem2 = CatalogItem(user_id=1,
# revert all of them back to the last commit by calling # session.rollback() session = DBSession() # Create dummy user User1 = User( name="Lance Ko", email="*****@*****.**", picture= 'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png' ) # noqa session.add(User1) session.commit() # Menu for UrbanBurger store1 = Store(user_id=1, name="Octagon Store") session.add(store1) session.commit() menuItem2 = MenuItem(user_id=1, name="Dell XPS 15 Laptop", description="Small 15-inch laptop packs powerhouse \ performance and a stunning InfinityEdge display \ with an optional touch screen", price="1000.50", product="Computer", store=store1) session.add(menuItem2) session.commit()
DBSession = sessionmaker(bind=engine) session = DBSession() userlink = """https://pbs.twimg.com/profile_images/2671170543/ 18debd694829ed78203a5a36dd364160_400x400.png""" User1 = User(name="Robo Barista", email="*****@*****.**", picture=userlink) session.add(User1) session.commit() print session.query(User).all() # American Eagle Store fashionStore1 = Store(user_id=1, name="American Eagle") session.add(fashionStore1) session.commit() FashionItem1 = FashionItem(user_id=1, name="SHOULDER TOP", price="$2.99", category="Tops", store=fashionStore1) session.add(FashionItem1) session.commit() FashionItem2 = FashionItem(user_id=1, name="OVERSIZED T-SHIRT",
# 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="David Todd", email="*****@*****.**", picture='http://code-love.com/wp-content/uploads/2015/11/logo-udacity.png') session.add(User1) session.commit() # Denali Store store1 = Store(user_id=1, name="Denali") session.add(store1) session.commit() shopItem1 = ShopItem(user_id=1, name="The Underground", description="a tour of a young slave", price="$3.59", category="Book", store=store1) session.add(shopItem1) session.commit() shopItem2 = ShopItem(user_id=1,
from database_setup import Store, Base, Tv, User engine = create_engine('sqlite:///tvcatalog.db') Base.metadata.bind = engine DBSession = sessionmaker(bind=engine) session = DBSession() #Electronic Depot catalog User1 = User(name="Johnny Guzman", email="*****@*****.**") session.add(User1) session.commit() store1 = Store(user_id=1, name="Tech World") session.add(store1) session.commit() tv1 = Tv( user_id=1, brand="Samsung", size="65", price="$4,999.99", series="Q900", description="Smart 8K UHD TV", year="2019", ) session.add(tv1)