Пример #1
0
def add_credit_card():
    credit_card_types = api.get_card_types()
    addresses = [address for address in api.get_person(session['user_id']).get_addresses() if address.get_type() == 'billing']
    months = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"] 
    years = ["2017", "2018", "2019", "2020", "2021", "2022"]
    state_codes = api.get_state_codes()
    return render_template('edit_credit_card.html', addresses=addresses, credit_card_types=credit_card_types, months=months, years=years, navs=make_navs())
Пример #2
0
def cart_submit():
    if session['user_type'] != 'customer':
        flash("You don't have a cart to submit", category='error')
        return redirect(url_for('index'))
    user = api.get_person(session['user_id'])
    order_id = user.submit_cart()
    flash("Cart submitted as order id: %d" % order_id)
    return redirect(url_for('index'))
Пример #3
0
def credit_cards():
    if session['user_type'] != 'customer':
        return redirect(url_for('index')) 
    user = api.get_person(session['user_id'])
    if not user:
        return redirect(url_for('logout'))
    credit_cards = user.get_credit_cards()
    return render_template('credit_cards.html', credit_cards=credit_cards, navs=make_navs())
Пример #4
0
def address():
    if session['user_type'] != 'customer':
        return redirect(url_for('index')) 
    user = api.get_person(session['user_id'])
    if not user:
        return redirect(url_for('logout'))
    addresses = user.get_addresses()
    return render_template('addresses.html', addresses=addresses, navs=make_navs())
Пример #5
0
def index():
    account_balance = None
    orders = None
    if session['user_type'] == 'customer':
        user = api.get_person(session['user_id'])
        account_balance = user.get_balance()
        orders = user.get_order_history()
        orders = [order for order in user.get_order_history() if order.get_status() == 'pending' or order.get_status() == 'shipping']
        
    elif session['user_type'] == 'staff':
        orders = [order for order in api.get_orders() if order.get_status() == 'pending' or order.get_status() == 'shipping']
    return render_template('index.html',orders = orders, account_balance = account_balance, navs=make_navs());
Пример #6
0
def modify_cart():
    if 'diff' in request.form and 'product_id' in request.form:

        diff = int(request.form['diff'])
        product = api.get_product(int(request.form['product_id']))
        cart = api.get_person(session["user_id"]).get_cart()
        current_quantity = cart.get_product_quantity(product)
        changed_quantity = int(current_quantity + diff)

        if changed_quantity < 0:
            cart.modify_product_quantity(product, 0)
        else:
            cart.modify_product_quantity(product, changed_quantity)

        return redirect(url_for('view_cart'))
    else:
        flash("Missing some data", category='error')
        return redirect(request.referrer)
Пример #7
0
def add_credit_card_post():
    credit_card = api.make_new_credit_card(api.get_person(session['user_id']), int(request.form['credit_card_number']), int(request.form['credit_card_security_code']), int(request.form['credit_card_expiration_month']), int(request.form['credit_card_expiration_year']), request.form['credit_card_type'], api.get_address(int(request.form['credit_card_address_id'])))
    return redirect(url_for('view_credit_card', credit_card_id = credit_card.get_id()))
Пример #8
0
def add_address_post():
    address = api.make_new_address(request.form['address_street'], request.form['address_city'], request.form['address_state'], int(request.form['address_zip_code']), request.form['address_type'], api.get_person(session['user_id']), apt_no=request.form['address_apartment_no'])
    address.set_default_flag(('address_default' in request.form))
    return redirect(url_for('view_address', address_id = address.get_id()))
Пример #9
0
def view_cart():
    cart = api.get_cart(api.get_person(session['user_id']))
    products = cart.get_products_and_quantities()
    return render_template('cart.html', products=products, cart=cart, navs=make_navs())