Beispiel #1
0
def editProduct(id):
    count = session.query(Product).count()
    if id > count:
        response = make_response(json.dumps("No Product Exists With This ID."),
                                 404)
        response.headers['Content-Type'] = 'application/json'
        return response
    elif id < 1:
        response = make_response(json.dumps("No Product Exists With This ID."),
                                 404)
        response.headers['Content-Type'] = 'application/json'
        return response
    else:
        originalProduct = session.query(Product).filter_by(id=id).one()
        updateValue = request.get_json(silent=True)
        if updateValue['name']:
            session.delete(originalProduct)
            editedProduct = Product(id=originalProduct.id,
                                    name=updateValue['name'],
                                    price=originalProduct.price)
            session.add(editedProduct)
            session.commit()
            response = make_response(json.dumps('Item Edited.'), 200)
            response.headers['Content-Type'] = 'application/json'
            return response
        elif updateValue['price']:
            session.delete(originalProduct)
            editedProduct = Product(id=originalProduct.id,
                                    name=originalProduct.name,
                                    price=updateValue['price'])
            session.add(editedProduct)
            session.commit()
            response = make_response(json.dumps('Item Edited.'), 200)
            response.headers['Content-Type'] = 'application/json'
            return response
Beispiel #2
0
def newProduct(category_id):
    """Create a new Product in selected category."""

    session = DBSession()
    category = session.query(Category).filter_by(id=category_id).one()

    if login_session['user_id'] != category.user_id:
        flash('You are not authorized to add products for category: {}. '
              'You can only Add items to the Categories you have created.'.
              format(category.name))
        session.close()
        return redirect(url_for('categoryMenu', category_id=category_id))

    if request.method == 'POST':
        newProduct = Product(name=request.form['name'],
                             category_id=category_id,
                             user_id=category.user_id)
        newProduct.description = request.form['description']
        newProduct.price = request.form['price']

        session.add(newProduct)
        session.commit()
        flash("New Product Created!")
        session.close()
        return redirect(url_for('categoryMenu', category_id=category_id))
    else:
        session.close()
        return render_template('newproduct.html', category=category)
def newProduct(supplement_id):
    if 'user_id' not in login_session:
        return redirect('/login')
    else:
        user_id = login_session['user_id']
    if request.method == 'POST':
        if 'youtube' not in request.form['videoURL']:
            videoURL = None
        else:
            videoURL = request.form['videoURL']
            if 'embed' not in videoURL:
                videoURL = videoURL.replace("watch?v=", "embed/")
            if ('www' not in videoURL or 'http' not in videoURL
                    or '.com' not in videoURL):
                videoURL = None
        newProduct = Product(
            name=request.form['name'],
            price=request.form['price'],
            manufacturer=request.form['manufacturer'],
            videoURL=videoURL,
            description=request.form['description'],
            supplement_id=supplement_id,
            user_id=user_id,
        )
        db.session.add(newProduct)
        db.session.commit()
        flash('The product %s has bee added', newProduct.name)
        return redirect(
            url_for('supplementProducts', supplement_id=supplement_id))
    else:
        return render_template('newProduct.html',
                               supplement_id=supplement_id,
                               user_id=user_id)
Beispiel #4
0
def addProduct(category_id):
    if "email" not in login_session:
        return redirect(url_for("showLogin"))
    if request.method == "GET":
        return render_template("newproduct.html", category_id=category_id)
    if request.method == "POST":
        if 'image' not in request.files:
            flash('Please upload an image for the product')
            return redirect(request.url)
        file = request.files['image']
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            flash('Please upload an image for the product')
            return redirect(request.url)
        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            imgpath = url_for('uploaded_img', filename=filename)
        newProduct = Product(name=request.form['name'],
                             description=request.form['description'],
                             price=request.form['price'],
                             category_id=category_id,
                             imgpath=imgpath,
                             user_id=login_session['gplus_id'])
        session.add(newProduct)
        session.commit()
        return redirect(url_for("listProducts"))
