Ejemplo n.º 1
0
def newProduct():
    if 'username' not in login_session:
        flash('Please Login to create new item')
        return redirect('/login')

    if request.method == 'POST':
        user = session.query(User).filter_by(name=login_session['username'].encode('ascii','ignore')).one()
        try:
            cat = session.query(Categories).filter_by(
                name=str(request.form['category']).strip().encode('ascii','ignore')).one()
        except:
            new_cat = Categories(name=request.form['category'].strip().encode('ascii','ignore'))
            session.add(new_cat)
            session.commit()
            cat = session.query(Categories).filter_by(
                name=str(request.form['category']).strip().encode('ascii','ignore')).one()
            pass
        P = Products(name=str(request.form['name']).strip().encode('ascii','ignore'), cat_id=cat.id,
                     category=str(request.form['category']).strip().encode('ascii','ignore'),
                     desc=str(request.form['description']).strip().encode('ascii','ignore'), user_id=user.id,
                     img=str(request.form['img']).encode('ascii','ignore'), url=str(request.form['url']).encode('ascii','ignore'))
        session.add(P)
        session.commit()
        return redirect('/catalog')
    else:
        return render_template('new_product.html')
Ejemplo n.º 2
0
def newProduct():
    if request.method == 'POST':  # POST creates a new product
        productName = request.form.get('txtName')
        category = request.form.get('selCategory')
        price = request.form.get('txtPrice')
        description = request.form.get('txtDescription')
        checkUserCategory = session.query(Category).filter_by(
                            id=category, user_id=login_session['id']
                            ).first()
        if checkUserCategory is not None:
            newProduct = Products(name=productName, price=price,
                                  description=description,
                                  category_id=category,
                                  user_id=login_session['id'])
            session.add(newProduct)
            session.commit()
            flash('Product "'+newProduct.name+'" added to catalog.')
            categories = session.query(Category).all()
            product = session.query(Products).filter_by(
                      id=newProduct.id).join(Category).first()
            returnURL = '''/catalog/{0}/{1}/{2}/view'''
            return redirect(returnURL.format(product.category.name,
                            product.name, product.id))
            # Formats URL and redirects to newly created product page
        else:
            # unauthorised access of any kind [url manipulation, xss attacks]
            # will be redirected to 404 handler """
            return redirect('404')
    else:
        # GET displays the UI page to create new product
        categories = session.query(Category).filter_by(
                     user_id=login_session['id']).all()
        return render_template('_add-product.html', categories=categories)
Ejemplo n.º 3
0
def add_product():
    """
    Handler for the add_product page.

    Args:
        None

    GET: Render the new_product.html template.

    POST: Create a new product based on the form input and add it to the
    database. Then redirect to /catalog.
    """

    if 'username' not in login_session:
        return redirect('/login')

    if request.method == 'POST':
        session = DBSession()
        new_product = Products(name=request.form['name'],
                               description=request.form['description'],
                               price_cents=int(request.form['price']) * 100,
                               created_by=login_session['user_id'])
        session.add(new_product)
        session.commit()
        flash('New Item %s Successfully Created' % new_product.name)
        return redirect(url_for('catalog'))
    else:
        return render_template('new_product.html')
Ejemplo n.º 4
0
def newProducts():
    if request.method == 'POST':
        newProducts = Products(name=request.form['name'])
        session.add(newProducts)
        session.commit()
        return redirect(url_for('showProducts'))
    else:
        return render_template('newProducts.html')
Ejemplo n.º 5
0
def newProduct(category_id):
    category = session.query(Categories).filter_by(id=category_id).one()
    if 'username' not in login_session:
        return render_template("not_auth.html")
    if request.method == 'POST':
        newprod = Products(name=request.form['prodname'],
                           description=request.form['proddesc'],
                           category_id=category_id)
        session.add(newprod)
        session.commit()
        flash("New Product Created!")
        return redirect(url_for('showProducts', category_id=category_id))
    else:
        return render_template("newproduct.html", category_id=category_id)
Ejemplo n.º 6
0
def addProduct(donors_id):
	currentdonor = session.query(Donors).filter_by(id=donors_id).one()
	if request.method == 'POST':
		newProduct = Products(
			bcode=request.form['bcode'],
			product_code=request.form['product_code'],
			type=request.form['type'],
			exp_date=request.form['exp_date'],
			donors_id=donors_id
			)
		session.add(newProduct)
		session.commit()
		return redirect(url_for('historyDonors', donors_id=donors_id))
	else:
		return render_template('addproduct.html',currentdonor=currentdonor, donors_id=donors_id)
Ejemplo n.º 7
0
def admin():
    user = session.query(User).all()
    products = session.query(Products).all()
    if request.method == 'POST':
        name = request.form['name']
        category = request.form['category']
        thits = 0
        uhits = 0

        newProduct = Products(name = name, category = category, thits = thits, uhits = uhits)
        session.add(newProduct)
        session.commit()

        flash("Successfully added "+name+" into "+category+" category!")
        return redirect(url_for('admin'))

    return render_template('admin.html', user = user, products = products)
