예제 #1
0
파일: main.py 프로젝트: ANDaniell/web_shop
def item(id_item):
    data = [1, 2, 3, 4]
    dbworker = DBWorker()
    temp = dbworker.get_good(id_item)
    inf = temp['characteristics']
    data = temp['img']
    ab = temp["about"]
    return make_response(
        render_template('item.html', data=data, inf=inf, about=ab))
예제 #2
0
def get_basket():
    dbworker = DBWorker()
    try:
        goods = session['current_cart']
        data = []
        for i in goods:
            gg = dbworker.get_good(i)
            total = gg['price']
            data.append(gg)
    except Exception:
        data = None
    city = {'city': 'Город'}
    if current_user.is_authenticated:
        # print(dbworker.get_user(current_user.get_id()))
        city = dbworker.get_address_by_user(current_user.get_id())
    if request.method == 'GET':
        return make_response(
            render_template('basket.html', data=data, city=city))
    if request.method == 'POST':
        print(request.form.get('city_user'))
        if request.form.get('Encrypt') == 'Encrypt':
            # pass
            session['current_cart'] = []
            print("Encrypted")
            return redirect('/')

        elif request.form.get('Decrypt') == 'Decrypt':
            if dbworker.get_addreass_by_value(
                    request.form.get('city_user')) is not None:
                address = dbworker.get_addreass_by_value(
                    request.form.get('city_user'))
                print('find')
            else:
                address = dbworker.add_address(request.form.get('city_user'))
                print(address)
            # pass # do something else
            if current_user.is_authenticated:
                user = current_user.get_id()
                print('user:'******'session:', session['current_cart'])
                dbworker.add_order(111, 1, session['current_cart'], int(user),
                                   address)
                session['current_cart'] = []
            else:
                print(session['current_cart'])
                dbworker.add_order(111, 1, session['current_cart'], None,
                                   address)
                session['current_cart'] = []
            print("Decrypted")
            return redirect('/')
        elif 'Remove' in str(request.form):
            lst = request.form.get('Remove').split()
            a = int(lst[1])
            print(session['current_cart'])
            print('---' * 10)
            arr = []
            for i in session['current_cart']:
                if a != i:
                    arr.append(i)
            print(session['current_cart'])
            session['current_cart'] = arr
            if session['current_cart'] == [] or session['current_cart'] is None:
                return redirect('/')
            else:
                return redirect('/basket')
        else:
            print('nothing')
        print(request.form)
        return make_response(
            render_template('basket.html', data=data, city=city))