def search(): """抽离搜索业务逻辑,每个视图函数都支持""" form = SearchForm() if form.validate_on_submit(): type = types[form.type.data] content = form.content.data return redirect(url_for('main.search_detail', type=type, q=content))
def index(): form = SearchForm() if form.validate_on_submit(): value = form.value.data print("VALUE", value) render_template('index.html', form=form) return render_template('index.html', form=form)
def search(): form = SearchForm() if form.validate_on_submit(): empty = False data = None if form.data_type.data == 'task': data = Paper.query.filter( or_(Paper.title.like(f'%{form.search_text.data}%'), Paper.description.like( f'%{form.search_text.data}%'))).all() elif form.data_type.data == 'user': data = User.query.filter( User.name.like(f'%{form.search_text.data}%')).all() if not data: empty = True return render_template('search_results.html', title='Search results', data=data, empty=empty, data_type=form.data_type.data, search_text=form.search_text.data, header='Search results') return render_template('insert_data.html', title='Search', form=form, header='Search')
def index(): form = SearchForm() if form.validate_on_submit(): if not any([ form.neighborhood_search.data, form.type_search.data, form.date_search ]): return redirect(url_for('main.explore')) else: params = [] params.append(form.neighborhood_search.data) params.append(form.type_search.data) params.append(form.date_search.data) return search_results(params) page = request.args.get('page', 1, type=int) index = ["index"] gigs = current_user.favorite_gigs().paginate( page, current_app.config['GIGS_PER_PAGE'], False) next_url = url_for('main.index', page=gigs.next_num) \ if gigs.has_next else None prev_url = url_for('main.index', page=gigs.prev_num) \ if gigs.has_prev else None return render_template('index.html', title='Home', form=form, gigs=gigs.items, next_url=next_url, prev_url=prev_url)
def search_appointment(): form = SearchForm() if form.validate_on_submit(): return redirect( url_for('main.search_result', search_type=form.search_type.data, q=form.searchbox.data)) return render_template("main/search.html", form=form)
def index(): search_form = SearchForm() surprise_form = SurpriseForm() if search_form.validate_on_submit(): session.pop('searchQuery', None) session['searchQuery'] = search_form.search_query.data return redirect(url_for('data_sources_blueprint.get_restaurant_from_google')) return render_template('index.html', title="Home Page", form=search_form, surprise_form=surprise_form)
def search(): form = SearchForm() if form.validate_on_submit(): return jsonify(status='ok', url=url_for('main.search_list', terms=form.terms.data)) return render_template('main/search.html', title="Search Stories", form=form)
def index(): form = SearchForm() if form.validate_on_submit(): hash = form.input.data.upper() elif request.method == 'POST': hash = request.form['hash'].upper() else: return render_template('main/index.html', form=form) return redirect(url_for('main.result', type='search', hash=hash))
def search(): form = SearchForm() if form.validate_on_submit(): inp = form.inp.data.lower() results = User.query.filter(User.Email.contains(inp)) return render_template('search-list.html', results=results, form=form) return render_template('search-list.html', form=form)
def trade(): form_search = SearchForm(request.form) if form_search.validate_on_submit(): companies = Tickers.query.filter(Tickers.ticker.like('%{}%'.format(form_search.ticker.data)) \ | Tickers.name.like('%{}%'.format(form_search.ticker.data)))[0:100] return render_template('trade.html', title=('Trade'), form=form_search, companies=companies) return render_template('trade.html', title=('Trade'), form=form_search)
def search(): form = SearchForm() if form.validate_on_submit(): topics = Topic.query.filter(Topic.description.contains( form.value.data)).all() topics += Topic.query.filter(Topic.name.contains( form.value.data)).all() return render_template('search.html', form=form, topics=topics) topics = Topic.query.all() return render_template('search.html', form=form, topics=topics)
def search_appointment(filterby): def sameDay(now, specificAppointmentTime): #print(specificAppointmentTime.year, now.year, specificAppointmentTime.month,now.month, specificAppointmentTime.day,now.day) return specificAppointmentTime.year == now.year and specificAppointmentTime.month == now.month and specificAppointmentTime.day == now.day def sameWeek(now, specificAppointmentTime): #print(now.isocalendar()[1], specificAppointmentTime.isocalendar()[1], now.year, specificAppointmentTime.year) return now.isocalendar()[1] == specificAppointmentTime.isocalendar( )[1] and now.year == specificAppointmentTime.year appointment_list = Appointment.query.all() now = datetime.now() if filterby == 0: #No Filter print('No Filter') elif filterby == 1: #Filter for today for appointment in reversed( appointment_list ): #if not reversed, array will skip certian items when removed if not sameDay(now, appointment.appointment_start_date): appointment_list.remove(appointment) elif filterby == 2: #Filter for this week for appointment in reversed( appointment_list ): #if not reversed, array will skip certian items when removed if not sameWeek(now, appointment.appointment_start_date): appointment_list.remove(appointment) elif filterby == 3: #Filter Overdue (Everything before current datetime) for appointment in reversed( appointment_list ): #if not reversed, array will skip certian items when removed if appointment.appointment_start_date > now: appointment_list.remove(appointment) else: print('No Filter') #filters based on what user is searching for search = '' form = SearchForm() if form.validate_on_submit(): search = form.search.data if search != '': for appointment in reversed(appointment_list): if search in appointment.customer_name or search in appointment.appointment_title: print(search, 'found') else: appointment_list.remove(appointment) count = len(appointment_list) return render_template("main/appointmentsearch.html", appointment_list=appointment_list, filterby=filterby, search=search, count=count, form=form)
def home(): sForm = SearchForm() now = datetime.now() if now.hour == 0 or now.hour == 12: trip_start_check() if sForm.validate_on_submit(): if sForm.search.data: result1 = User.query.filter( func.lower(User.username) == func.lower(sForm.search.data)) result2 = Trip.query.filter( func.lower(Trip.name) == func.lower(sForm.search.data)) result3 = Trip.query.filter( func.lower(Trip.location) == func.lower(sForm.search.data)) result4 = User.query.filter( func.lower(User.first_name) == func.lower(sForm.search.data)) result5 = User.query.filter( func.lower(User.last_name) == func.lower(sForm.search.data)) result6 = User.query.filter( func.lower(User.full_name) == func.lower(sForm.search.data)) return render_template('results.html', users=result1, trips_name=result2, trips_location=result3, users_name=result4, users_last_name=result5, users_full_name=result6, sForm=sForm) else: result = User.query.all() result2 = Trip.query.all() return render_template('results.html', users=result, sForm=sForm, trips=result2) per_page_val = 5 page = request.args.get('page', 1, type=int) trips = Trip.query.order_by(Trip.date_created.desc()).paginate( page=page, per_page=per_page_val) users = User.query.all() ids = [("id" + str(trip.id)) for trip in trips.items] print(ids) return render_template('home2.html', trips=trips, users=users, sForm=sForm, ids=ids)
def search_project(): projectname = '' form = SearchForm() if form.validate_on_submit(): projectname = form.name.data projects = Project.get_all( ) if projectname == '' else Project.get_project_by_name(projectname) return render_template("main/search.html", data=projects, is_users=False, form=form)
def index(): form = SearchForm() q = pagination = tools = tool_query = None if form.validate_on_submit(): q = form.q.data tool_query = Tool.query.filter(Tool.name.ilike(f'%{q}%')) pagination, tools = get_pagination(tool_query) if not tools: flash('找不到工具,换个关键字试试?', 'danger') return render_template('index.html', form=form, pagination=pagination, tools=tools)
def leaderboard(): search_form = SearchForm() users = db.session.query(User) if search_form.validate_on_submit(): users = users.filter(User.username.like('%' + search_form.search.data + '%')) users = users.join(Post).join(Like).group_by(User.id).order_by(func.count().desc()) users, next_url, prev_url = paginate(users, current_app.config['USERS_PER_PAGE']) return render_template('leaderboard.html', title='Leaderboard', users=users.items, next_url=next_url, prev_url=prev_url, form=search_form)
def popular(): search_form = SearchForm() posts = db.session.query(Post) if search_form.validate_on_submit(): posts = posts.filter(Post.title.like('%' + search_form.search.data + '%') | Post.body.like('%' + search_form.search.data + '%')) posts = posts.join(Like).group_by(Post.id).order_by(func.count().desc()) posts, next_url, prev_url = paginate(posts, current_app.config['POSTS_PER_PAGE']) return render_template('popular.html', title='Popular', posts=posts.items, next_url=next_url, prev_url=prev_url, form=search_form, include_chat=True)
def index(): subject_results = Subject.query.all() form = SearchForm() if form.validate_on_submit(): context = form.context.data results = Question.query.filter( Question.context.like('%' + context + '%')).all() return render_template('search_results.html', results=results, count=len(results)) return render_template('index.html', form=form, subject_results=subject_results)
def search_user(): username = '' form = SearchForm() if form.validate_on_submit(): username = form.name.data users = User.get_all( form.name.data) if username == '' else User.get_user_by_username( username) return render_template("main/search.html", data=users, is_users=True, form=form)
def explore_chats(): form = SearchForm() chats = db.session.query(Chat) if form.validate_on_submit(): chats = chats.filter(Chat.name.like('%' + form.search.data + '%') | Chat.about.like('%' + form.search.data + '%')) chats = chats.join(followers).group_by(Chat.id).order_by(func.count().desc()) chats, next_url, prev_url = paginate(chats, current_app.config['CHATS_PER_PAGE']) return render_template('explore_chats.html', title='Explore', chats=chats.items, next_url=next_url, prev_url=prev_url, form=form)
def search(): form = SearchForm() dne = False data = None is_favorite = False word = "" favorites = Favorites.query.filter_by(user_id=current_user.id).all() if form.validate_on_submit(): word = form.word.data data = fetch_meaning(word) try: tmp = data[0]['shortdef'][0] for item in favorites: if item.word == word: is_favorite = True break except: dne = True resp = make_response( render_template('search.html', title='Search', form=form, is_favorite=is_favorite, dne=dne, data=data, word=word)) if not dne: resp.set_cookie('word', word) return resp if 'word' in request.cookies: word = request.cookies.get('word') form.word.data = word data = fetch_meaning(word) for item in favorites: if item.word == word: is_favorite = True break return render_template('search.html', title='Search', form=form, is_favorite=is_favorite, dne=dne, data=data, word=word)
def index(): form = SearchForm() page = request.args.get('page', 1, type=int) if form.validate_on_submit(): flash('Search for {}'.format(form.email.data)) words_email = ["%" + form.email.data + "%"] rule_sender = and_(*[LogImported.sender_address.like(w) for w in words_email]) rule_recipient = and_(*[LogImported.recipient_address.like(w) for w in words_email]) rule_return = and_(*[LogImported.return_path.like(w) for w in words_email]) rule_email = rule_sender + rule_recipient + rule_return words_ip = ["%" + form.ip.data + "%"] rule_client_ip = and_(*[LogImported.client_ip.like(w) for w in words_ip]) rule_server_ip = and_(*[LogImported.server_ip.like(w) for w in words_ip]) rule_original_client_ip = and_(*[LogImported.original_client_ip.like(w) for w in words_ip]) rule_original_server_ip = and_(*[LogImported.original_server_ip.like(w) for w in words_ip]) rule_ip = rule_client_ip + rule_server_ip + rule_original_client_ip + rule_original_server_ip rule = rule_email + rule_ip l = LogImported.query.filter(rule) # l = LogImported.query.filter(LogImported.sender_address.like("%" + form.email.data + "%")).all() # l = LogImported.query.filter_by(sender_address=form.email.data).all() flash(l.paginate(page, per_page=50, error_out=True)) pagination = l.paginate(page, per_page=50, error_out=True) pageitems = pagination.items session['email'] = form.email.data session['ip'] = form.ip.data return render_template('index.html', title=_('Home'), form=form, loglist = l, \ pageitems = pageitems, pagination = pagination) elif session['email'] is not '*****@*****.**': words_email = ["%" + session['email'] + "%"] rule_sender = and_(*[LogImported.sender_address.like(w) for w in words_email]) rule_recipient = and_(*[LogImported.recipient_address.like(w) for w in words_email]) rule_return = and_(*[LogImported.return_path.like(w) for w in words_email]) rule_email = rule_sender + rule_recipient + rule_return words_ip = ["%" + session['ip'] + "%"] rule_client_ip = and_(*[LogImported.client_ip.like(w) for w in words_ip]) rule_server_ip = and_(*[LogImported.server_ip.like(w) for w in words_ip]) rule_original_client_ip = and_(*[LogImported.original_client_ip.like(w) for w in words_ip]) rule_original_server_ip = and_(*[LogImported.original_server_ip.like(w) for w in words_ip]) rule_ip = rule_client_ip + rule_server_ip + rule_original_client_ip + rule_original_server_ip rule = rule_email + rule_ip l = LogImported.query.filter(rule) flash(l.paginate(page, per_page=50, error_out=True)) pagination = l.paginate(page, per_page=50, error_out=True) pageitems = pagination.items return render_template('index.html', title=_('Home'), form=form, loglist = l, \ pageitems = pageitems, pagination = pagination) else: return render_template('index.html', title=_('Home'), form=form)
def index(): form = SearchForm() if request.method == "POST" and form.validate_on_submit(): return redirect(url_for(".search", query=form.search.data)) page = request.args.get("page", 1, type=int) show_followed = False if current_user.is_authenticated: show_followed = bool(request.cookies.get("show_followed", "")) if show_followed: query = current_user.followed_images else: query = Image.query pagination = query.order_by(Image.timestamp.desc()).paginate(page, per_page=current_app.config["IMAGES_PER_PAGE"], error_out=False) images = pagination.items return render_template("index.html", images=images, pagination=pagination, form=form, show_followed=show_followed)
def search(): form = SearchForm() form.subber.choices = form.presenter.choices = ( [(None, 'None')] + [(u.id, u.firstname + ' ' + u.lastname[0]) for u in User.query.order_by('firstname')]) if form.validate_on_submit(): query = Paper.query needles = [] u_queries = [] d_queries = [] if form.title.data: needles.append((Paper.title, form.title.data)) if form.authors.data: needles.append((Paper.authors, form.authors.data)) if form.abstract.data: needles.append((Paper.abstract, form.abstract.data)) if form.sub_date.data and (form.sub_date.data != ''): dates = [ datetime.strptime(i, '%d/%M/%Y') for i in form.sub_date.data.split('-') ] d_queries.append((Paper.timestamp, dates[0], dates[1])) if form.vote_date.data and (form.vote_date.data != ''): dates = [ datetime.strptime(i, '%d/%M/%Y') for i in form.vote_date.data.split('-') ] d_queries.append((Paper.voted, dates[0], dates[1])) if form.subber.data and (form.subber.data != 'None'): u_queries.append((Paper.subber_id, form.subber.data)) if form.presenter.data and (form.presenter.data != 'None'): u_queries.append((Paper.volunteer_id, form.presenter.data)) for needle in needles: query = query.filter(needle[0].ilike(f'%{needle[1]}%')) for d_query in d_queries: query = query.filter(d_query[0] >= d_query[1], d_query[0] <= d_query[2]) for u_query in u_queries: query = query.filter(u_query[0] == u_query[1]) papers = query.order_by(Paper.timestamp.desc()).all() return render_template('main/search.html', papers=papers, form=form, showsub=True) return render_template('main/search.html', form=form)
def search(): form = SearchForm() #popualte form db_subjects = Subject.query.order_by('name').all() db_cities = City.query.order_by('name').all() sbj_None = Subject(name='Subject', id=0) db_subjects.insert(0, sbj_None) city_None = City(name='City', id=0) db_cities.insert(0, city_None) form.subject.choices = [(g.id, g.name) for g in db_subjects] form.city.choices = [(g.id, g.name) for g in db_cities] tutors = Tutor.query.all( ) #pass it as argument in render_template to show the list of tutors available for that #selection if form.validate_on_submit(): subject = Subject.query.filter_by(id=form.subject.data).first() selected_tutors = subject.tutors print str(subject.tutors) #render only the users for that city if City is not None: city = City.query.filter_by(id=form.city.data).first() if city is not None: for t in selected_tutors: if not city.id == t.city_id: selected_tutors.remove(t) return render_template('search.html', form=form, tutors=selected_tutors) return render_template( 'search.html', form=form, tutors=tutors, unreviewed_stud_lessons=checkForStudReviews(current_user), reviewed_lessons=checkForTutReviews(current_user))
def leaderboard(): search_form = SearchForm() users = db.session.query(User) if search_form.validate_on_submit(): users = users.filter( User.username.like('%' + search_form.search.data + '%')) users = users.join(Post).join(Like).group_by(User.id).order_by( func.count().desc()) page = request.args.get('page', 1, type=int) users = users.paginate(page, current_app.config['USERS_PER_PAGE'], False) next_url = url_for('main.leaderboard', page=users.next_num) if users.has_next else None prev_url = url_for('main.leaderboard', page=users.prev_num) if users.has_prev else None return render_template('leaderboard.html', title='Leaderboard', users=users.items, next_url=next_url, prev_url=prev_url, form=search_form)
def searchAdvance(): searchForm = SearchForm() if request.method == "GET": searchForm.fromDate.data = searchForm.fromDate.data if searchForm.fromDate.data else datetime.datetime.now( ).year - 1 searchForm.toDate.data = datetime.datetime.now().year return render_template("search.html", form=searchForm) if searchForm.validate_on_submit(): regex = {} if searchForm.animal_name.data != "": regex.update({ 'animal_name': { '$regex': re.compile(searchForm.animal_name.data, re.I) } }) if searchForm.species.data != "": regex.update({ 'species': { '$regex': re.compile(searchForm.species.data, re.I) } }) if searchForm.fromDate.data and searchForm.toDate.data: fromRange = datetime.datetime(searchForm.fromDate.data, 1, 1) toRange = datetime.datetime(searchForm.toDate.data, 12, 31) regex.update( {'date_of_birth': { '$gte': fromRange, '$lte': toRange }}) return render_template("search.html", form=searchForm, results=insertAnimal.get_animals( searchForm.category.data, regex)) else: return render_template("search.html", form=searchForm)
def explore_chats(): form = SearchForm() chats = db.session.query(Chat) if form.validate_on_submit(): chats = chats.filter( Chat.name.like('%' + form.search.data + '%') | Chat.about.like('%' + form.search.data + '%')) page = request.args.get('page', 1, type=int) chats = chats.join(followers).group_by(Chat.id).order_by( func.count().desc()) chats = chats.paginate(page, current_app.config['CHATS_PER_PAGE'], False) next_url = url_for('main.explore_chats', page=chats.next_num) if chats.has_next else None prev_url = url_for('main.explore_chats', page=chats.prev_num) if chats.has_prev else None return render_template('explore_chats.html', title='Explore', chats=chats.items, next_url=next_url, prev_url=prev_url, form=form)
def popular(): search_form = SearchForm() posts = db.session.query(Post) if search_form.validate_on_submit(): posts = posts.filter( Post.title.like('%' + search_form.search.data + '%') | Post.body.like('%' + search_form.search.data + '%')) posts = posts.join(Like).group_by(Post.id).order_by(func.count().desc()) page = request.args.get('page', 1, type=int) posts = posts.paginate(page, current_app.config['POSTS_PER_PAGE'], False) next_url = url_for('main.popular', page=posts.next_num) if posts.has_next else None prev_url = url_for('main.popular', page=posts.prev_num) if posts.has_prev else None return render_template('popular.html', title='Popular', posts=posts.items, next_url=next_url, prev_url=prev_url, form=search_form, include_chat=True)
def index(): if not current_user.is_authenticated: return redirect(url_for('auth.login')) form = SearchForm() search = None results = [] if form.validate_on_submit(): try: journeys = eval(current_user.journeys) if journeys[0]['travel_address'] == '': flash('Please set up journeys in "Edit Journeys!"') return redirect(url_for('main.edit_profile')) except: current_app.logger.info( f"Failed to evaluate {journeys}. by {current_user.username}") return redirect(url_for('main.index')) potential_house = form.potential_house.data try: house_coordinates = get_coordinates(potential_house) except: flash( 'Address could not be found. Please double-check the address!') return redirect(url_for('main.index')) for journey in journeys: label = journey['label'] direction = journey['direction'] if direction == "to": origin = potential_house destination = journey['travel_address'] elif direction == "from": origin = journey['travel_address'] destination = potential_house in_json_results = [] for mode in journey['travel_modes']: duration = calculate_route(origin, destination, mode) directions_url = generate_directions_url( origin, destination, mode) in_json_result = { "mode": mode, "duration": duration, "directions_url": directions_url } in_json_results.append(in_json_result) search = { 'label': label, 'direction': direction, "arrive_by": "", "potential_house": potential_house, "house_lat": str(house_coordinates['lat']), "house_lng": str(house_coordinates['lng']), "travel_address": journey['travel_address'], "results": in_json_results } results.append(search) search = Search(searches=results, author=None) db.session.add(search) db.session.commit() return render_template('index.html', title='Home', search=search, form=form)