Beispiel #5
0
def productcreate(productcat):
        if 'username' not in login_session:
                flash("Restricted access")
                return redirect('/restaurants')
        if login_session['admin'] != 1:
                flash("Restricted access")
                return redirect('/restaurants')
        if request.method == 'POST':
                print("post")
                newItem = Product(name=request.form['name'], catagory=productcat,
id=(request.form['catcode']+request.form['id']),
                size=request.form['size'],
                material = 'stainless steel', price=request.form['price'],
polish=request.form['polish'], image=request.form['image'])
                session.add(newItem)
                session.commit()
                return redirect(url_for('productdetail', productid=newItem.id))
        else:
                print("get")
                chaf = session.query(Product).filter_by(catagory="CD")
                table = session.query(Product).filter_by(catagory="TW")
                house = session.query(Product).filter_by(catagory="HW")
                counter = session.query(Product).filter_by(catagory="CN")
                tab = session.query(Product).filter_by(catagory="TB")
                return render_template('additem.html', chaf=chaf, table=table,
house=house, counter=counter, tab=tab, productcat=productcat,
flag=2,log=2)
Beispiel #6
0
def newProduct(category_id):
    """Create a new product in one specific category."""
    if 'username' not in login_session:
        return redirect('/login')
    categories = session.query(Category).order_by(asc(Category.name))
    category = session.query(Category).filter_by(id=category_id).first()
    if login_session['user_id'] != category.user_id:
        flash('You are not authorized to add products to {} category. Please '
              'create your own category do add items.'.format(category.name))
        return redirect(url_for('newCategory'))
    if request.method == 'POST':
        newProduct = Product(name=request.form['name'],
                             description=request.form['description'],
                             price=request.form['price'],
                             picture=request.form['picture'],
                             category_id=category_id,
                             user_id=category.user_id)
        session.add(newProduct)
        flash('%s Successfully Created' % newProduct.name)
        session.commit()
        return redirect(url_for('showList', category_id=category_id))
    else:
        return render_template('newproduct.html',
                               category=category,
                               categories=categories)
Beispiel #7
0
def createProduct(shop_id):
    targetShop = session.query(Shop).filter_by(id=shop_id).one()
    if login_session['user_id'] != targetShop.owner_id:
        return jsonify("unauthorized")
    newProduct = Product(name=request.data, shop_id=shop_id, image=defImgUrl)
    session.add(newProduct)
    session.commit()
    product = session.query(Product).filter_by(name=request.data,
        shop_id=shop_id).order_by(Product.id.desc()).first()
    return jsonify(product=product.serialize)
Beispiel #8
0
def addProduct():
    """App route function to add new Product to the Product list."""
    # If user is not logged in, inform him about it and redirect
    if 'email' not in login_session:
        return redirect('/login')
    # Check if user is logged in and save the result in isLogin
    isLogin = '******' in login_session
    # All categories ordered by name
    categories = session.query(Category).order_by(Category.name).all()
    if request.method == 'POST':
        # Check if all the fields are filled out
        if request.form['name'] == '':
            flash("Please, enter product name. \
                  Make sure you fill out all the fields")
            return render_template('addproduct.html',
                                   categories=categories,
                                   isLogin=isLogin)
        if request.form['image_url'] == '':
            flash("Please, enter product image(link of the image). \
                   Make sure you fill out all the fields")
            return render_template('addproduct.html',
                                   categories=categories,
                                   isLogin=isLogin)
        if request.form['product_url'] == '':
            flash("Please, enter product URL. \
                  Make sure you fill out all the fields")
            return render_template('addproduct.html',
                                   categories=categories,
                                   isLogin=isLogin)
        if request.form['description'] == '':
            flash('Please, enter product description. \
                  Make sure you fill out all the fields')
            return render_template('addproduct.html',
                                   categories=categories,
                                   isLogin=isLogin)

        category = (session.query(Category)
                    .filter_by(name=request.form['category_name']).one())
        newProduct = Product(name=request.form['name'],
                             description=request.form['description'],
                             image_url=request.form['image_url'],
                             product_url=request.form['product_url'],
                             category_id=category.id,
                             user_id=login_session['user_id'])
        session.add(newProduct)
        session.commit()
        flash('New Product {} Successfully Created'.format(newProduct.name))
        return redirect(url_for('showCategoryProducts',
                                cat_id=newProduct.category_id))
    else:
        return render_template('addproduct.html',
                               categories=categories, isLogin=isLogin)
Beispiel #9
0
def newProduct():
    if request.method == 'POST':
        toAdd = request.get_json(silent=True)
        newProduct = Product(name=toAdd['name'], price=toAdd['price'])
        session.add(newProduct)
        session.commit()
        response = make_response(json.dumps('New Item Added.'), 200)
        response.headers['Content-Type'] = 'application/json'
        return response
    else:
        error = make_response(json.dumps("Error Adding Product"), 404)
        response.headers['Content-Type'] = 'application/json'
        return error
Beispiel #10
0
def newProduct(brand_id):
    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'POST':
        newProduct = Product(name=request.form['name'],
                             description=request.form['description'],
                             price=request.form['price'],
                             brand_id=brand_id,
                             user_id=login_session['user_id'])
        session.add(newProduct)
        session.commit()
        return redirect(url_for('showProducts', brand_id=brand_id))
    else:
        return render_template('newproduct.html', brand_id=brand_id)
Beispiel #11
0
def newProduct(order_id):
    if request.method == 'POST':
        newProduct = Product(donorId=request.form['donorId'],
                             pCode=request.form['pCode'],
                             bType=request.form['bType'],
                             pDate=request.form['pDate'],
                             pVol=request.form['pVol'],
                             order_id=order_id)
        session.add(newProduct)
        session.commit()
        return redirect(url_for('showProduct', order_id=order_id))
    else:
        return render_template('newproduct.html', order_id=order_id)

    return render_template('newproduct.html', order_id=order_id)
Beispiel #12
0
def sellProduct():
    if request.method == 'POST':
        if request.form['productName'] == '' or request.form[
                'productPrice'] == '':
            flash("Enter all details Product Name and Product Price")
        else:
            newProduct = Product(cat_id=request.form['Category'],
                                 item_id='2I',
                                 name=request.form['productName'],
                                 price=request.form['productPrice'],
                                 seller=session['email'])
            db.add(newProduct)
            db.commit()
            flash('Your Product is added')

    return redirect(url_for('sellItem'))
Beispiel #13
0
def newProductItem(catalog_id):
    if 'username' not in login_session:
        return redirect('/login')
    catalog = session.query(Catalog).filter_by(id=catalog_id).one()
    if login_session['user_id'] != catalog.user_id:
        return "<script>function myFunction() {alert('You are not authorized to add a product to this catalog. Please create your own catalog in order to add products.');}</script><body onload='myFunction()''>"
    if request.method == 'POST':
        newItem = Product(name=request.form['name'],
                          description=request.form['description'],
                          catalog_id=catalog_id,
                          user_id=catalog.user_id)
        session.add(newItem)
        session.commit()
        flash('New Product %s Item Successfully Created' % (newItem.name))
        return redirect(url_for('showProduct', catalog_id=catalog_id))
    else:
        return render_template('productsadd.html', catalog_id=catalog_id)
def newProduct(company_id):
    if 'username' not in login_session:
        flash("You need to login first before making this change")
        return redirect(url_for('/login'))
    company = session.query(Company).filter_by(id=company_id).one()
    if request.method == 'POST':
        newProduct = Product(name=request.form['name'],
                             description=request.form['description'],
                             price=request.form['price'],
                             categary=request.form['categary'],
                             company_id=company_id,
                             user_id=company.user_id)
        session.add(newProduct)
        session.commit()
        flash('New Product %s Added Successfully' % (newProduct.name))
        return redirect(url_for('showProduct', company_id=company_id))
    else:
        return render_template('newProduct.html', company_id=company_id)
Beispiel #15
0
def newProduct(name, description, price, category_id, owner_id):
    '''name description price category_id owner_id'''
    if (not name) or name.strip() == '':
        return None
    new = Product(name=name.lower(),
                  description=description,
                  price=price,
                  category_id=category_id,
                  owner_id=owner_id)
    try:
        session.add(new)
        session.commit()
        print "new product successful"
        return new
    except Exception:
        session.rollback()
        print "new product FAIL"
        return None
Beispiel #16
0
def newProduct():
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newProduct = Product(name=request.form['name'],
                             description=request.form['description'],
                             price=request.form['price'],
                             image=request.form['image'],
                             room=request.form['room'],
                             user_id=login_session['user_id'],
                             user_picture=login_session['picture'])
        room = request.form['room']
        session.add(newProduct)
        flash('New Product Added \n %s' % newProduct.name)
        session.commit()
        return redirect(url_for('showProducts', room_name=room))
    else:
        return render_template('newproduct.html', login_session=login_session)
Beispiel #17
0
def newProduct(store_id):
    store = session.query(Store).filter_by(id=store_id).one()
    if login_session['user_id'] != store.user_id:
        flash('You are not authorized to edit %s '
              'Please create your own to edit' % editStore.name)
    if request.method == 'POST':
        newItem = Product(name=request.form['name'],
                          description=request.form['description'],
                          price=request.form['price'],
                          size=request.form['size'],
                          category=request.form['category'],
                          store_id=store_id,
                          user_id=store.user_id)
        session.add(newItem)
        session.commit()
        flash('New Product %s Successfully Created' % (newItem.name))
        return redirect(url_for('showProduct', store_id=store_id))
    else:
        return render_template('newproduct.html', store_id=store_id)
