def search(): form = SearchForm() if form.validate_on_submit(): coin = form.user_input.data coin = str(coin).replace(" ", "-").lower() return redirect(url_for('.search_coin', coin=coin)) return render_template('search.html', title='Search Coins', form=form)
def search(): """ Handles searching for tv shows or movies. """ # Generate the form form = SearchForm() # If the user has submitted a POST request, it will be validated below. if form.validate_on_submit(): # Retrieve show/movie title and whether it actually is a tv show or movie form_title = form.title.data form_type = form.type.data # Perform necessary searches if form_type == 'tv': results = search_tv(form_title) else: results = search_movie(form_title) # Display results form = QuickAddForm() return render_template('results.html', results=results, type=form_type, form=form) # If the request was GET, render the register page with the search form. return render_template('search.html', form=form)
def buy(): form = SearchForm() if form.validate_on_submit(): items = Item.query.whoosh_search(form.query.data).all() else: items = Item.query.order_by(Item.post_date.desc()).all() return render_template("market/buy.html", buy="active", items=items, form=form)
def product(page, filter=None, data=None): if filter == None: listOfProduct = Product.query.all() elif filter == 'old': oldProductPhotos = Productphoto.query.filter_by(photo_status=3).all() listOfProduct = [] for photo in oldProductPhotos: listOfProduct.append(photo.photo) elif filter == 'search': listOfProduct = Product.query.filter( Product.name.like('%{}%'.format(data))).all() listOfProducts = listOfProduct * 20 productsStore = [[[ 0 if i + j * 9 + k * 3 >= len(listOfProducts) else listOfProducts[i + j * 9 + k * 3] for i in range(3) ] for k in range(3)] for j in range(math.ceil(len(listOfProducts) / 9))] numberOfPages = len(productsStore) products = productsStore[int(page) - 1] categories = Category.query.all() form = SearchForm() if form.validate_on_submit(): searchData = form.search.data return redirect( url_for('product', page=1, filter='search', data=searchData)) return render_template('product.html', categories=categories, products=products, zip=zip, numberOfPages=numberOfPages, page=int(page), filter=filter, data=data, form=form)
def search(): form = SearchForm() if form.validate_on_submit(): if form.search.data: user = form.search.data return redirect(url_for('user_posts', username=user)) return render_template('search.html', form=form)
def home(title='Home'): """Home page""" form = SearchForm() # Get links using Wikipedia's search API if form.validate_on_submit(): search_term = '_'.join(form.data['search_term'].split()) flash(search_term) search_api = 'http://en.wikipedia.org/w/api.php?action=opensearch&search=' + search_term headers = { 'Host': 'en.wikipedia.org', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0', 'Accept': '*/*', 'Accept-Language': 'en-US,en;q=0.5', 'Accept-Encoding': 'gzip, deflate', 'DNT': 1, 'Referer': 'http://www.wikipedia.org/', 'Connection': 'keep-alive' } response = json.loads(requests.get(search_api, headers=headers).text) session['links'] = response[ 3] # store links in a session object to be obtained during next request print response print response[3] return redirect('/search_results') return render_template('home.html', title=title, form=form)
def history(): mylist_all = WatchHistory.query.with_entities( WatchHistory.movieid).filter_by(userid=current_user.userid).all() mylist = [i[0] for i in mylist_all] my_movies_history = Movies.query.filter(Movies.movieid.in_(mylist)).all() likes_all = Likes.query.with_entities( Likes.movieid).filter_by(userid=current_user.userid).all() likes = [i[0] for i in likes_all] mylist_all = MyList.query.with_entities( MyList.movieid).filter_by(userid=current_user.userid).all() mylist = [i[0] for i in mylist_all] form = SearchForm() if form.validate_on_submit(): return redirect(url_for('search', search_text=form.search_field.data)) image_file = url_for('static', filename='profile_pics/' + current_user.image_file) return render_template('myhistory.html', title='Watch History', form=form, image_file=image_file, history=my_movies_history, likes=likes, mylist=mylist)
def latest(): views_all = Views.query.with_entities(Views.movieid).order_by( Views.views.desc()).limit(20).all() most_views = [i[0] for i in views_all] trending = Movies.query.filter( Movies.movieid.in_(most_views)).limit(20).all() new_movies = Movies.query.filter( Movies.release_year.in_(["2019", "2018", "2017"])).order_by( Movies.release_year.desc()).limit(20).all() likes_all = Likes.query.with_entities( Likes.movieid).filter_by(userid=current_user.userid).all() likes = [i[0] for i in likes_all] mylist_all = MyList.query.with_entities( MyList.movieid).filter_by(userid=current_user.userid).all() mylist = [i[0] for i in mylist_all] form = SearchForm() if form.validate_on_submit(): return redirect(url_for('search', search_text=form.search_field.data)) image_file = url_for('static', filename='profile_pics/' + current_user.image_file) return render_template('latest.html', title='Latest', image_file=image_file, form=form, trending=trending, likes=likes, mylist=mylist, new_movies=new_movies)
def index(): form = SearchForm() if form.validate_on_submit(): render_template('index.html', form=form) else: flash_errors(form) return render_template('index.html', form=form)
def index_update(): form = SearchForm() error = None from_day = None to_day = None teacher = None lessons = {} if form.validate_on_submit(): group = form.groupname.data from_day = form.from_day.data to_day = form.to_day.data teacher = form.teacher.data try: group_record = Group.query.filter_by(name=group).first() lessons = utils.get_lessons_range(group_record, from_day, to_day) app.logger.info(lessons) except SQLAlchemyError as e: error = "Incorrect input data!" return render_template('index.html', form=form, day_schedule=lessons, error=error)
def user(username): user = User.query.filter_by(username=username).first_or_404() page = request.args.get('page', 1, type=int) posts = user.posts.order_by(Post.timestamp.desc()).paginate( page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('user', username=user.username, page=posts.next_num) \ if posts.has_next else None prev_url = url_for('user', username=user.username, page=posts.prev_num) \ if posts.has_prev else None form = SearchForm() if form.validate_on_submit(): username_search = request.form["search"] check_db = db.session.query( User.username).filter(User.username == username_search).scalar() if check_db == None: flash('Användaren finns inte!') return render_template('user.html', form=form, drop_down_cats=drop_down_cats, user=user, posts=posts.items, next_url=next_url, prev_url=prev_url) else: return redirect(url_for('user', username=username_search)) return render_template('user.html', form=form, drop_down_cats=drop_down_cats, user=user, posts=posts.items, next_url=next_url, prev_url=prev_url)
def search(search_text): likes_all = Likes.query.with_entities( Likes.movieid).filter_by(userid=current_user.userid).all() likes = [i[0] for i in likes_all] mylist_all = MyList.query.with_entities( MyList.movieid).filter_by(userid=current_user.userid).all() mylist = [i[0] for i in mylist_all] x = query_index('movies', search_text, 1, 100) s = [i['_id'] for i in x] search_results = Movies.query.filter(Movies.movieid.in_(s)).all() form = SearchForm() if form.validate_on_submit(): return redirect(url_for('search', search_text=form.search_field.data)) image_file = url_for('static', filename='profile_pics/' + current_user.image_file) return render_template('search.html', title='Search Results', search_text=search_results, image_file=image_file, form=form, likes=likes, my_list=mylist)
def search(): from app.forms import SearchForm form = SearchForm() if form.validate_on_submit(): from app.models import BookTable bt = BookTable() search_query = "%" + str(form.search.data) + "%" books = bt.search_books(search_query) return render_template("search.html", form=form, count_books=len(books), books=books, searched=True) return render_template("search.html", form=form, count_books=0, books=[], searched=False)
def search(): form = SearchForm() template = 'search.html' if form.validate_on_submit(): if (form.zipcode.data is "" and form.city.data is "" and form.state.data is ""): flash('Please fill in a field to search') return render_template(template, title='search', config=site_config, form=form) locations = search_locations(form) return render_template(template, title='search', config=site_config, form=form, locations=locations) return render_template(template, title='search', config=site_config, form=form)
def search(dishname): form = SearchForm() if form.validate_on_submit(): return redirect(url_for('search', dishname=form.search.data)) dishes = Dishes.query.all() for dish in dishes: if dish.dishname.upper() == dishname.upper(): if not current_user.is_anonymous: quantity = Quantity.query.filter_by(customer=current_user) \ .filter_by(dish=dish).first() return render_template('search.html', title='Search', dish=dish, quantity=quantity, next_page='search', form=form) else: return render_template('search.html', title='Search', dish=dish, next_page='search', form=form) flash("Sorry, this dish is not available here.") return redirect(url_for('index'))
def index(): form = SearchForm() message = None lessons = {} if form.validate_on_submit(): group = form.groupname.data from_day = form.from_day.data to_day = form.to_day.data teacher = form.teacher.data group = Group.query.filter_by(name=group).first() if not group: flash(f'Group not found', 'info') return redirect(url_for('index')) pib_len = 3 if not teacher: lessons = utils.get_lessons_range(group, from_day, to_day) elif len(teacher.split()) == pib_len: name, surname, patronymic = teacher.split() teacher = utils.get_teacher(name, surname, patronymic) lessons = utils.get_lessons_range_with_teacher( group, teacher, from_day, to_day) else: flash('Teacher not found', 'info') return redirect(url_for('index')) if not lessons: flash(f'No lessons for this period', 'info') return redirect(url_for('index')) return render_template('index.html', form=form, day_schedule=lessons)
def index(): form = SearchForm() g.search_form = SearchForm() if form.validate_on_submit(): ... return redirect('/result') return render_template('search.html', title='Search', form=form)
def signup(): search = SearchForm() if request.method == 'POST' and search.validate_on_submit(): return redirect((url_for('search_page', searchQuery=search.searchParam.data))) if session.get('logged_in') == True: return redirect(url_for('index')) form = SignupForm() if form.validate_on_submit(): name = form.restaurant_name.data email = form.restaurant_email.data phone = form.restaurant_phone.data zipcode = form.restaurant_zipcode.data address = form.restaurant_street.data + form.restaurant_city.data + form.restaurant_state.data new_seller = seller(seller_name=name, seller_email=email, seller_phone=phone, seller_zipcode=zipcode, seller_address=address) new_seller.set_password(form.restaurant_password.data) db.session.add(new_seller) db.session.commit() session["user_id"] = new_seller.seller_id session["logged_in"] = True return redirect(url_for('index')) return render_template('signup.html', title='Sign Up', form=form, search=search)
def mysql_time(): query = "" search_value = "" current_page = "mysql_time" title = "MySQL Time-Based" form = SearchForm() if form.validate_on_submit(): search_value = form.search.data query = f"SELECT * FROM MOCK_DATA WHERE `email` = '{form.search.data}';" execute_query(query) return render_template( "time.j2.html", title=title, form=form, search_value=search_value, current_page=current_page, query=query, success=True, ) return render_template( "time.j2.html", title=title, form=form, search_value=search_value, current_page=current_page, query=query, )
def search(): form = SearchForm() search_results = [] numMarketing = len( list(db.openings.find({"$text": { "$search": 'marketing' }}))) numEngineer = len( list(db.openings.find({"$text": { "$search": 'engineer' }}))) numSales = len(list(db.openings.find({"$text": {"$search": 'sales'}}))) if form.validate_on_submit(): search_results = list( db.openings.find({"$text": { "$search": form.search.data }})) num_results = len(search_results) return render_template('search_results.html', form=form, results=search_results[:10], start=0, end=10, page=1, total=2, q=form.search.data, num_results=num_results) return render_template('search.html', numMarketing=numMarketing, numEngineer=numEngineer, numSales=numSales, form=form)
def search(): form = SearchForm() if form.validate_on_submit(): src = string(request.args[src]) return '''<h1>The Source is {}</h1>'''.format(src) return render_template('search.html', title='Search Pcap', form=form)
def index(): requests = Request.query.all() search = SearchForm(request.form) search.origin.choices = sorted(app.config['LOCATIONS'], key=lambda x: x[1]) search.destination.choices = sorted(app.config['LOCATIONS'], key=lambda x: x[1]) if search.validate_on_submit(): if search.destination.data == search.origin.data: flash("Origin and Destination cannot be the same") else: return redirect( url_for('search_results', origin=search.origin.data, destination=search.destination.data, date=search.date.data)) if current_user.is_authenticated: return render_template('index.html', user=current_user, requests=requests, form=search) else: return render_template('index.html')
def search(): form = SearchForm() if form.validate_on_submit(): search_term = form.search_term.data return redirect(url_for('gallery', search_term=search_term)) return redirect(url_for('home'))
def search(): form = SearchForm() if form.validate_on_submit(): flash('Success search') data = { 'query': form.query.data, 'order': form.order.data, 'reviewer': form.reviewer.data } if form.publication_start.data is not None: if form.publication_end.data is not None: data.update({ 'publication-date': form.publication_start.data + ';' + form.publication_end.data }) else: data.update({'publication-date': form.plulication_start}) if form.opening_start.data is not None: if form.opening_end.data is not None: data.update({ 'opening-date': form.opening_start.data + ';' + form.opening_end.data }) else: data.update({'opening-date': form.opening_start.data}) if form.critics_pick.data: data.update({'critics-pick': 'Y'}) query = {k: v for k, v in data.items() if data[k] is not None} movies = get_movies(query) return render_template('result.html', title='Result', movies=movies) return render_template('search.html', title='Search', form=form)
def index(): form = SearchForm() if form.validate_on_submit(): interface = SearchInterface() interface.search_job(form.query.data) return render_template('results.html', form=form, interface=interface) return render_template('index.html', title='Sign In', form=form)
def mysql_sqli(): form = SearchForm() if form.validate_on_submit(): search_value = form.search.data query = ("SELECT * FROM MOCK_DATA WHERE `first_name` LIKE '%" + form.search.data + "%' LIMIT 10;") data, error = execute_query(query) query = query.split("--")[0] return render_template( "table.j2.html", title="MySQL Union", form=form, data=data, search_value=search_value, query=query, current_page="mysql_sqli", error=error, record_count=len(data), ) query = "SELECT * FROM MOCK_DATA LIMIT 10;" data, error = execute_query(query) query = query.split("--")[0] return render_template( "table.j2.html", title="MySQL Union", form=form, data=data, search_value="", query=query, current_page="mysql_sqli", error=error, record_count=len(data), )
def search(): form = SearchForm() if form.validate_on_submit(): c = int(form.category.data) s = form.search.data if c == 0: # автор writer = Writer.query.filter_by(name=s).first() if writer: return redirect(url_for('writer', writer_id=writer.id)) else: return render_template('search.html', title="Поиск", form=form, err=True) elif c == 1: # книга book = Book.query.filter_by(title=s).first() if book: return redirect(url_for('book', book_id=book.id)) else: return render_template('search.html', title="Поиск", form=form, err=True) elif c == 2: # комментарий user = User.query.filter_by(login=s).first() if user: return redirect(url_for('user', user_id=user.id)) else: return render_template('search.html', title="Поиск", form=form, err=True) return render_template('search.html', title="Поиск", form=form, err=False)
def hosts_search(): # print("WORKING!!!!!!!") hosts = Host.query.all() form = SearchForm() form['csrf_token'].data = request.cookies['csrf_token'] if form.validate_on_submit(): search = form.data['search'] if search: search = search.lower() sommelier = form.data['sommelier'] mixologist = form.data['mixologist'] if search == "": if sommelier == True and mixologist == True: data = Host.query.filter((Host.sommelier == True) & (Host.mixologist == True)).order_by( Host.state).order_by( Host.last_name).all() elif sommelier == True and mixologist == False: data = Host.query.filter((Host.sommelier == True)).all() elif mixologist == True and sommelier == False: data = Host.query.filter((Host.mixologist == True)).all() else: data = Host.query.all() else: if sommelier == True and mixologist == True: data = Host.query.filter( or_( func.lower(Host.first_name).like(f"{search}%"), func.lower(Host.last_name).like(f"{search}%"), func.lower(Host.state).like(f"{search}%"), func.lower(Host.city).like(f"{search}%")) & (Host.sommelier == True) & (Host.mixologist == True)).all() elif sommelier == True and mixologist == False: data = Host.query.filter( or_( func.lower(Host.first_name).like(f"{search}%"), func.lower(Host.last_name).like(f"{search}%"), func.lower(Host.state).like(f"{search}%"), func.lower(Host.city).like(f"{search}%")) & (Host.sommelier == True)).all() elif mixologist == True and sommelier == False: data = Host.query.filter( or_( func.lower(Host.first_name).like(f"{search}%"), func.lower(Host.last_name).like(f"{search}%"), func.lower(Host.state).like(f"{search}%"), func.lower(Host.city).like(f"{search}%")) & (Host.mixologist == True)).all() else: data = Host.query.filter( or_( func.lower(Host.first_name).like(f"{search}%"), func.lower(Host.last_name).like(f"{search}%"), func.lower(Host.state).like(f"{search}%"), func.lower(Host.city).like(f"{search}%"))) # print("THISSTUFF!!!!", [host.to_dict() for host in data]) return {"hosts": [host.to_dict() for host in data]}
def search(): form = SearchForm() if form.validate_on_submit(): stats = teamsfranchises.query.filter_by( franchName=form.team.data).all() teamStats = teams.query.filter_by(yearID=form.yearID.data).join( teamsfranchises, teamsfranchises.franchID == teams.franchID).filter_by( franchName=form.team.data).all() batStats = batting.query.filter_by(yearID=form.yearID.data).join( teams, teams.teamID == batting.teamID).join( teamsfranchises, teamsfranchises.franchID == teams.franchID).filter_by( franchName=form.team.data).all() for row in batStats: if row.pa is None: row.setValues() pitchStats = pitching.query.filter_by(yearID=form.yearID.data).join( teams, teams.teamID == pitching.teamID).join( teamsfranchises, teamsfranchises.franchID == teams.franchID).filter_by( franchName=form.team.data).all() for row in pitchStats: if row.ip is None: row.setIP() fieldingStats = fielding.query.filter_by(yearID=form.yearID.data).join( teams, teams.teamID == fielding.teamID).join( teamsfranchises, teamsfranchises.franchID == teams.franchID).filter_by( franchName=form.team.data).all() # I'm afraid this query is incorrect in its calculation for all players on the team. I was trying to figure out the union operator from SQL Alchemy but i couldn't figure it out in time. I would assume that you would use the union operator and separate queries for the three positions (fielding, batting, and pitching) to find all of the players on the team. players = people.query.join( pitching, pitching.playerID == people.playerID).join( batting, batting.playerID == people.playerID).filter_by( yearID=form.yearID.data).join( teamsfranchises, teamsfranchises.franchID == batting.teamID).filter_by( franchName=form.team.data).all() teamManagers = managers.query.filter_by(yearID=form.yearID.data).join( teamsfranchises, teamsfranchises.franchID == managers.teamID).filter_by( franchName=form.team.data).all() return render_template('search.html', title='Results', form=form, stats=stats, batStats=batStats, pitchStats=pitchStats, teamManagers=teamManagers, players=players, teamStats=teamStats) return render_template('search.html', title='Search', form=form)
def search(): form = SearchForm() if form.validate_on_submit(): results = ts.searching(form.word.data, form.number_of_res.data) return render_template("results.html", title="Results", results=results) return render_template("search.html", title="Search", form=form)
def index(): form = SearchForm() if form.validate_on_submit(): search = form.search.data return redirect(url_for('results', search=search)) return render_template('index.html', title='Home', form=form)
def dispatch_request(self, t="search.html"): book_mgr = BookAbstraction() author_mgr = AuthorAbstraction() result = [] form = SearchForm() if request.method == 'POST': if form.validate_on_submit(): if len(form.search.data) < 2: return redirect(url_for('search')) result = book_mgr.book_search(form.search.data) result.extend(author_mgr.author_search(form.search.data)) if not result: result = "No books found" else: result = set(result) return render_template(t, form=form, result=result, page_title='Search', user=current_user)