Ejemplo n.º 8
0
def addProducts(uToken):
	if request.method == 'POST':
		if request.form['name']=="":
			return jsonify({'message':'Please enter the product name'})
		if request.form['id']=="":
			return jsonify({'message':'Please enter the product ID'})
		try:
			newProduct = Products(name = request.form['name'], id = request.form['id'], description = request.form['description'],
				price=request.form['price'], size=request.form['size'], brand=request.form['brand'], color=request.form['color'])
			session.add(newProduct)
			session.commit()
		except:
			return jsonify({'message':'There is a problem with inserting data to the database.'})
		
		return redirect(url_for('showProducts'))
	else:
		return render_template('addProducts.html', userToken=uToken)
Ejemplo n.º 9
0
def AddProduct(category_id, subcategory_id):
    """ Adds product under subcategory list,
        user need to be signin to perform this action.
        if the input is empty return the template for input """
    if 'username' not in login_session:
        return redirect(url_for('showLogin'))
    prodid = session.query(ProductType).filter_by(
        category_id=category_id, ProductTypeID=subcategory_id).one()
    if request.method == 'POST':
        addnew = Products(ProductName=request.form['name'],
                          ProductDescription=request.form['description'],
                          product_id=prodid.ProductTypeID,
                          user_id=login_session['user_id'])
        session.add(addnew)
        session.commit()
        flash('new item is added')
        return redirect(
            url_for('ProductList',
                    category_id=category_id,
                    subcategory_id=subcategory_id))
    else:
        return render_template('AddProduct.html',
                               category_id=category_id,
                               subcategory_id=subcategory_id)
Ejemplo n.º 10
0
for line in content:
    details = line.split(":::")
    ch = ['#', '=', '-', '+']
    if any(ext not in details[0] for ext in ch):
        reviewers = details[5].split(">>>")
        reviews = details[6].split("<<<")
        fir = details[0].find("\"")
        if fir != "-1":
            name = details[0][0:fir]
        try:
            cat = session.query(Categories).filter_by(
                name=details[2].strip()).one()
            P = Products(name=name.strip(),
                         cat_id=cat.id,
                         category=details[2].strip(),
                         desc=details[3].strip(),
                         user_id=uid,
                         img=details[4],
                         url=details[7])
            session.add(P)
            session.commit()
        except:
            new_cat = Categories(name=details[2].strip())
            session.add(new_cat)
            session.commit()
            cat = session.query(Categories).filter_by(
                name=details[2].strip()).one()
            P = Products(name=name.strip(),
                         cat_id=cat.id,
                         category=details[2].strip(),
                         desc=details[3].strip(),
Ejemplo n.º 11
0
SubSubCat3 = Categories(name="Balls", parent_id=SubCat9.id)
session.add(SubSubCat3)
session.commit()

SubSubCat4 = Categories(name="Resin", parent_id=SubCat9.id)
session.add(SubSubCat4)
session.commit()

SubSubCat5 = Categories(name="Handball Shoes", parent_id=SubCat9.id)
session.add(SubSubCat5)
session.commit()

# Products
Pd1 = Products(name="Black T-Shirt",
               description="It's a black T-Shirt",
               price_cents=2999,
               creator=User1)
session.add(Pd1)
session.commit()

Pd2 = Products(name="Blue T-Shirt",
               description="It's a blue T-Shirt",
               price_cents=3999,
               creator=User2)
session.add(Pd2)
session.commit()

Pd3 = Products(name="Long Pants",
               description="These pants are long",
               price_cents=3999,
               creator=User1)
Ejemplo n.º 12
0
# 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()

#----------Store items----------------

# Polo_Shirt

storeProduct1 = Products(name="Polo Shirt1",
                         id="PS1",
                         description="Some polo type shirt",
                         price=10,
                         size="M",
                         brand="Nautica",
                         color="Navy")

session.add(storeProduct1)
session.commit()

storeProduct2 = Products(name="Polo Shirt2",
                         id="PS2",
                         description="Some polo type shirt",
                         price=12,
                         size="L",
                         brand="Nike",
                         color="White")
Ejemplo n.º 13
0
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()


#----------Store items----------------

# Polo_Shirt

storeProduct1 = Products(name="IZOD Polo Shirt", id = "IZD_PS", description = "IZOD polo type shirt", 
                     price = 25, size = "M", brand = "IZOD", color = "Navy" )

session.add(storeProduct1)
session.commit()

storeProduct2 = Products(name="Nautica Polo Shirt", id = "NTA_PS", description = "Nautica polo type shirt", 
                     price = 30, size = "L", brand = "Nautica", color = "White" )

session.add(storeProduct2)
session.commit()

storeProduct3 = Products(name="Levis 505 Jeans", id = "LVS_BJ", description = "Levis 505 jeans", 
                     price = 40, size = "32x32", brand = "Levis", color = "Midnight Blue" )

session.add(storeProduct3)
session.commit()
Ejemplo n.º 14
0
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()


#----------Store items----------------

# Polo_Shirt

storeProduct1 = Products(name="Polo Shirt", id = "PS1", description = "Some polo type shirt", 
                     price = 10, size = "M", brand = "Nautica", color = "Navy" )

session.add(storeProduct1)
session.commit()

storeProduct2 = Products(name="Denim Jeans", id = "PS2", description = "Some denim jeans", 
                     price = 20, size = "32x32", brand = "GAP", color = "Blue" )

session.add(storeProduct2)
session.commit()





#-------------------Users Registration--------------------------