Beispiel #18
0
def newProduct(brand_id):
    session6 = DBSession()
    brand = session6.query(Brand).filter_by(id=brand_id).one()
    if 'username' not in login_session:
        return redirect('/login')
    if request.method == 'POST':
        newBrand = Product(name=request.form['name'],
                           description=request.form['description'],
                           price=request.form['price'],
                           costumetype=request.form['costumetype'],
                           brand_id=brand.id,
                           user_id=brand.user_id)
        session6.add(newBrand)
        session6.commit()
        session6.close()
        return redirect(url_for('showProduct', brand_id=brand_id))
    else:
        return render_template('newProduct.html', brand_id=brand_id)

    return render_template('newProduct.html')
Beispiel #19
0
def addItem():
    categories = session.query(ProductCatagory).all()
    if request.method == 'POST':
        itemName = request.form['name']
        itemDescription = request.form['description']
        itCat = session.query(ProductCatagory).filter_by(
            name=request.form['ProductCatagory']).one()
        if itemName != '':
            print("item name %s" % itemName)
            addingItem = Product(name=itemName,
                                 description=itemDescription,
                                 ProductCatagory=itCat,
                                 user_id=login_session['user_id'])
            session.add(addingItem)
            session.commit()
            return redirect(url_for('home'))
        else:
            return render_template('addItem.html', categories=categories)
    else:
        return render_template('addItem.html', categories=categories)
Beispiel #20
0
def addProduct():
    categories = session.query(Category).order_by(asc(Category.name))

    if request.method == 'POST':
        if request.form.get('category'):
            category_id = request.form.get('category')
            category = session.query(Category).filter_by(
                id=category_id).one_or_none()
        if request.form['name']:
            newProduct = Product(name=request.form['name'],
                                 price=request.form['price'],
                                 description=request.form['description'],
                                 category=category)
            session.add(newProduct)
            session.commit()
            print("done")
            return redirect(
                url_for('specificCategory',
                        id=category_id,
                        category_name=category.name))
        else:
            return redirect(url_for('pageNotFound'))
    else:
        return render_template('addProduct.html', categories=categories)
Beispiel #21
0
def NewProduct(p_name,p_desc,p_price,p_flavour,p_path,cid,c_user_id):
    item = Product(name = p_name,description=p_desc, price=p_price, flavour=p_flavour,image=p_path,catagory_id=cid,user_id=c_user_id)
    session.add(item)
    session.commit()
Beispiel #22
0
session.add(category1)
session.commit()

category2 = Category(name="Entertainment", description="TV, Games, and other")

session.add(category2)
session.commit()

category3 = Category(name="Stationary", description="Books")

session.add(category3)
session.commit()

# Dummy Products
product1 = Product(name="Batakali", description="Shirt", price="5.23", 
			category=category1)

session.add(product1)
session.commit()

product2 = Product(name="Techno Tv", description="Television Set", 
			price="12.45", category=category2)

session.add(product2)
session.commit()

product3 = Product(name="Code Book", description="Algorithms Book",
			price="65.45", category=category3)

session.add(product3)
session.commit()
Beispiel #23
0
)  # NOQA
session.add(User1)
session.commit()

# Add suspension category
category1 = Category(user_id=1, name="Suspension")

session.add(category1)
session.commit()

# Add items in suspension category
product1 = Product(
    user_id=1,
    name="Fox Front Shocks",
    description=
    "Fox Shocks are used in off-road vehicles. Comfort and endurance in all-terrain.",  # NOQA
    price="$250.99",
    picture=
    "https://cdn3.volusion.com/sxegw.zwlry/v/vspfiles/photos/FOX-883-24-02X-2.jpg",  # NOQA
    category=category1)
session.add(product1)
session.commit()

