Verified Commit bfd59229 authored by Kevin Morris's avatar Kevin Morris
Browse files

change: display default package search parameter values in its form



The previous behavior was carried over from PHP. It has been requested
that we use the true defaults when rendering the default form, making
search a bit more sensible.

Closes #269

Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 0bfecb98
...@@ -40,7 +40,7 @@ async def packages_get(request: Request, context: Dict[str, Any], ...@@ -40,7 +40,7 @@ async def packages_get(request: Request, context: Dict[str, Any],
search_by = context["SeB"] = request.query_params.get("SeB", "nd") search_by = context["SeB"] = request.query_params.get("SeB", "nd")
# Query sort by. # Query sort by.
sort_by = context["SB"] = request.query_params.get("SB", "p") sort_by = request.query_params.get("SB", None)
# Query sort order. # Query sort order.
sort_order = request.query_params.get("SO", None) sort_order = request.query_params.get("SO", None)
...@@ -93,13 +93,6 @@ async def packages_get(request: Request, context: Dict[str, Any], ...@@ -93,13 +93,6 @@ async def packages_get(request: Request, context: Dict[str, Any],
# Apply user-specified specified sort column and ordering. # Apply user-specified specified sort column and ordering.
search.sort_by(sort_by, sort_order) search.sort_by(sort_by, sort_order)
# If no SO was given, default the context SO to 'a' (Ascending).
# By default, if no SO is given, the search should sort by 'd'
# (Descending), but display "Ascending" for the Sort order select.
if sort_order is None:
sort_order = "a"
context["SO"] = sort_order
# Insert search results into the context. # Insert search results into the context.
results = search.results().with_entities( results = search.results().with_entities(
models.Package.ID, models.Package.ID,
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
</div> </div>
<div> <div>
<label for="id_sort_by">{{ "Sort by" | tr }}</label> <label for="id_sort_by">{{ "Sort by" | tr }}</label>
{% if not SB %}
{% set SB = 'p' %}
{% endif %}
<select name='SB'> <select name='SB'>
<option value='n' {% if SB == "n" %}selected{% endif %}>{{ "Name" | tr }}</option> <option value='n' {% if SB == "n" %}selected{% endif %}>{{ "Name" | tr }}</option>
<option value='v' {% if SB == "v" %}selected{% endif %}>{{ "Votes" | tr }}</option> <option value='v' {% if SB == "v" %}selected{% endif %}>{{ "Votes" | tr }}</option>
...@@ -46,6 +49,9 @@ ...@@ -46,6 +49,9 @@
</div> </div>
<div> <div>
<label for="id_order_by">{{ "Sort order" | tr }}</label> <label for="id_order_by">{{ "Sort order" | tr }}</label>
{% if not SO %}
{% set SO = 'd' %}
{% endif %}
<select name='SO'> <select name='SO'>
<option value='a' {% if SO == "a" %}selected{% endif %}>{{ "Ascending" | tr }}</option> <option value='a' {% if SO == "a" %}selected{% endif %}>{{ "Ascending" | tr }}</option>
<option value='d' {% if SO == "d" %}selected{% endif %}>{{ "Descending" | tr }}</option> <option value='d' {% if SO == "d" %}selected{% endif %}>{{ "Descending" | tr }}</option>
......
{% set reverse_order = "d" if SO == "a" else "a" %}
<table {% if table_id %}id="{{ table_id }}"{% endif %} class="results"> <table {% if table_id %}id="{{ table_id }}"{% endif %} class="results">
<thead> <thead>
<tr> <tr>
...@@ -5,9 +7,10 @@ ...@@ -5,9 +7,10 @@
<th></th> <th></th>
{% endif %} {% endif %}
<th> <th>
{% set order = SO %}
{% if SB == "n" %} {% if SB == "n" %}
{% set order = "d" if order == "a" else "a" %} {% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %} {% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'n'), ('SO', order)) | urlencode }}"> <a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'n'), ('SO', order)) | urlencode }}">
{{ "Name" | tr }} {{ "Name" | tr }}
...@@ -15,35 +18,39 @@ ...@@ -15,35 +18,39 @@
</th> </th>
<th>{{ "Version" | tr }}</th> <th>{{ "Version" | tr }}</th>
<th> <th>
{% set order = SO %}
{% if SB == "v" %} {% if SB == "v" %}
{% set order = "d" if order == "a" else "a" %} {% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %} {% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'v'), ('SO', order)) | urlencode }}"> <a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'v'), ('SO', order)) | urlencode }}">
{{ "Votes" | tr }} {{ "Votes" | tr }}
</a> </a>
</th> </th>
<th> <th>
{% set order = SO %}
{% if SB == "p" %} {% if SB == "p" %}
{% set order = "d" if order == "a" else "a" %} {% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %} {% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'p'), ('SO', order)) | urlencode }}">{{ "Popularity" | tr }}</a><span title="{{ 'Popularity is calculated as the sum of all votes with each vote being weighted with a factor of %.2f per day since its creation.' | format(0.98) }}" class="hover-help"><sup>?</sup></span> <a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'p'), ('SO', order)) | urlencode }}">{{ "Popularity" | tr }}</a><span title="{{ 'Popularity is calculated as the sum of all votes with each vote being weighted with a factor of %.2f per day since its creation.' | format(0.98) }}" class="hover-help"><sup>?</sup></span>
</th> </th>
{% if request.user.is_authenticated() %} {% if request.user.is_authenticated() %}
<th> <th>
{% set order = SO %}
{% if SB == "w" %} {% if SB == "w" %}
{% set order = "d" if order == "a" else "a" %} {% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %} {% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'w'), ('SO', order)) | urlencode }}"> <a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'w'), ('SO', order)) | urlencode }}">
{{ "Voted" | tr }} {{ "Voted" | tr }}
</a> </a>
</th> </th>
<th> <th>
{% set order = SO %}
{% if SB == "o" %} {% if SB == "o" %}
{% set order = "d" if order == "a" else "a" %} {% set order = reverse_order %}
{% else %}
{% set order = SO %}
{% endif %} {% endif %}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'o'), ('SO', order)) | urlencode }}"> <a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'o'), ('SO', order)) | urlencode }}">
{{ "Notify" | tr }} {{ "Notify" | tr }}
...@@ -52,13 +59,14 @@ ...@@ -52,13 +59,14 @@
{% endif %} {% endif %}
<th>{{ "Description" | tr }}</th> <th>{{ "Description" | tr }}</th>
<th> <th>
{% if SB == "m" %}
{% set order = reverse_order %}
{% else %}
{% set order = SO %} {% set order = SO %}
{% if SB == "m" %} {% endif %}
{% set order = "d" if order == "a" else "a" %} <a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'm'), ('SO', order)) | urlencode }}">
{% endif %} {{ "Maintainer" | tr }}
<a href="/packages?{{ q | extend_query(('O', 0), ('SB', 'm'), ('SO', order)) | urlencode }}"> </a>
{{ "Maintainer" | tr }}
</a>
</th> </th>
</tr> </tr>
</thead> </thead>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment