chg: [title search] add pagination

This commit is contained in:
Terrtia 2023-06-14 10:38:33 +02:00
parent d4152462f5
commit f3946cc4f3
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
3 changed files with 42 additions and 8 deletions

View file

@ -19,6 +19,7 @@ sys.path.append(os.environ['AIL_BIN'])
##################################
# Import Project packages
##################################
from lib.ail_core import paginate_iterator
from lib.objects import Titles
from packages import Date
@ -72,14 +73,37 @@ def objects_title_range_json():
date_to = date['date_to']
return jsonify(Titles.Titles().api_get_chart_nb_by_daterange(date_from, date_to))
@objects_title.route("/objects/title/search", methods=['POST'])
@objects_title.route("/objects/title/search_post", methods=['POST'])
@login_required
@login_read_only
def objects_title_search():
@login_analyst
def objects_title_search_post():
to_search = request.form.get('to_search')
type_to_search = request.form.get('search_type', 'id')
search_type = request.form.get('search_type', 'id')
case_sensitive = request.form.get('case_sensitive')
case_sensitive = bool(case_sensitive)
page = request.form.get('page', 1)
try:
page = int(page)
except (TypeError, ValueError):
page = 1
return redirect(
url_for('objects_title.objects_title_search', search=to_search, page=page,
search_type=search_type, case_sensitive=case_sensitive))
@objects_title.route("/objects/title/search", methods=['GET'])
@login_required
@login_analyst
def objects_title_search():
to_search = request.args.get('search')
type_to_search = request.args.get('search_type', 'id')
case_sensitive = request.args.get('case_sensitive')
case_sensitive = bool(case_sensitive)
page = request.args.get('page', 1)
try:
page = int(page)
except (TypeError, ValueError):
page = 1
titles = Titles.Titles()
if type_to_search == 'id':
@ -97,9 +121,12 @@ def objects_title_search():
return create_json_response({'error': 'Unknown search type'}, 400)
if search_result:
dict_objects = titles.get_metas(search_result.keys(), options={'sparkline'})
ids = sorted(search_result.keys())
dict_page = paginate_iterator(ids, nb_obj=500, page=page)
dict_objects = titles.get_metas(dict_page['list_elem'], options={'sparkline'})
else:
dict_objects = {}
return render_template("search_title_result.html", dict_objects=dict_objects, search_result=search_result,
dict_page=dict_page,
to_search=to_search, case_sensitive=case_sensitive, type_to_search=type_to_search)

View file

@ -1,8 +1,9 @@
<div class="card border-secondary my-2">
<div class="card-body text-dark">
<h5 class="card-title">Titles Search:</h5>
<form action="{{ url_for('objects_title.objects_title_search') }}" id="search_subtype_onj" method='post'>
<form action="{{ url_for('objects_title.objects_title_search_post') }}" id="search_subtype_onj" method='post'>
<div class="input-group mb-1">
<input type="text" name="page" value="{% if page %}{{ page }}{% else %}1{% endif %}" hidden="">
<select class="custom-select col-2" name="search_type" value="{% if type_to_search %}{{ type_to_search }}{% else %}content{% endif %}" required>
<option value="content">Content Search</option>
<option value="id" {% if type_to_search %}{% if type_to_search == "id" %}selected{% endif %}{% endif %}>ID Search</option>

View file

@ -35,8 +35,9 @@
<div class="col-12 col-lg-10" id="core_content">
{% with page=dict_page['page'] %}
{% include 'title/block_titles_search.html' %}
{% endwith %}
<table id="table_objects" class="table table-striped table-bordered">
@ -70,6 +71,11 @@
</tbody>
</table>
{% with page=dict_page['page'], nb_page_max=dict_page['nb_pages'], nb_first_elem=dict_page['nb_first_elem'], nb_last_elem=dict_page['nb_last_elem'], nb_all_elem=dict_page['nb_all_elem'] %}
{% set target_url=url_for('objects_title.objects_title_search') + "?search=" + to_search + "&search_type=" + type_to_search + "&case_sensitive=" + case_sensitive|string %}
{% include 'pagination.html' %}
{% endwith %}
</div>
</div>
</div>