Python forms 模块,SearchForm() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用forms.SearchForm()

项目:Commodity-analysis    作者:buhuipao    | 项目源码 | 文件源码
def index():
    form = SearchForm()
    if form.validate_on_submit():
        old_word = session.get('key_word')
        old_price = session.get('price')
        if old_word == form.key_word.data and \
           old_price == form.price.data:
            flash('It seems like you searched the same keyword and \
                    price for the two time!')
        session['price'] = form.price.data
        session['key_word'] = form.key_word.data
        return redirect(url_for('search',
                        key_word=form.key_word.data,
                        price=form.price.data, refresh=form.refresh.data))

    return render_template('index.html', form=form)
项目:pi_romulus    作者:ArthurMoore85    | 项目源码 | 文件源码
def onStart(self):
        """
        Initialize the forms.
        """
        self.addForm('MAIN', SearchForm, name="Search for ROM")
项目:isthislegit    作者:duo-labs    | 项目源码 | 文件源码
def search():
    form = SearchForm(request.form)
    reports = []
    if form.validate_on_submit():
        results = search_provider.search(form['query'].data)
        for result in results:
            report = {f.name: f.value for f in result.fields}
            report['id'] = result.doc_id
            reports.append(report)
        return render_template('search.html', reports=reports)
    return render_template('search.html', reports=reports)
项目:flask-wallapop-watcher    作者:tanrax    | 项目源码 | 文件源码
def buscador():
    form = SearchForm()
    results = None
    if form.validate_on_submit():
        name = form.name.data
        price_max = form.price_max.data or ''
        # Search in Wallapop
        results = get_resultados(name, price_max)
    return render_template('items/buscador.html', form=form, results=results)
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def base_options():
    # a function for the options required by every page
    return {
        'pages': Page.query.all(),
        'current_user': current_user,
        'search_form': forms.SearchForm()
    }
    # TODO: try to use: app.jinja_env.globals['func_name'] = func


# ---------------------------------------------- ROUTING FUNCTIONS
项目:tingsmen    作者:pasqu4le    | 项目源码 | 文件源码
def search():
    # ajax request handling
    if g.sijax.is_sijax_request:
        g.sijax.register_callback('update_notifications', update_notifications)
        g.sijax.register_callback('set_all_notifications_seen', set_all_notifications_seen)
        return g.sijax.process_request()
    # non-ajax handling:
    # posts = Post.query.search(interrogation).all()
    form = forms.SearchForm()
    options = {
        'title': 'Search',
        'search_form': form,
    }
    if form.validate_on_submit():
        selection = form.filter.data
        interrogation = form.interrogation.data
        if not selection or selection == 'all':
            options.update({
                'users': User.query.search(interrogation, sort=True)[:5],
                'topics': Topic.query.search(interrogation, sort=True)[:5],
                'posts': Post.query.search(interrogation, sort=True)[:5],
                's_pages': Page.query.search(interrogation, sort=True)[:5],
                'proposals': Proposal.query.search(interrogation, sort=True)[:5],
                'laws': Law.query.search(interrogation, sort=True)[:5]
            })
        elif selection == 'users':
            options['users'] = User.query.search(interrogation, sort=True)[:20]
        elif selection == 'topics':
            options['topics'] = Topic.query.search(interrogation, sort=True)[:20]
        elif selection == 'posts':
            options['posts'] = Post.query.search(interrogation, sort=True)[:20]
        elif selection == 'pages':
            options['s_pages'] = Page.query.search(interrogation, sort=True)[:20]
        elif selection == 'proposals':
            options['proposals'] = Proposal.query.search(interrogation, sort=True)[:20]
        elif selection == 'laws':
            options['laws'] = Law.query.search(interrogation, sort=True)[:20]
    options.update(base_options())
    return render_template("search.html", **options)
项目:Commodity-analysis    作者:buhuipao    | 项目源码 | 文件源码
def search():
    # ????????????????????
    form = SearchForm()
    if form.validate_on_submit():
        old_word = session.get('key_word')
        old_price = session.get('price')
        if old_word == form.key_word.data and \
           old_price == form.price.data:
            flash('It seems like you searched the same keyword and \
                    price for the two time!')
        session['price'] = form.price.data
        session['key_word'] = form.key_word.data
        return redirect(url_for('search',
                        key_word=form.key_word.data,
                        price=form.price.data,
                        refresh=form.refresh.data))

    key_word = request.args.get('key_word', None)
    price = float(request.args.get('price', '0'))
    refresh = request.args.get('refresh', 'False')
    page = int(request.args.get('page', 1))
    if refresh == 'True':
        result, end_page = Search(price, key_word, page), 5
    else:
        data = db.search_goods(price, key_word)
        end_page = len(data)/8 if len(data) % 8 == 0 else len(data)/8 + 1
        # ????????????8????
        try:
            result = data[8*(page-1):8*page]
        except:
            result = data[8*(page-1):]
    end_page_list = range(1, end_page+1)
    prev_page = page - 1 if page - 1 else 1
    next_page = page + 1 if page + 1 <= end_page else end_page
    return render_template(
            'search.html',
            form=form,
            key_word=key_word,
            price=price,
            refresh=refresh,
            page=page,
            result=result,
            end_page_list=end_page_list,
            prev_page=prev_page,
            next_page=next_page)