def add(): if request.method == 'POST': newItem = Items(name=request.form['name'], description=request.form['description'], category_name=request.form['category'], user_id=login_session['user_id']) session.add(newItem) session.commit() flash("New Item %s Created!" % newItem.name) return redirect(url_for('catalog')) else: categories = session.query(Categories).all() return render_template('addItem.html', categories=categories)
def newItems(categories_id): if 'username' not in login_session: return redirect('/login') categories = session.query(Categories).filter_by(id=categories_id).one() if request.method == 'POST': newItem = Items(name=request.form['name'], description=request.form['description'], categories_id=categories_id, user_id=categories.user_id) session.add(newItem) session.commit() flash('New Menu %s Item Successfully Created' % (newItem.name)) return redirect(url_for('showMenu', categories_id=categories_id)) else: return render_template('newitems.html', categories_id=categories_id)
def additem(): if 'username' not in login_session: return redirect(url_for('catalog')) else: if request.method == 'POST': newitem = Items( name=request.form['name'], description=request.form['description'], creator_email=login_session['email'], category_id=request.form['cat']) session.add(newitem) session.commit() return redirect(url_for('catalog')) else: return render_template('additem.html')
def create_item(cat_id): if request.method == 'POST': name = request.form['item_name'] description = request.form['item_desc'] price = request.form['item_price'] user_session = login_session['username'] if name is None or description is None or price is None: print 'Missing arguments' abort(400) user_id = session.query(User).\ filter_by(username=user_session).first() item = Items(itemName=name, itemDesc=description, itemPrice=price, userID=user_id.id, catID=cat_id) session.add(item) session.commit() flash('Your item is added successfully') return redirect(url_for('showCategoryItems', cat_id=cat_id)) else: return render_template('addItem.html', cat_id=cat_id, pagename='Add item')
# 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() # items for Soccer category1 = Category(name="Soccer") session.add(category1) session.commit() Item1 = Items(name="soccer shin Gaurd", description="xzcvxzv", price="$2.99", category=category1) session.add(Item1) session.commit() Item2 = Items(name="soccer ball", description="fsgsd", price="$5.50", category=category1) session.add(Item2) session.commit() Item3 = Items(name="soccer shoes", description="scvxc", price="$3.99", category=category1)
session = DBSession() #Create first user User1 = User(name="Ankit Singh", email="[email protected]") session.add(User1) session.commit() cat = Categories(user_id=1, name="Soccor") session.add(cat) session.commit() Litem1 = Items( user_id=1, name="Shinguards", description= " A shin guard or shin pad is a piece of equipment worn on the front of a players 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 and laws of the sport or worn voluntarily by the participants for protective measures!!", categories=cat) session.add(Litem1) session.commit() Litem1 = Items( user_id=1, name="Two shinguards", description= "This technology dates back to ancient times as early as Greek and Roman Republics. Back then, shin guards were viewed as purely protective measures for warriors in battle and were made of bronze or other hard, sturdy materials. The earliest known physical proof of the technology appeared when archaeologist Sir William Temple discovered a pair of bronze greaves with a Gorgons head design in the relief on each knee capsule. After careful, proper examination it was estimated that the greaves were made in Apulia, a region in Southern Italy, around 550/500 B.C!!", categories=cat) session.add(Litem1) session.commit()
class Wishlist(): def __init__(self): self.items = Items() self.links = Links() self.reservations = Reservations() def add_item(self, name, description, image, links = None, max_reservations = 0): """Add an item to the wish list""" id = self.items.add_item(name, description, image, max_reservations) if links is not None: self.links.add_links(id, links) return id def add_reservation(self, item, amount): """ Place a reservation on an item if max_reservations number is not reached """ max_reservations = self.items.get_max_reservations(item) reserved = self.reservations.count_reservations(item) if (reserved + amount) > max_reservations: raise WishlistError('Reservation amount is too large') self.reservations.add_reservation(item, amount) def remove_reservation(self, item, amount): reserved = self.reservations.count_reservations(item) new_amount = amount if reserved == 0: return if amount > reserved: new_amount = reserved self.reservations.remove_reservation(item, new_amount) def get_reservations(self, item): return self.reservations.count_reservations(item) def get_items(self): """Returns all items""" items = self.items.get_items() for item in items: links = self.links.get_links(item['id']) item['links'] = links return items
def __init__(self): self.items = Items() self.links = Links() self.reservations = Reservations()