Skip to content

Commit

Permalink
Merge select_value/index and select_values/search
Browse files Browse the repository at this point in the history
  • Loading branch information
sqrd-max committed Dec 7, 2023
1 parent b952083 commit e3dd627
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 42 deletions.
73 changes: 32 additions & 41 deletions rcdb_web/select_values/veiws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

2 changes: 1 addition & 1 deletion rcdb_web/templates/select_values/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}

<div class="container">

Expand Down

0 comments on commit e3dd627

Please sign in to comment.