def yahoo_buy_search(): form = SearchForm() # flask_wtf類中提供判斷是否表單提交過來的method,不需要自行利用request.method來做判斷 if form.validate_on_submit(): return render_template('yahoo_buy_search.html', form=form, result_div=_get_data_from_db(form.input_question.data, form.input_sort.data)) # 如果不是提交過來的表單,就是GET,這時候就回傳yahoo_buy_search.html網頁 return render_template('yahoo_buy_search.html', form=form)
def hello_world(): form = SearchForm() parsed_category_list = None parsed_result_list = None if form.validate_on_submit(): result = es.search(index='schedule_overtime*', body={ "from": 0, "size": 10000, "query": { "query_string": { "query": "chain:" + form.data['chain'] + "* org:" + form.data['org'] + "*", "default_operator": "AND" } } }) result_list = result['hits']['hits'] parsed_result_list = [] parsed_category_list = result['hits']['hits'][0]['_source'].keys() for i in result_list: for k, v in i.items(): if k == u'_source': parsed_result_list.append(v.values()) return render_template('result.html', form=form, the_category=parsed_category_list, the_result=parsed_result_list)
def search(): # Форма поиска по записям form = SearchForm() # При загрузке страницы if request.method == 'GET': return render_template('search_form.html', form=form, message='По вашему запросу ничего не найдено!') # Поиск по записям if form.validate_on_submit(): # Создание сессии подключения к БД session = db_session.create_session() # Текст поиска text = form.search.data # Поиск notes = session.query(Notes).filter(Notes.user_id == current_user.id, Notes.title.like(f'%{text}%')) # Если записок несколько - сортировка по важности notes = sorted(notes, key=lambda x: x.is_important, reverse=True) # Ничего не найдено if not notes: return render_template( 'search_form.html', form=form, message='По вашему запросу ничего не найдено!') # Возвращение записок, удовлетворяющих условию return render_template('search_form.html', form=form, notes=notes)
def recipe_post(recipe_id): form = SearchForm() db_sess = db_session.create_session() recipe = db_sess.query(Recipe).get(recipe_id) author = db_sess.query(User).get(recipe.author) lks = loads(recipe.likers) like_btn = LikeButton() if current_user.is_authenticated and current_user.id not in lks else DislikeButton() if form.query_field.data: return redirect(f'/search?query={form.query_field.data}') if current_user.is_authenticated and current_user.id in lks and like_btn.is_submitted(): recipe.likes_count -= 1 print('-') lks.remove(author.id) if current_user.is_authenticated and current_user.id not in lks and like_btn.is_submitted(): recipe.likes_count += 1 print('+') lks.append(author.id) if current_user.is_anonymous and like_btn.is_submitted(): flash('You have to log in') recipe.likers = dumps(lks) db_sess.commit() recipe.views_count += 1 return render_template('recipe_post.html', form=form, recipe=recipe, author=author, like_btn=like_btn, json_ingredients=loads(recipe.ingredients), json_tags=loads(recipe.tags))
def index(): form = SearchForm() if form.query_field.data: return redirect(f'/search?query={form.query_field.data}') db_sess = db_session.create_session() cotw_list = db_sess.query(Recipe).filter(Recipe.cotw == True) hot_list = db_sess.query(Recipe).order_by(desc(Recipe.likes_count / Recipe.views_count)) return render_template('index.html', form=form, cotw_list=cotw_list, hot_list=hot_list)
def search(): form = SearchForm() if form.query_field.data: return redirect(f'/search?query={form.query_field.data}') keyword = request.args.get('query') db_sess = db_session.create_session() recipes_list = db_sess.query(Recipe).filter((Recipe.name.like(f"%{keyword}%")) | (Recipe.tags.like(f"%{keyword}%"))) return render_template('recipes.html', recipes_list=recipes_list, form=form)
def account(name): form = SearchForm() db_sess = db_session.create_session() profile = db_sess.query(User).filter(User.nickname == name).first() recipes_list = db_sess.query(Recipe).filter(Recipe.author == profile.id) return render_template('account.html', profile=profile, recipes_list=recipes_list, form=form)
def login(): form = SearchForm() return render_template('log_analysis.html', title='Web Log Analyzer', form=form)
def __init__(self, user, password): self.api = API(user, password) self.form = SearchForm(parent=self)
def not_found(error): form = SearchForm() return render_template('404.html', form=form)
def all_recipes(): form = SearchForm() db_sess = db_session.create_session() recipes = db_sess.query(Recipe).all() return render_template('recipes.html', form=form, recipes_list=recipes)
def search_form(self): from search_form import SearchForm if self._search_form is None: self._search_form = SearchForm(self.driver) return self._search_form
def egbot(): bfx = BitfinexREST() bfx.load_key('.key/read-key') form = SearchForm() # TODO add form functionality to select crypto and dynamically update list egbot_result = None egbot_header = None active_summary = None summary_header = None position = None position_header = None ticker = None ticker_header = None symbol = None inactive_summary = None inactive_summary_header = None dao = EgbotDAO() trials_dict = dao.get_all_trials_by_crypto() trials_list = [] for k, v in trials_dict.items(): for trial in v: str_trial = str(trial) str_trial = k + ': ' + str_trial trials_list.append((str_trial, str_trial)) form.trial.choices = trials_list if form.validate_on_submit(): crypto = form.data['trial'][0:6] trial_string = form.data['trial'][8:] trial_datetime = datetime.strptime(trial_string, '%Y-%m-%d %H:%M:%S.%f') orders = dao.get_order_data_for_trial(crypto, trial_datetime) egbot_header = orders[0].keys() egbot_result = [list(x.values()) for x in orders] for x in egbot_result: x[2] = datetime.utcfromtimestamp(float(x[2])) active_positions = bfx.get_active_positions(crypto) active_summary, inactive_summary = bfx.get_summary( egbot_result, active_positions, crypto) summary_header = active_summary.keys() active_summary = list(active_summary.values()) inactive_summary_header = inactive_summary.keys() inactive_summary = list(inactive_summary.values()) if active_positions: position_header = active_positions[0].keys() position = [list(x.values()) for x in active_positions] tick = bfx.get_ticker(crypto) ticker = list(tick.values()) ticker_header = list(tick.keys()) symbol = crypto.upper() symbol = symbol[0:3] return render_template('base.html', form=form, the_egbot_header=egbot_header, the_egbot_result=egbot_result, the_summary_header=summary_header, the_summary=active_summary, the_inactive_summary_header=inactive_summary_header, the_inactive_summary=inactive_summary, the_position_header=position_header, the_position=position, the_ticker=ticker, the_ticker_header=ticker_header, the_ticker_symbol=symbol)