def contact_us():
    command = """ SELECT name, deptPhone, deptLine, deptMang
                  FROM category """
    cursor.execute(command)
    phone_numbers = cursor.fetchall()

    return render_template('contact.html', categories=phone_numbers)
Ejemplo n.º 2
0
def dropdown_search():
	command = """ SELECT name
				  FROM category"""
	cursor.execute(command)
	dropdown_category = cursor.fetchall()

	return (dropdown_category)
def categories():
    command = """SELECT {a}.id, {a}.name
                      FROM {a} 
              """.format(a='category')
    cursor.execute(command)
    category_data = cursor.fetchall()

    return render_template('categories.html', my_list=category_data)
def category(key):
    command = """ SELECT *
                    FROM category
                    WHERE category.id = {p1}
            """.format(p1=key)
    cursor.execute(command)
    category_name = cursor.fetchall()[0][1]

    command = """SELECT {a}.id, {a}.brand, {a}.name, {a}.price, {b}.name, {a}.image
                      FROM {a} join {b} ON {a}.category_id = {b}.id
                      WHERE {a}.category_id = {p1}
        """.format(a="product", b='category', p1=key)
    cursor.execute(command)
    product_data = cursor.fetchall()

    return render_template('category.html', category_id=key, category_name=category_name,
                           my_list=product_data)
Ejemplo n.º 5
0
def tck():
    command = """SELECT {a}.id, {a}.name, {a}.value, {b}.name
                      FROM {a} join {b} ON {a}.category_id = {b}.id
        """.format(a="tics", b='category')
    cursor.execute(command)
    astro_data = cursor.fetchall()

    return render_template('ticket.html', my_list=astro_data)
Ejemplo n.º 6
0
def tickets():
    command = """SELECT {a}.id, {a}.issue, {b}.issue
                      FROM {a} join {b} ON {a}.risk_id = {b}.id
        """.format(a="ticket", b='risks')
    cursor.execute(command)
    ticket_data = cursor.fetchall()

    return render_template('ticket.html', my_list=ticket_data)
def product_search():
    # All the arguments
    name = request.args.get('name')
    price = request.args.get('price')
    price_greater_equal = request.args.get('price_ge')
    price_smaller_equal = request.args.get('price_se')
    category = request.args.get('category')
    brand = request.args.get('brand')
    year = request.args.get('year')
    rating = request.args.get('rating')
    stock = request.args.get('stock')
    # Creates the argument for each varibale from above
    condition = ""
    if name != None:
        condition += "product.name LIKE '%" + name + "%'"
    if price != None:
        if condition != "":
            condition += " AND "
        condition += "product.price=" + str(price)
    if category != None:
        if condition != "":
            condition += " AND "
        condition += "category.name LIKE '%" + category + "%'"
    if brand != None:
        if condition != "":
            condition += " AND "
        condition += "product.brand LIKE '%" + brand + "%'"
    if price_greater_equal != None:
        if condition != "":
            condition += " AND "
        condition += "product.price >= " + str(price_greater_equal)
    if price_smaller_equal != None:
        if condition != "":
            condition += " AND "
        condition += "product.price <= " + str(price_smaller_equal)

        # Creates the query from the DB
    if condition == "":
        command = """SELECT {a}.id, {a}.brand, {a}.name, {a}.price, {b}.name, {a}.image
                          FROM {a} 
                          JOIN {b} 
                          ON {a}.category_id = {b}.id
            """.format(a="product", b='category')
    else:
        command = """SELECT {a}.id, {a}.brand, {a}.name, {a}.price, {b}.name, {a}.image
                          FROM {a} 
                          JOIN {b} 
                          ON {a}.category_id = {b}.id
                          WHERE {cond}
            """.format(a="product", b='category', cond=condition)
    # Executes either command depending on the search type
    cursor.execute(command)
    product_data = cursor.fetchall()
    # When user hits submit on search it will render template with the returned searches
    return render_template('products.html', my_list=product_data)
def products():
    # selects all product.id,name,price and category.name
    command = """SELECT {a}.id, {a}.brand, {a}.name, {a}.price, {b}.name, {a}.image
	             FROM {a} 
                 JOIN {b} 
                 ON {a}.category_id = {b}.id
	    """.format(a="product", b='category')
    cursor.execute(command)
    product_data = cursor.fetchall()
    # takes 'command' and renders the template products.html
    return render_template('products.html', my_list=product_data)
def addToCart(item_map):
    if len(item_map) > 0:
        condition = buildCondition(item_map)
        quantityList = buildQuantityList(item_map)
        command = """ SELECT {a}.id, {a}.brand, {a}.name, {a}.price, {a}.image
                  FROM {a} WHERE {b}""".format(a='product', b=condition)
        cursor.execute(command)
        cart_data = cursor.fetchall()
        session['cart_data'] = cart_data
        session['quantityList'] = quantityList
        return redirect(url_for('my_view.cart'))
    return render_template('cart.html')
Ejemplo n.º 10
0
def register_page():
    try:
        form = RegistrationForm(request.form)
        if request.method == "POST" and form.validate():
            username  = form.username.data
            email = form.email.data
            salt = '@uI2Gg3ezB0o0o!i!@'
            password = sha256_crypt.encrypt((str(form.password.data)+salt))

            username_query = cursor.execute("SELECT user_username FROM registered_users WHERE user_username = (?)", (username,))
            username_check = cursor.fetchall()
            print (username_check) # prints a list

            email_query = cursor.execute("SELECT user_email FROM registered_users WHERE user_email = (?)", (email,))
            email_check = cursor.fetchall()
            print (email_check) # prints a list

            if len(username_check) > 0:
                flash("Sorry that username is already taken, please choose another!")
                return render_template('register.html', form=form)

            if len(email_check) > 0:
                flash('That email is already associated with another account, please use another!')
                return render_template('register.html', form=form)

            else:
                cursor.execute("INSERT INTO registered_users (user_email, user_username, user_hash) VALUES (?, ?, ?)", ((email), (username), (password)))
                conn.commit()
                flash("Thanks for registering, {u}!".format(u=username))

                session['logged_in'] = True
                session['username'] = username

                return redirect(url_for('my_view.home'))

    except Exception as e:
        logging.error(error_handling())
        
    return render_template("register.html", form=form)
def product(key):
    # selects all columns shown
    command = """SELECT {a}.id, {a}.name, {a}.price, {b}.name, {a}.image, {a}.stock, {a}.description
                      FROM {a} 
                      JOIN {b} 
                      ON {a}.category_id = {b}.id
                      WHERE {a}.id = {p1}
        """.format(a="product", b='category', p1=key)
    cursor.execute(command)
    # fetches all the columns from the command variable
    product_data = cursor.fetchall()
    # if the len of product_data DB is too long it will show error
    if len(product_data) == 0:
        flash('Key not found, please try again!')
    item = product_data[0]
    # renders template to show a single product
    return render_template('product.html', single_product=item, key=key)