def search(): form = SearchForm() if form.validate_on_submit(): results = wiki.search(form.term.data) return render_template('search.html', form=form, results=results, search=form.term.data) return render_template('search.html', form=form, search=None)
def covid(): form = SearchForm() if form.validate_on_submit(): if (not checkImage(form.state.data)): createImage(form.state.data) session['image'] = form.state.data + "_" + str(datetime.date.today()) return redirect(url_for('result')) return render_template('search.html', form=form)
def main(): form = SearchForm() if form.validate_on_submit(): isbn = form.isbn.data title = form.title.data.lower() author = form.author.data.lower() pub_year = form.pub_year.data form.isbn.data = "" form.title.data = "" form.author.data = "" form.pub_year.data = "" books = Book.query.filter( or_(Book.isbn.like("%" + isbn + "%"), func.lower(Book.author).like("%" + author + "%"), func.lower(Book.title).like("%" + title + "%"), Book.pub_year == pub_year)).all() if books: return render_template('index.html', form=form, books=books) flash('There is no such a book in our records') return redirect(url_for('main')) books = Book.query[:20] return render_template('index.html', form=form, books=books)
def dispatch_request(self): """ This form is plugeable. That means that all what you need to do is to install the package and run the url :: /ponywhoosh/ (You may change it in the config) and get the results. Returns: Results: The results are sent to the template using bootstrap. They are renderized using whether a grid or a table, depending on what models did you register. By default the first field registered is considered the one that will be contained in the tittle of each searh result. """ ctx = {"form": SearchForm()} query, fields = None, None wildcards = True except_field = None form = SearchForm() if self.debug: print "form:" pprint(form.data) if form.validate_on_submit(): query = form.query.data models = re.split("\W+", form.models.data, flags=re.UNICODE) fields = re.split("\W+", form.fields.data, flags=re.UNICODE) except_fields = re.split("\W+", form.except_field.data, flags=re.UNICODE) add_wildcards = form.add_wildcards.data something = form.something.data results = self._pw.search( query, add_wildcards=add_wildcards, something=something, include_entity=True, fields=fields, models=models, except_fields=except_fields, use_dict=False, ) if self.debug: print "form = ", pprint( { "query": query, "add_wildcards": add_wildcards, "something": something, "include_entity": True, "fields": fields, "models": models, "except_fields": except_fields, } ) print "results = " pprint(results) return render_template( "ponywhoosh/results.html", entidades=list(self._pw._entities.keys()), form=form, results=results, n=results["cant_results"], labels=results["results"].keys(), ) return render_template("ponywhoosh/index.html", form=form, query=query)
def dispatch_request(self): """ This form is plugeable. That means that all what you need to do is to install the package and run the url :: /ponywhoosh/ (You may change it in the config) and get the results. Returns: Results: The results are sent to the template using bootstrap. They are renderized using whether a grid or a table, depending on what models did you register. By default the first field registered is considered the one that will be contained in the tittle of each searh result. """ ctx = {'form' : SearchForm()} except_field = None query, fields = None, None wildcards = True form = SearchForm() if self.debug: print 'form:' pprint(form.data) if form.validate_on_submit(): add_wildcards = form.add_wildcards.data except_fields = re.split('\W+', form.except_field.data, flags=re.UNICODE) fields = re.split('\W+', form.fields.data, flags=re.UNICODE) models = re.split('\W+', form.models.data, flags=re.UNICODE) query = form.query.data something = form.something.data results = self._pw.search( query , add_wildcards=add_wildcards , something=something , include_entity=True , fields=fields , models=models , except_fields=except_fields , use_dict=False ) if self.debug: print 'form = ', pprint({ 'query': query , 'add_wildcards': add_wildcards , 'something': something , 'include_entity': True , 'fields': fields , 'models': models , 'except_fields': except_fields }) print "results = " pprint(results) return render_template( 'ponywhoosh/results.html' , entidades=list(self._pw._entities.keys()) , action_url_form=self.action_url_form , form=form , results=results , n=results['cant_results'] , labels=results['results'].keys() ) return render_template( 'ponywhoosh/index.html' , form=form , action_url_form=self.action_url_form , query=query )