Ejemplo n.º 1
0
def pay():
    global res
    ords = get_ords()
    db_sess = db_session.create_session()
    goods = db_sess.query(Goods)
    summ = 0
    for i in goods:
        if i.id in ords:
            summ += i.cost

    form2 = SearchForm()
    if form2.validate_on_submit():
        db_sess = db_session.create_session()
        goods = db_sess.query(Goods)
        for i in goods:
            if str(form2.ttle.data).lower() in str(i.title).lower():
                res.append(i.id)
        return redirect('/search_results')

    form3 = PayForm()
    if form3.validate_on_submit():
        return redirect('/')

    return render_template("pay.html", title='Оплата', goods=goods,
                           ords=ords, summ=summ, form2=form2, form3=form3)
Ejemplo n.º 2
0
def index():
    global res, categories
    res.clear()
    form = SearchForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        goods = db_sess.query(Goods)
        for i in goods:
            if str(form.ttle.data).lower() in str(i.title).lower():
                res.append(i.id)
        return redirect('/search_results')
    db_sess = db_session.create_session()
    goods = db_sess.query(Goods)
    # form4 = FavsForm()
    # form4 = ChecksForm()  # new
    # if form4.validate_on_submit():
    #     db_sess = db_session.create_session()
    #     assoc = Association(
    #         user_id=current_user.id,
    #         favs_id=form4.favs_id.data,
    #         orders_id=0,
    #         o_count=0
    #     )
    #     db_sess.add(assoc)
    #     db_sess.commit()
    return render_template("main.html", title='Главная страница', goods=goods,
                           favs=get_favs(), ords=get_ords(),
                           form2=form, cats=categories)
Ejemplo n.º 3
0
def find_category(category_id):
    form = SearchForm()
    if form.validate_on_submit():
        return redirect('/search/{}'.format(form.search.data))
    db_sess = db_session.create_session()
    games = db_sess.query(Game).filter(Game.category_id == category_id).all()
    return render_template("main.html", games=games, form=form)
Ejemplo n.º 4
0
def index():
    db_sess = db_session.create_session()
    games = db_sess.query(Game).all()
    form = SearchForm()
    if form.validate_on_submit():
        return redirect('/search/{}'.format(form.search.data))
    print(current_user if current_user else "Не авторизаван")
    return render_template("main.html", games=games, form=form)
Ejemplo n.º 5
0
def favorites():
    global res
    form = SearchForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        goods = db_sess.query(Goods)
        for i in goods:
            if str(form.ttle.data).lower() in str(i.title).lower():
                res.append(i.id)
        return redirect('/search_results')

    db_sess = db_session.create_session()
    goods = db_sess.query(Goods)
    return render_template("favorites.html", title='Избранное', goods=goods,
                           favs=get_favs(), form2=form)
Ejemplo n.º 6
0
def product(r):
    global res
    form = SearchForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        goods = db_sess.query(Goods)
        for i in goods:
            if str(form.ttle.data).lower() in str(i.title).lower():
                res.append(i.id)
        return redirect('/search_results')

    db_sess = db_session.create_session()
    goods = db_sess.query(Goods)
    for i in goods:
        if i.id == r:
            tl = i.title
    return render_template("product.html", title=f'{tl}', goods=goods,
                           favs=get_favs(),
                           ords=get_ords(),
                           form2=form, i_id=r)
Ejemplo n.º 7
0
def search_results():
    global res, categories
    form = SearchForm()
    if form.validate_on_submit():
        res.clear()
        db_sess = db_session.create_session()
        goods = db_sess.query(Goods)
        for i in goods:
            if str(form.ttle.data).lower() in str(i.title).lower():
                res.append(i.id)
        return redirect('/search_results')

    # form.button.data true - false
    db_sess = db_session.create_session()
    goods = db_sess.query(Goods)

    return render_template('search_results.html', title='Результаты поиска',
                           res=res, form2=form,
                           goods=goods,
                           favs=get_favs(), ords=get_ords(), cats=categories)
Ejemplo n.º 8
0
def cat(r):
    global res, categories
    form = SearchForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        goods = db_sess.query(Goods)
        for i in goods:
            if str(form.ttle.data).lower() in str(i.title).lower():
                res.append(i.id)
        return redirect('/search_results')

    db_sess = db_session.create_session()
    goods = db_sess.query(Goods)
    col = 0
    for i in goods:
        if i.category == categories[r - 1]:
            col += 1
    return render_template("categories.html", title='Поиск по категориям',
                           goods=goods, favs=get_favs(),
                           ords=get_ords(),
                           form2=form, cat=categories[r - 1], col=col, cats=categories)
Ejemplo n.º 9
0
def basket():
    global res
    ords = get_ords()
    form = SearchForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        goods = db_sess.query(Goods)
        for i in goods:
            if str(form.ttle.data).lower() in str(i.title).lower():
                res.append(i.id)
        return redirect('/search_results')

    db_sess = db_session.create_session()
    goods = db_sess.query(Goods)
    summ = 0
    for i in goods:
        if i.id in ords:
            summ += i.cost

    return render_template("basket.html", title='Корзина', goods=goods,
                           ords=ords, summ=summ, form2=form)
Ejemplo n.º 10
0
def search(game_title):
    form = SearchForm()
    if form.validate_on_submit():
        return redirect('/search/{}'.format(form.search.data))
    else:
        session = db_session.create_session()
        games = session.query(Game).all()
        dct = {}
        for game in games:
            dct[game.id] = 0
            i = 0
            if game_title.lower() in game.title.lower():
                dct[game.id] += len(game_title)
            if len(game_title) == len(game.title):
                dct[game.id] += len(game_title) // 2
            for char in zip(game.title.lower(), game_title.lower()):
                if i > len(game_title):
                    break
                if char[0] == char[1]:
                    dct[game.id] += 1
                i += 1
        lst = []
        for key, value in dct.items():
            lst.append((key, value))
        lst.sort(key=lambda x: x[1], reverse=True)

        game = session.query(Game).filter(
            Game.id.in_([
                x[0] for x in list(
                    filter(lambda x: lst[0][1] - 2 <= x[1] <= lst[0][1] + 2,
                           lst))
            ])).all()
        return render_template("main.html",
                               games=game,
                               form=form,
                               value=game_title)
Ejemplo n.º 11
0
def main_page():
    form = SearchForm()
    if form.validate_on_submit():
        res = form.search.data
        return redirect('/search/{}/1'.format(res))
    return render_template("index.html", title="Главная", form=form)