コード例 #1
0
ファイル: main.py プロジェクト: Dikiliev/web_project
def search_user():  # Поиск других пользователй
    form = SearchForm()
    if form.validate_on_submit():
        name = form.name.data  # Введенная пользователем имя (часть имени)
        db_sess = db_session.create_session()

        # Пользаветели чьи имена начинаются на name
        users = db_sess.query(User).filter((User.name.like(f'{name}%')) | (
            User.full_name.like(f'{name}%'))).all()
        # Добавление пользаветелей чьич именах есть name
        users += db_sess.query(User).filter(
            User.id.notin_([user.id for user in users]),
            (User.name.like(f'%{name}%')) |
            (User.full_name.like(f'%{name}%'))).all()

        return render_template('search.html',
                               title='Поиск',
                               theme=get_theme(),
                               form=form,
                               users=users)

    return render_template('search.html',
                           title='Поиск',
                           theme=get_theme(),
                           form=form)
コード例 #2
0
def reqister():
    global res

    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')

    form = RegisterForm()
    if form.validate_on_submit():
        if form.password.data != form.password_again.data:
            return render_template('register.html', title='Регистрация',
                                   form=form,
                                   message="Пароли не совпадают", form2=form2)
        db_sess = db_session.create_session()
        if db_sess.query(User).filter(User.email == form.email.data).first():
            return render_template('register.html', title='Регистрация',
                                   form=form,
                                   message="Такой пользователь уже есть",
                                   form2=form2)
        user = User(
            surname=form.surname.data,
            name=form.name.data,
            email=form.email.data,
        )
        user.set_password(form.password.data)
        db_sess.add(user)
        db_sess.commit()
        return redirect('/login')
    return render_template('register.html', title='Регистрация', form=form,
                           form2=form2)
コード例 #3
0
def login():
    global res

    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')

    form = LoginForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        user = db_sess.query(User).filter(User.email == form.email.data).first()
        if user and user.check_password(form.password.data):
            login_user(user, remember=form.remember_me.data)
            return redirect("/")
        return render_template('login.html',
                               message="Неправильный логин или пароль",
                               form=form,
                               form2=form2)
    return render_template('login.html', title='Авторизация', form=form,
                           form2=form2)
コード例 #4
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)
コード例 #5
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)
コード例 #6
0
ファイル: app.py プロジェクト: LivelyPuer/TorrentGames
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)
コード例 #7
0
ファイル: app.py プロジェクト: LivelyPuer/TorrentGames
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)
コード例 #8
0
def search():

    search_form = SearchForm()

    if request.method == 'GET':
        return render_template('search.html', form=search_form, result=None)
    else:
        return render_template('search.html',
                               form=search_form,
                               result=search_form.data_result())
コード例 #9
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)
コード例 #10
0
ファイル: run.py プロジェクト: diadkoroman/elibr
def indexview():
    title = app.config.get('PAGETITLE') if app.config.get('PAGETITLE') else ''
    uname = session.get('uname') if session.get('uname') else None
    #####################################
    try:
        books = [(item.id,item.nazva,','.join([autor.imja for autor in item.authors])) for item in sess.query(Book).all()]
    except:
        books = None

    ############ РОБОТА ФОРМИ ПОШУКУ ##################
    if request.method == 'POST':
        sf = SearchForm(request.form)
        if sf.validate():
            try:
                searchbooks = sess.query(Book).filter(or_(Book.nazva == sf.searchf.data,
                Book.nazva.startswith(sf.searchf.data),
                Book.nazva.contains(sf.searchf.data),
                Book.nazva.endswith(sf.searchf.data)
                ))
                books = [(item.id,item.nazva,','.join([autor.imja for autor in item.authors])) for item in searchbooks]

                searchauthors = sess.query(Author).filter(or_(Author.imja == sf.searchf.data,
                Author.imja.startswith(sf.searchf.data),
                Author.imja.contains(sf.searchf.data),
                Author.imja.endswith(sf.searchf.data)
                ))
                books2=[]
                for item in searchauthors:
                    for b in item.books:
                        books2.append((b.id,b.nazva,','.join([autor.imja for autor in b.authors])))
                books = books + books2
            except:
                books=None
    else:
        pass
    ###################################################


    # якщо користувач не авторизований - він бачить дефолтну першу сторінку
    # авторизований користувач входить на першу для авторизованих
    if not session.get('user_auth_key'):
        return render_template('components/page.html',title=title,books=books)
    else:
        return render_template('components/page_aut.html',title=title,uname=uname,books=books)
コード例 #11
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)
コード例 #12
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)
コード例 #13
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)
コード例 #14
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)
コード例 #15
0
ファイル: app.py プロジェクト: LivelyPuer/TorrentGames
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)
コード例 #16
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)