def newItem(category_name=None): """ Create a new item for category. :param category_name: (string) :return: HTML page """ session = DBSession() categories = getCategories(session) category = None if category_name: category = getCategory(category_name, session) if request.method == 'GET': return render_template('newitem.html', category=category, categories=categories) if request.method == 'POST': new_item = Item(label=bleach.clean(request.form['name']), description=bleach.clean(request.form['description']), category_id=bleach.clean(request.form['category']), user_id=login_session['user_id']) new_item = addItem(new_item, session) flash(new_item.label + " created.") if category: return redirect( url_for('CategoryItems', category_name=category.name)) return redirect(url_for('Catalog'))
def newItem(category_id): category = session.query(Category).filter_by(id=category_id).one() user_id = session.query( User.id).filter_by(gid=login_session['gplus_id']).one()[0] if category.owner_id != user_id: # Check if user is allowed to access this resource flash("You are not allowed to add items to this category.") return redirect(url_for('showItem', category_id=category_id)) if request.method == 'POST': if request.form['csrf_token'] != login_session['state']: # Cross Site Request Forgery Protection flash('CSRF Token Invalid - Please log back in.') return redirect(url_for('showCategories')) newItem = Item(name=request.form['name'], description=request.form['description'], price=request.form['price'], category_id=category_id, owner_id=user_id) session.add(newItem) session.commit() flash('New Menu %s Item Successfully Created' % (newItem.name)) return redirect(url_for('showItem', category_id=category_id)) else: return render_template('newItem.html', category_id=category_id, user=login_session, csrf=login_session['state'])
def create_item(): error = False try: name = request.form.get('name', '') temp_category_name = request.form.get('category_name') new_category_name = ','.join(temp_category_name) new_origin_price = request.form.get('origin_price', '') new_sale_price = request.form.get('sale_price', '') new_count = request.form.get('count', '') category = Category.query.filter( Category.id == new_category_name[0]).one_or_none().format() id = category['id'] new_item = Item(name=name, category_id=id, origin_price=new_origin_price, sale_pric=new_sale_price, count=new_count) new_item.insert() except: error = True finally: return redirect(url_for('home'))
def newItemF(category_id): if 'email' not in login_session: return redirect('/login') categories = session.query(Category).filter_by(id=category_id).one() items = session.query(Item).filter_by(category_id=category_id).all() user = getUserInfo(getUserID(login_session['email'])) if request.method == 'POST': newI = Item(name=request.form['name'], nutrients=request.form['nutrients'], price=request.form['price'], weight=request.form['weight'], user_id=user.id, category_id=category_id) session.add(newI) session.commit() return redirect(url_for('showItems', category_id=categories.id)) flash('New item has been added successfully.') else: return render_template('newItem.html', category_id=category_id, categories=categories, items=items)
role='admin') session.add(User1) session.commit() # Create dummy categories and items # Items for Action category1 = Category(name="Action") session.add(category1) session.commit() item1 = Item( title="Counter-Strike: Global Ofensive", description= "Counter-Strike: Global Offensive (CS: GO) will expand upon the team-based action gameplay that it pioneered when it was launched 14 years ago. CS: GO features new maps, characters, and weapons and delivers updated versions of the classic CS content (de_dust, etc.).", picture= "http://cdn.akamai.steamstatic.com/steam/apps/730/header.jpg?t=1440086526", price='$10.99', category=category1, user_id=1) session.add(item1) session.commit() item2 = Item( title="Satellite Reign", description= "Satellite Reign is a real-time, class-based strategy game, set in an open-world cyberpunk city. You command a group of 4 agents through rain-soaked, neon-lit streets, where the law is the will of mega-corporations.", picture= "http://cdn.akamai.steamstatic.com/steam/apps/268870/header.jpg?t=1440745532", price='$22.39',
session.add(C2) session.commit() C3 = Category(name="Japan") session.add(C3) session.commit() C4 = Category(name="Home") session.add(C4) session.commit() C5 = Category(name="Dogs") session.add(C5) session.commit() # Add items I1 = Item(name="buster", label="Buster", description="A real rascal.", category_id=1, user_id=1) session.add(I1) session.commit() I2 = Item( name= "that place with a really long name that might break japan as we know it", label= "That place with a really long name that might break japan as we know it", description="Ramen here.", category_id=3, user_id=1) session.add(I2) session.commit() I3 = Item(name="mr. kitty",
category1 = Category(user_id=1, name="Meat", description="Meat is animal flesh that is eaten as " "food. Humans have hunted and killed " "animals for meat since prehistoric times. " "The advent of civilization allowed the " "domestication of animals such as " "chickens, sheep, rabbits, pigs and cattle.") session.add(category1) session.commit() item1 = Item(user_id=1, name="Bacon", nutrients="One 10-g slice of cooked side bacon contains 4.5 g " "of fat, 3.0 g of protein, and 205 mg of sodium.", price="$7.50", weight="100 grams", category=category1) session.add(item1) session.commit() item2 = Item(user_id=1, name="Chicken Breasts", nutrients="A whole chicken breast with skin provides 366 " "calories, 55 grams of protein, 0 grams of " "carbohydrate, 14 grams of fat, 4 grams of saturated " "fat and 132 milligrams of sodium.", price="$12.99", weight="500 grams",
category_kitchen = Category(name="Kitchen", owner_id=1) category_livingroom = Category(name="Living Room", owner_id=1) category_decorations = Category(name="Decorations", owner_id=1) category_bathroom = Category(name="Bathroom", owner_id=1) session.add(category_office) session.add(category_bedroom) session.add(category_kitchen) session.add(category_livingroom) session.add(category_decorations) session.add(category_bathroom) # Office Items item_office_1 = Item(name="Mahogany Office Desk", description=("Fantastic solid mahogany desk. " "200cm x 100cm x 60cm"), price="1500.00", category=category_office, owner_id=1) item_office_2 = Item(name="Ergonomic Office Chair", description="Very comfortable office chair," " made by ergonomic experts in Italy.", price="199.99", category=category_office, owner_id=1) session.add(item_office_1) session.add(item_office_2) # Bedroom Items item_bedroom_1 = Item(name="Kingsize Royal Bed", description="A bed worthy of the royalty!", price="3999.99",