Beispiel #1
0
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))
Beispiel #2
0
def user():
    dbworker = DBWorker()
    if current_user.is_authenticated:
        print('ok')
        print(current_user.get_id())
        data = dbworker.get_orders(current_user.get_id())
        print(data)
        # user = current_user.get_id()  # return username in get_id()
    else:
        return 'войдите или зарегистрируйтесь'
    return make_response(
        render_template('user_page.html', user=user, data=data))
Beispiel #3
0
def login():
    dbworker = DBWorker()
    if request.method == 'GET':
        return make_response(render_template('login_user.html'))
    elif request.method == 'POST':
        mail = request.form.get('email')
        passw = request.form.get('password')
        acc = request.form.get('accept')
        print(acc)
        if not dbworker.check_user(mail, passw):
            return make_response(
                render_template('login_user.html',
                                resp='Ошибка во введённых данных'))

        print(request.form.get('email'))
        print(request.form.get('password'))
        user, user_id = dbworker.get_user(mail)
        login_user(user, remember=acc)
        return redirect('/')
Beispiel #4
0
def items(number):
    dbworker = DBWorker()
    numb = str(number)
    if not numb.isdigit():
        number = 0
    if dbworker.count_goods() > int(number) + 8:
        maxx = (int(number)) * 8 + 1
    else:
        maxx = dbworker.count_goods()
    minn = (int(number) - 1) * 8 + 1
    goods = dbworker.get_goods(minn, maxx)
    leng = maxx - int(number)
    if leng > 4:
        goods_resp = [[goods[0], goods[1], goods[2], goods[3]]]
        gg = []
        for g in goods[4:]:
            gg.append(g)
        leng = len(gg)
        goods_resp.append(gg)
    else:
        goods_resp = [goods]
        leng = len(goods)
    # print(leng)
    flag = (dbworker.count_goods() > (int(number) * 8 + 1))
    res = str(session.get("current_cart"))
    print(session.items(), res)
    if request.method == 'GET':
        return make_response(
            render_template('items.html',
                            goods_resp=goods_resp,
                            number=int(number),
                            leng=leng,
                            flag=flag))
Beispiel #5
0
def UserLogIn():
    if request.method == 'GET':
        return make_response(render_template('user_check_page.html'))
    elif request.method == 'POST':
        name = request.form.get("name")
        mail = request.form.get('email')
        passw = request.form.get('password')
        loc = request.form.get('city_user')

        print(request.form.get("name"))
        print(request.form.get('email'))
        print(request.form.get('password'))
        print(request.form.get('city_user'))
        print(request.form.get('accept'))

        dbworker = DBWorker()
        try:
            dbworker.add_user(name, mail, passw)
            return redirect('/')

        except Exception as e:
            print(e)
            return "Invalid data"
Beispiel #6
0
import pytest
import unittest

from data import db_session
from data.dbworker import DBWorker

dbworker = DBWorker()


def test_user():
    dbworker.add_user('Daniel', '*****@*****.**', 'password')
Beispiel #7
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))
Beispiel #8
0
def test():
    url = url_for('item', id_item='101')
    dbworker = DBWorker()
    dbworker.add_user('Daniel', '*****@*****.**', 'password')
    return make_response(render_template('test.html', item1=url))