diff --git a/rcdb_web/select_values/veiws.py b/rcdb_web/select_values/veiws.py index dcd53b2..f8f56be 100644 --- a/rcdb_web/select_values/veiws.py +++ b/rcdb_web/select_values/veiws.py @@ -15,59 +15,50 @@ mod = Blueprint('select_values', __name__, url_prefix='/select_values') -@mod.route('/') +@mod.route('/', methods=['GET']) def index(): all_conditions = g.tdb.session.query(ConditionType).order_by(ConditionType.name.asc()).all() run_periods = g.tdb.session.query(RunPeriod).all() + run_from_str = request.args.get('runFrom', '') run_to_str = request.args.get('runTo', '') - search_query = request.args.get('q', '') - req_conditions_str = request.args.get('cnd', '') - - print(run_periods) - - return render_template("select_values/index.html", - all_conditions=all_conditions, - run_periods=run_periods, - run_from_str=run_from_str, - run_to_str=run_to_str, - search_query=search_query, - req_conditions_str=req_conditions_str) - - -@mod.route('/search', methods=['GET']) -def search(): - all_conditions = g.tdb.session.query(ConditionType).order_by(ConditionType.name.asc()).all() - run_periods = g.tdb.session.query(RunPeriod).all() - run_range = request.args.get('rr', '') - search_query = request.args.get('q', '') req_conditions_str = request.args.get('cnd', '') - req_conditions_values = req_conditions_str.split(',') - run_from_str = request.args.get('runFrom', '') - run_to_str = request.args.get('runTo', '') + # Check if there are search parameters in the URL + if 'q' in request.args: + # Handle search request + search_query = request.args.get('q', '') + run_range = request.args.get('rr', '') + req_conditions_values = req_conditions_str.split(',') - if run_from_str or run_to_str: - run_range = run_from_str + "-" + run_to_str + if run_from_str or run_to_str: + run_range = run_from_str + "-" + run_to_str - run_from, run_to = _parse_run_range(run_range) + run_from, run_to = _parse_run_range(run_range) - try: - table = g.tdb.select_values(val_names=req_conditions_values, search_str=search_query, run_min=run_from, - run_max=run_to, sort_desc=True) - except Exception as err: - flash("Error in performing request: {}".format(err), 'danger') - return redirect(url_for('select_values.index')) + try: + table = g.tdb.select_values(val_names=req_conditions_values, search_str=search_query, run_min=run_from, + run_max=run_to, sort_desc=True) + except Exception as err: + flash("Error in performing request: {}".format(err), 'danger') + return redirect(url_for('select_values.index')) - + return render_template("select_values/index.html", + all_conditions=all_conditions, + run_periods=run_periods, + run_range=run_range, + run_from=run_from, + run_to=run_to, + search_query=search_query, + req_conditions_str=req_conditions_str, + req_conditions_values=req_conditions_values, + table=table) + # Handle regular index page request return render_template("select_values/index.html", all_conditions=all_conditions, run_periods=run_periods, - run_range=run_range, - run_from=run_from, - run_to=run_to, - search_query=search_query, - req_conditions_str=req_conditions_str, - req_conditions_values=req_conditions_values, - table=table) + run_from_str=run_from_str, + run_to_str=run_to_str, + req_conditions_str=req_conditions_str) + diff --git a/rcdb_web/templates/select_values/index.html b/rcdb_web/templates/select_values/index.html index ba21bb5..8c933fc 100644 --- a/rcdb_web/templates/select_values/index.html +++ b/rcdb_web/templates/select_values/index.html @@ -5,7 +5,7 @@ {% block container %} -{{ search_box.run_search_box(condition_types=all_conditions, run_periods=run_periods, run_from=run_from, run_to=run_to, search_query=search_query, req_conditions_str=req_conditions_str, form_url=url_for("select_values.search"), show_req_conditions=True) }} +{{ search_box.run_search_box(condition_types=all_conditions, run_periods=run_periods, run_from=run_from, run_to=run_to, search_query=search_query, req_conditions_str=req_conditions_str, form_url=url_for("select_values.index"), show_req_conditions=True) }}