Пример #1
0
def create_employee():

    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')

    # employeeNumber = dao.get_next_employee_number(conn)

    employeeNumber = request.form.get('employeeNumber')
    print('employeeNumber: ', employeeNumber)
    lastName = request.form.get('lastName')
    firstName = request.form.get('firstName')
    extension = request.form.get('extension')
    email = request.form.get('email')
    officeCode = request.form.get('officeCode')
    reportsTo = request.form.get('reportsTo')
    jobTitle = request.form.get('jobTitle')

    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')

    dao.new_employee(conn, employeeNumber, lastName, firstName, extension,
                     email, officeCode, reportsTo, jobTitle)

    conn.commit()

    return redirect(url_for('display_employees'))
Пример #2
0
def show_employees(office_code):

    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')
    cursor = dao.get_employees(conn, office_code)

    return render_template('employees.html', cursor=cursor)
Пример #3
0
def index():

    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')
    cursor = dao.get_offices(conn)

    return render_template('index.template.html', cursor=cursor)
Пример #4
0
def process_create_product():
    # extract out all the variables from the form
    product_code = request.form.get('productCode')
    product_name = request.form.get('productName')
    product_line = request.form.get('productLine')
    product_vendor = "default vendor"
    product_scale = 100
    product_description = "Desc"
    quantity_in_stock = 10
    buy_price = 19.99
    MSRP = 25.00

    # prepare the SQL
    sql = f"""
        insert into `products` (`productCode`, `productName`, `productLine`, `productScale`, `productVendor`, `productDescription`, `quantityInStock`, `buyPrice`, `MSRP`)
        VALUES
            ('{product_code}', '{product_name}', '{product_line}',
            '{product_scale}', '{product_vendor}','{product_description}', '{quantity_in_stock}', '{buy_price}', '{MSRP}'  )
    """

    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '', 'classicmodels')
    cursor = data.create_cursor(conn)
    cursor.execute(sql)
    conn.commit()
    return redirect(url_for('search'))
Пример #5
0
def index():
    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '', 'classicmodels')
    cursor = data.create_cursor(conn)
    cursor.execute("""
        select * from `products`
    """)
    return render_template('index.template.html', cursor=cursor)
Пример #6
0
def search():
    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')
    product_line_cursor = data.get_product_lines(conn)

    # create the query
    sql = """select * from `products` where 1"""

    # we use request.args to get whatever is in the query string
    selected_product_line = request.args.get('selected_product_line')
    if selected_product_line:
        print("Filtering by", selected_product_line)
        sql = sql + f" and `productLine` = '{selected_product_line}'"

    search_terms = request.args.get('search-by')
    # if search_terms is not None
    if search_terms:
        sql = sql + f" and `productName` like '%{search_terms}%'"

    products_cursor = data.create_cursor(conn)
    products_cursor.execute(sql)

    return render_template('search.template.html',
                           product_lines=product_line_cursor,
                           products=products_cursor,
                           sql=sql)
Пример #7
0
def display_offices():

    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')

    cursor_offices = dao.get_offices(conn)

    return render_template('offices.html', cursor_offices=cursor_offices)
Пример #8
0
def create_employee_form():
    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')

    cursor_cty = dao.get_office_code_country(conn)
    cursor_rpt_to = dao.get_reports_to(conn)

    return render_template('create_employee_form.html',
                           cursor_cty=cursor_cty,
                           cursor_rpt_to=cursor_rpt_to)
Пример #9
0
def create_office():

    officeCode = request.form.get('officeCode')
    city = request.form.get('city')
    phone = request.form.get('phone')
    addressLine1 = request.form.get('addressLine1')
    addressLine2 = request.form.get('addressLine2')
    state = request.form.get('state')
    country = request.form.get('country')
    postalCode = request.form.get('postalCode')
    territory = request.form.get('territory')

    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')

    dao.new_offices(conn, officeCode, city, phone, addressLine1, addressLine2,
                    state, country, postalCode, territory)

    return redirect(url_for('display_offices'))
Пример #10
0
def display_employees():

    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                               'classicmodels')

    # get the SQL data for selecting employees first name/last name at dropdown
    cursor_fn = dao.get_employees_fn(conn)
    cursor_ln = dao.get_employees_ln(conn)
    cursor_ct = dao.get_employees_ct(conn)
    cursor_jt = dao.get_employees_jt(conn)

    # get user input at dropdown for firstname and lastname when user submit via button
    user_input_fn = ""
    user_input_ln = ""
    user_input_ct = ""
    user_input_jt = ""

    if request.method == 'POST':
        user_input_fn = request.form.get('firstName')
        user_input_ln = request.form.get('lastName')
        user_input_ct = request.form.get('country')
        user_input_jt = request.form.get('jobTitle')

    # get SQL data for table with filters to display on employees_only.html
    cursor = dao.get_employees_filtered(conn, user_input_fn, user_input_ln,
                                        user_input_ct, user_input_jt)
    saved_list = list(cursor)
    # print('--------hello------')
    # print(saved_list)

    return render_template('employees_only.html',
                           saved_list=saved_list,
                           cursor_fn=cursor_fn,
                           cursor_ln=cursor_ln,
                           cursor_ct=cursor_ct,
                           cursor_jt=cursor_jt)
import data
import os

conn = data.get_connection('localhost', os.environ.get('C9_USER'), '',
                           'classicmodels')
cursor = data.create_cursor(conn)

product_line = input("Please enter the product line: ")
text_description = input("Please enter the description: ")

sql = f"""
    insert into `productlines` 
        (`productLine`, `textDescription`)
    VALUES
        ('{product_line}', '{text_description}')
"""

# remember to execute the query
cursor.execute(sql)

#commit the changes (i.e confirm the changes)
conn.commit()
Пример #12
0
def create_product():
    conn = data.get_connection('localhost', os.environ.get('C9_USER'), '', 'classicmodels')
    product_lines = data.get_product_lines(conn)
    return render_template('create_product.template.html', product_lines=product_lines)