def booksearch(): form = forms.SearchForm() if form.validate_on_submit(): data = form.bookinfo.data.strip() # 去掉首位空格 readers = [] #单条件查询 if data.find(' ') < 0: readers = models.Book.query.filter( models.Book.id.like('%' + data + '%')).all() else: # 组合查询 c = data.split() length = len(c) count = 0 result = models.Book.query.filter( models.Book.id.like('%' + c[count] + '%')).all() readerset = set(result) count += 1 # 用set找出and匹配元素 while count < length: result = models.Book.query.filter( models.Book.id.like('%' + c[count] + '%')).all() readerset = readerset & set(result) count += 1 readers = list(readerset) if readers == []: flash('null') return render_template('afterbooksearch.html', readers=readers) return render_template('booksearch.html', form=form)
def search(): reader_no = session['user'] form = forms.SearchForm() if form.validate_on_submit(): data = form.bookinfo.data.strip() #去掉首位空格 book = [] if data.find(' ') < 0: # 单条件查询 book = models.Book.query.filter( or_(models.Book.name.like('%' + data + '%'), models.Book.id == data, models.Book.author.like('%' + data + '%'), models.Book.press.like('%' + data + '%'), models.Book.summary.like('%' + data + '%'), models.Book.publish_date.like('%' + data + '%'))).all() else: # 组合查询 c = data.split() length = len(c) count = 0 result = models.Book.query.filter( or_(models.Book.name.like('%' + c[count] + '%'), models.Book.id == data, models.Book.author.like('%' + c[count] + '%'), models.Book.press.like('%' + c[count] + '%'), models.Book.summary.like('%' + c[count] + '%'), models.Book.publish_date.like('%' + c[count] + '%'))).all() bookset = set(result) count += 1 #用set找出and匹配元素 while count < length: result = models.Book.query.filter( or_(models.Book.name.like('%' + c[count] + '%'), models.Book.id == data, models.Book.author.like('%' + c[count] + '%'), models.Book.press.like('%' + c[count] + '%'), models.Book.summary.like('%' + c[count] + '%'), models.Book.publish_date.like('%' + c[count] + '%'))).all() bookset = bookset & set(result) count += 1 book = list(bookset) if book == []: flash('无搜索结果') else: return render_template('aftersearch.html', books=book) return render_template('search.html', form=form, reader_no=reader_no)
def search1(): form = forms.SearchForm(request.form) result = '' debug ='' message='' if request.method == 'POST' and form.validate(): q = request.form["searchKeyword"] twitter_api = twitter_auth() count = 100 # lang = 'us' #tl result_type = 'popular' # until ='2014-03-21' search_results = twitter_api.search.tweets( q=q, count=count) statuses = search_results['statuses'] message = str(len(statuses))+' results for \''+q+'\'' result = statuses for item in result: res = item['text'] if 'text' in item else item print res retweet = item['retweet_count'] if 'text' in item else item print retweet favorites = item['favorite_count'] if 'text' in item else item print favorites name = item['user']['screen_name'] if 'text' in item else item print name real = item['user']['name'] if 'text' in item else item print real pic = item['user']['profile_image_url_https'] if 'text' in item else item print pic followers = item['user']['followers_count'] if 'text' in item else item print followers date = item['created_at'] if 'text' in item else item print res,date t = models.Search(tweet=q, key=res, retweet=retweet, favorites=favorites, name=name, real=real, pic=pic, followers=followers, date=date) db.session.add(t) db.session.commit() # print result # for _ in range(5): # # print "Length of statuses", len(statuses) # try: # next_results = search_results['search_metadata']['next_results'] # except KeyError, e: # No more results when next_results doesn't exist # break # kwargs = dict([ kv.split('=') for kv in next_results[1:].split("&") ]) # print kwargs # result = search_results = twitter_api.search.tweets(**kwargs) # statuses += search_results['statuses'] # result = statuses return render_template('search.html', message=message, result=result, form=form, debug=debug)
def index(): venue_check = models.Venue.select() band_check = models.Band.select() no_venues = "" no_bands = "" if venue_check.exists(): venues = models.Venue.select().order_by(models.Venue.name) else: venues = None no_venues = "none" if band_check.exists(): bands = models.Band.select().order_by(models.Band.name) else: bands = None no_bands = "none" form = forms.SearchForm() term = False if request.method == 'POST': if form.validate_on_submit(): term = form.search.data venues = [] bands = [] for venue in venue_check: print(venue) if term.lower() in venue.display_name.lower(): venues.append(venue) for band in band_check: if term.lower() in band.display_name.lower(): bands.append(band) if len(venues) == 0: no_venues = "search_fail" if len(bands) == 0: no_bands = "search_fail" print(no_bands) return render_template('index.html', title="Into The Pit", form=form, venues=venues, bands=bands, no_bands=no_bands, no_venues=no_venues, search_term=term)
def rooms(): form = forms.SearchForm(request.form) form2 = forms.SearchForm2(request.form) if request.method == 'GET': hostels = models.Hostel.query.all() return render_template('hostels.html', hostels=hostels, form=form, form2=form2) elif request.method == 'POST': if request.form['button'] == 'secondS': return redirect( url_for('room_detail', hostel=form2.hostel_id.data, room=form2.room_id.data)) elif request.form['button'] == 'firstS': kwargs = {form.radio.data: form.value.data} search_result = models.Person.query.filter_by(**kwargs).all() return render_template('search_person.html', result=search_result)
def index(): search = forms.SearchForm(request.form) if request.method == 'POST': return results(search) return render_template('main.html', form=search)
def index(): decks = ac.get_deck_names() form = forms.SearchForm() form.decks.choices = [(i, i) for i in decks] form.language.choices = [(l, l) for l in app.config["AVAILABLE_LANGUAGES"]] return render_template("index.html", decks=decks, form=form)
def before_request(): g.search_form = forms.SearchForm()
def before_request(): if current_user.is_authenticated: current_user.last_seen = datetime.now() db.session.commit() g.search_form = forms.SearchForm()