本文整理汇总了Python中forms.SearchForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python SearchForm.validate方法的具体用法?Python SearchForm.validate怎么用?Python SearchForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.SearchForm
的用法示例。
在下文中一共展示了SearchForm.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: events
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def events():
form = SearchForm(request.forms.decode())
# XXX: make WTForm for this and validate!
if form.validate():
filters = {}
if form.country.data != "":
filters['country'] = form.country.data
session = create_session()
matching_events = session.query(Event).filter_by(**filters).\
order_by(Event.start_date)
print "--------------------"
print form.yob.data
print form.yob is None
if form.yob is not None:
print form['yob']
matching_events = ((matching_events)
.filter(form.yob.data <= Event.max_yob) #1985 <= 2000
.filter(form.yob.data >= Event.min_yob)) #1985 >= 1980
e = list(matching_events)
return dict(events=e, get_url=app.get_url)
return dict(events=[], error="nothing found", get_url=app.get_url)
示例2: course
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def course():
if request.method == 'GET':
return render_template('admin/courselist.html')
form = SearchForm(request.form)
if form.validate():
sres=form.search()
return render_template('admin/courselist.html',result=sres)
return render_template('admin/courselist.html')
示例3: search
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def search():
form = SearchForm(request.form)
articles = None
if form.validate() and request.method == 'POST':
title = form.title.data
articles = Article.query.filter(Article.deleted == False, Article.raw_content.contains(title)).order_by(Article.id.desc())
return render_template('common/search.html', articles=articles)
示例4: xk
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def xk():
if request.method == 'GET':
return render_template('student/xk.html')
form = SearchForm(request.form)
#卧槽简直是坑啊,之前在这用wtform一切都没问题尼玛就是获取不到表单数据,索性SearchForm不继承Form,然后就过了,我勒个去,怀疑是wtform哪bug了
if form.validate():
sres=form.search()
return render_template('student/xk.html',result=sres)
return render_template('student/xk.html')
示例5: search
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def search():
form = SearchForm(request.form)
if not form.validate():
return render_template('search.html', term="", results=None)
term = request.form['searchfield']
results = db.session.execute("SELECT * FROM post WHERE to_tsvector(\
'english', title || ' ' || body) @@ to_tsquery(\
'english', '" + term + "') ORDER BY timestamp DESC LIMIT 20")
return render_template('search.html', term=term, results=results)
示例6: search
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def search():
form = SearchForm()
if request.method == 'POST':
if form.validate() == False:
return render_template('search.html', form=form)
else:
return "[1] Create a new user [2] sign in the user [3] redirect to the user's profile"
elif request.method == 'GET':
return render_template('search.html', form=form)
示例7: index
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def index():
if request.method == 'POST':
form = SearchForm(request.form)
if form.validate():
year = form.year.data
e = loadElectionData(year)
return render_template('ca/map.html', e=e)
else:
flash('Please choose an election year')
return frontPage()
else:
return frontPage()
示例8: search
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def search():
form = SearchForm()
if request.method == 'POST' and form.validate():
f = hp.find_device(form.search_string.data)
if f is not None: # flukso was found
return redirect(url_for('flukso', fluksoid=f.key))
else:
flash("Sorry, we couldn't find that Fluksometer")
return render_template(
"search.html",
form=form)
示例9: index
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def index():
form = SearchForm()
if request.method == 'POST':
if form.validate():
print(form.query.data)
data = utils.find_me(g.db, form.query.data)
for a in data:
print(a
)
session['data'] = data
return redirect(url_for('index'))
return render_template('index.html', form=form, data=session.get('data'))
示例10: index
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def index():
entries = None
form = SearchForm(request.args)
if request.method == 'GET' and form.validate():
data = form.q.data
if data:
# query has to use + and not space to
# pull correct data
data = data.replace(' ', '+')
feed_url = BASE_FEED_URL % data
f = feedparser.parse(feed_url)
entries = f.entries
return render_template('index.html', form=form, entries=entries)
示例11: search
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def search():
form = SearchForm()
if request.method == 'POST':
if form.validate() == False:
flash('All fields are required.')
return render_template('search.html', form = form)
else:
# return render_template('success.html')
# return temporary(form.name.data,None)
#this should also change the url...
return redirect(url_for('temporary',text=form.name.data,names=None))
elif request.method == 'GET':
return render_template('search.html', form = form)
示例12: index
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def index():
"""
The home page of the search engine. Has the search bar
which accepts the query string. Redirects to the results
page after the results are computed. WOW!
"""
form = SearchForm()
if request.method == 'POST':
if form.validate() == False:
return render_template('index.html', form=form)
else:
return redirect(url_for('search', q = form.queryfield.data))
elif request.method == 'GET':
return render_template('index.html', form=form)
示例13: results
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def results():
form = SearchForm()
if request.method == 'POST':
if form.validate() == False:
flash('All fields are required.')
return render_template('results.html', form=form)
else: # form validated
ret = info_retrieve_v3.getCourse(form.course.data)
if(ret == None): # bad input
flash('No result :(')
return render_template('results.html', form=form)
else: # success
table = ret
return render_template('results.html', form=form, table=table, success=True)
elif request.method == 'GET':
return render_template('home.html', form=form);
示例14: search
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def search():
form = SearchForm(request.args, csrf_enabled=False)
valid = form.validate()
network = form.network.data
channels = request.args.getlist('channel')
if config.SEARCH_AJAX_ENABLED:
if not valid:
# TODO: Improve this?
abort(404)
try:
dates = paths.channels_dates(network, channels)
except exceptions.NoResultsException:
abort(404)
except exceptions.MultipleResultsException:
return render_template('error/multiple_results.html', network=network, channel=channels[0])
max_segment = grep.max_segment(dates[-1]['date_obj'])
return render_template(
'search_ajax.html',
valid=valid,
form=form,
network=network,
channels=channels,
author=form.author.data,
query=json.dumps(form.text.data),
max_segment=max_segment,
)
else:
# We should have another copy of this to use...
if not valid:
results = []
else:
results = grep.run(
channels=channels,
network=network,
author=form.author.data,
query=form.text.data,
)
return render_template('search.html', valid=valid, form=form, network=network, channel=channels[0], results=results)
示例15: search_amazon_book
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import validate [as 别名]
def search_amazon_book():
form = SearchForm()
if request.form=='POST' and form.validate():
#if form.validate_on_submit():
amazon = bottlenose.Amazon(AWS_KEY,AMAZON_SECRET_KEY,LANG)
search = amazon.ItemSearch(EAN=str(form.ean.data), ISBN=str(form.isbn.data), Title=unicode(form.title.data), Author=unicode(form.author.data), SearchIndex='Books', ResponseGroup='Medium')
#
# I create a list of each book found with just what I need to identify them. We will be able to modify the book later.
#
root = objectify.fromstring(search)
listing = list()
for item in root.Items.Item:
dico = dict()
dico["title"] = unicode(item.ItemAttributes.Title)
dico["ASIN"] = unicode(item.ASIN)
try:
dico["img"] = unicode(item.SmallImage.URL)
except AttributeError:
dico["img"] = ''
try:
dico["ISBN"] = unicode(item.ItemAttributes.ISBN)
except AttributeError:
dico["ISBN"] = 0
try:
dico["EAN"] = int(item.ItemAttributes.EAN)
except AttributeError:
dico["EAN"] = 0
try:
dico["publisher"] = unicode(item.ItemAttributes.Publisher)
except AttributeError:
dico["publisher"] = ''
auts = list()
try:
for author in item.ItemAttributes.Author:
auts.append(unicode(author))
dico["authors"] = auts
except AttributeError:
dico["authors"] = ''
listing.append(dico)
return render_template('list_amazon_results.html',listing = listing)
return render_template('search_amazon_book.html', title = 'Chercher un livre dans la base de donnees mondiale d\'Amazon', form = form )