Skip to content

Commit

Permalink
Fix #278 - Ordered search keep order through pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed May 3, 2022
1 parent 697f72e commit 3d360e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions app/main/views/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,17 @@ def tokens_search_through_fields(corpus_id):

# there is at least one OR clause
# get sort arguments (sort per default by WordToken.order_id)
order_by_key = request.args.get("orderBy")
order_by = {
"order_id": WordToken.order_id,
"lemma": func.lower(WordToken.lemma),
"pos": func.lower(WordToken.POS),
"form": func.lower(WordToken.form),
"morph": func.lower(WordToken.morph),
}.get(request.args.get("orderBy"), WordToken.order_id)

}
if order_by_key not in order_by:
order_by_key = "order_id"
order_by = order_by.get(order_by_key)
args = []

if len(value_filters) > 1:
Expand All @@ -348,6 +351,8 @@ def tokens_search_through_fields(corpus_id):
return render_template_with_nav_info('main/tokens_search_through_fields.html',
search_kwargs={"corpus_id": corpus.id, **input_values},
changed=corpus.changed(tokens.items),
desc=request.args.get("desc", "0"),
orderBy=order_by_key,
corpus=corpus, tokens=tokens, **input_values)


Expand Down
6 changes: 4 additions & 2 deletions app/templates/main/tokens_search_through_fields.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ <h2>{{ tokens.total }} match{% if tokens.total > 1 %}es {% endif %} found</h2>

<div id="result_table" class="mt-3">
{{ nav.render_pagination(pagination=tokens, corpus_id=corpus.id, endpoint="main.tokens_search_through_fields",
lemma=lemma, morph=morph, POS=POS, form=form, get_params=["lemma", "morph", "POS", "form"]) }}
lemma=lemma, morph=morph, POS=POS, form=form, orderBy=orderBy, desc=desc,
get_params=["lemma", "morph", "POS", "form", "orderBy", "desc"]) }}

{{ tokens_macros.table(tokens, corpus=corpus, changed=changed, editable=True, similar=True, sortable=True, link_back=True, search_kwargs=search_kwargs, endpoint="main.tokens_search_through_fields") }}

{{ nav.render_pagination(pagination=tokens, corpus_id=corpus.id, endpoint="main.tokens_search_through_fields",
lemma=lemma, morph=morph, POS=POS, form=form, get_params=["lemma", "morph", "POS", "form"]) }}
lemma=lemma, morph=morph, POS=POS, form=form,
get_params=["lemma", "morph", "POS", "form", "orderBy", "desc"]) }}
</div>

{% endif %}
Expand Down

0 comments on commit 3d360e1

Please sign in to comment.