product2 = Product(
    user_id=1,
    name="Coil Springs",
    description=
    "Restore OEM-standard handling and smoother ride to your vehicle.",  # NOQA
    price="$45.00",
    picture=
    "https://content.speedwaymotors.com/ProductImages/252512_L1600_5a117319-e7af-4420-8c42-c7bcdf6db5fd.jpg",  # NOQA
Beispiel #24
0
brand1 = Brand(name="Apple", user_id=1 )
session.add(brand1)
session.commit()

brand2 = Brand(name="Samsung", user_id=1)
session.add(brand2)
session.commit()

brand3 = Brand(name="Huawei", user_id=1)
session.add(brand3)
session.commit()

product1 = Product(name="iphone Xs", description="""The iPhone XS
    display has rounded corners that follow a beautiful curved design,
    and these corners are within a standard rectangle. When measured
    as a standard rectangular shape, the screen is 5.85 inches
    diagonally (actual viewable area is less).""", price="999$",
    brand_id=1, user_id=1)
session.add(product1)
session.commit()

product2 = Product(name="iPad Pro", description="""The iPad Pro
    is a 12.9-inch tablet with 2,732 x 2,048 pixel resolution that
    is nearly as thin (6.9mm) as the company's iPad Air while weighing
    about the same (1.59 pounds) as Apple's original
    iPad device.""", price="799$", brand_id=1, user_id=1)
session.add(product2)
session.commit()

product3 = Product(name="MacBook Pro", description="""The MacBook Pro is a
    brand of Macintosh laptop computers by Apple Inc. that merged 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()

# Menu for UrbanBurger
order1 = Order(number=1961)

session.add(order1)
session.commit()

product3 = Product(donorId="W232978115",
                   pCode="E3098",
                   bType="O Neg",
                   pDate="11/08/16",
                   pVol="222",
                   order=order1)

session.add(product3)
session.commit()

product4 = Product(donorId="W981816476",
                   pCode="E3899",
                   bType="O POS",
                   pDate="11/08/16",
                   pVol="90",
                   order=order1)

session.add(product4)
session.commit()
Beispiel #26
0
# 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="zack peterson", email="*****@*****.**")

# Products for Groceries
ProductCatagory1 = ProductCatagory(name="Groceries")

session.add(ProductCatagory1)
session.commit()

Product2 = Product(name="Tuna",
                   description="Delicious Blue Finn Tuna, extra Dolphin",
                   price="1.23",
                   ProductCatagory=ProductCatagory1,
                   user=user1)
session.add(Product2)
session.commit()

# Products for Groceries
ProductCatagory2 = ProductCatagory(name="Cleaning")

session.add(ProductCatagory2)
session.commit()

Product2 = Product(name="Mop",
                   description="cleans the toughest staines",
                   price="1.23",
                   ProductCatagory=ProductCatagory2,
Beispiel #27
0
# 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)

session.add(product2)
session.commit()


product3 = Product(user_id=1, name="Ion", description="Stiff freeride boot",
                     price="$199", size="6 - 12", category="boots", store=store1)
session.add(room1)
session.commit()

room1 = Room(name="Bathroom")
session.add(room1)
session.commit()

room1 = Room(name="Outdoor")
session.add(room1)
session.commit()

product = Product(
    name="Bunk bed frame",
    description=
    "Made of solid wood, which is a hardwearing and warm natural material.",
    price="130",
    room="Bedroom",
    image="https://goo.gl/NV3kQZ",
    user_id="1",
    user_picture="https://goo.gl/5BEJBs")
session.add(product)
session.commit()

product = Product(
    name="Bed frame",
    description=
    "16 slats of layer-glued birch adjust to your body weight and increase the suppleness of the mattress.",
    price="125",
    room="Bedroom",
    image="https://goo.gl/JfbVnd",
    user_id="1",
    email="*****@*****.**",
    picture=
    'https://pbs.twimg.com/profile_images/2671170543/18debd694829ed78203a5a36dd364160_400x400.png'
)
session.add(User2)
session.commit()

#Menu for Food
category1 = Category(user_id=2, name="Food")

session.add(category1)
session.commit()

product1 = Product(
    user_id=2,
    name="Veggie Burger",
    description="Juicy grilled veggie patty with tomato mayo and lettuce",
    price="$7.50",
    category=category1)

session.add(product1)
session.commit()

product2 = Product(
    user_id=2,
    name="Chicken Burger",
    description="Juicy grilled chicken patty with tomato mayo and lettuce",
    price="$5.50",
    category=category1)

session.add(product2)
session.commit()
Beispiel #30
0
session.commit()

#############Store 1
shop = Shop(
    name="Blair's Blankets",
    hours="9am-7pm",
    phone_number="555-7654",
    image="https://images.pexels.com/photos/90317/pexels-photo-90317.jpeg",
    owner_id=1)
session.add(shop)
session.commit()

product = Product(
    name="duvet",
    description="it is the one that goes on the bed",
    image=
    "https://cdn.pixabay.com/photo/2016/04/28/13/41/sunday-1358907__340.jpg",
    price="$36",
    shop_id=1)
session.add(product)
session.commit()

product = Product(
    name="sheet",
    description="it is white",
    image=
    "https://cdn.pixabay.com/photo/2016/01/19/17/41/bed-linen-1149842__340.jpg",
    price="$16",
    shop_id=1)
session.add(product)
session.commit()