Exemple #1
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.get_result())
Exemple #2
0
def title():
    ava = stay_ava()
    form = SearchForm()
    if request.method == 'GET':
        db_sess = db_session.create_session()
        questions = db_sess.query(Questions).all()
        users = db_sess.query(User).all()
        questions.sort(key=lambda elem: elem.popular, reverse=True)
        questions = [(qst, user) for qst in questions
                     for user in users if user.id == qst.author]
        questions = [(qst, user, url_for('static', filename='img/avatars/' + user.photo),
                      str(qst.date)[:16])
                     for qst, user in questions]
        params = return_files(ava=ava, form=form, qst=questions)
        return render_template('search.html', **params)
    else:
        qes = requests.get(f'http://localhost:8080/api/search/{form.search_line.data}').json()
        qes_id = list(map(lambda x: qes['qest'][x], qes['qest']))
        db_sess = db_session.create_session()
        questions = db_sess.query(Questions).all()
        users = db_sess.query(User).all()
        questions.sort(key=lambda elem: elem.popular, reverse=True)
        questions = [(qst, user) for qst in questions
                     for user in users if user.id == qst.author]
        questions = [(qst, user, url_for('static', filename='img/avatars/' + user.photo),
                      str(qst.date)[:16]) for qst, user in questions]
        fo = []
        for i in questions:
            if i[0].id in qes_id:
                fo.append(i)
        questions = fo
        params = return_files(ava=ava, form=form, qst=questions)
        return render_template('search.html', **params)
    def get(self):

        articles = Article.query.order_by(Article.id.desc()).limit(5).all()

        return render_template('index.html',
                               title='Home | Aukcije Online',
                               session=session.get('username'),
                               articles=articles,
                               search_form=SearchForm())
Exemple #4
0
def search():
    db = OracleDb()
    search_form = SearchForm()
    user_names = db.sqlalchemy_session.query(OrmUser.user_name).all()
    file_names = db.sqlalchemy_session.query(OrmFile.file_name).all()

    if request.method == 'GET':
        return render_template('search.html',
                               form=search_form,
                               result=None,
                               users=user_names,
                               files=file_names)
    else:
        search_form.user_name.data = request.form.get('user_name')
        search_form.file_name.data = request.form.get('file_name')
        return render_template('search.html',
                               form=search_form,
                               result=search_form.search(),
                               users=user_names,
                               files=file_names)
Exemple #5
0
def search_page():
    # Загрузка формы
    form = SearchForm()
    db_sess = db_session.create_session()
    # Занесение категорий в форму
    form.category.choices = ['Всё']
    form.category.choices.extend(
        [i.name for i in db_sess.query(Category).all()])
    store_settings = get_store_settings()
    store_settings['title'] = 'Поиск'
    # Обработка поиска
    if form.validate_on_submit():
        # Поиск только по имени
        if form.category.data != 'Всё':
            category_id = db_sess.query(Category).filter(
                Category.name == form.category.data).first().id
            items = db_sess.query(Item).filter(
                Item.name.like(f"%{form.name.data}%"),
                Item.category == category_id).all()
        # Поиск по имени и категории
        else:
            items = db_sess.query(Item).filter(
                Item.name.like(f"%{form.name.data}%")).all()
        # Заполенение словаря получеными данными
        items = {
            'items': items,
            'rows':
            len(items) // 3 if len(items) % 3 == 0 else len(items) // 3 + 1,
            'length': len(items)
        }
        # Возврат результатов
        return render_template('search.html',
                               items=items,
                               form=form,
                               **store_settings)
    return render_template('search.html',
                           items={'items': []},
                           form=form,
                           **store_settings)
Exemple #6
0
def search():
    form = SearchForm()

    if request.method == 'POST':
        try:
            if form.type_field.data == 'vacancy_name':
                res = db.session.query(OrmVacancy).filter(OrmVacancy.vacancy_name == form.search_value.data).all()
            elif form.type_field.data == 'vacancy_company':
                res = db.session.query(OrmVacancy).filter(OrmVacancy.vacancy_company == form.search_value.data).all()
            elif form.type_field.data == 'vacancy_location':
                res = db.session.query(OrmVacancy).filter(OrmVacancy.vacancy_location == form.search_value.data).all()
            elif form.type_field.data == 'vacancy_employment':
                res = db.session.query(OrmVacancy).filter(OrmVacancy.vacancy_employment == form.search_value.data).all()
            elif form.type_field.data == 'vacancy_salary':
                res = db.session.query(OrmVacancy).filter(OrmVacancy.vacancy_salary == form.search_value.data).all()
        except:
            form.search_value.errors = ['wront format']
            return render_template('search.html', form=form)

        return render_template('search_result.html', vacancies=res)
    else:
        return render_template('search.html', form=form)
Exemple #7
0
def search():

    search_form = SearchForm()

    if request.method=='GET':