Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Discuss Data Project
Discuss Data
Commits
ccd75776
Commit
ccd75776
authored
May 11, 2021
by
felix.herrmann
Browse files
fix(search): sorting search results by date/alphabetically
parent
53685739
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
.pre-commit-config.yaml
View file @
ccd75776
...
...
@@ -18,13 +18,13 @@ repos:
types
:
[
python
]
#language_version: python3.6
-
repo
:
local
hooks
:
-
id
:
flake8
name
:
flake8
entry
:
flake8
language
:
python
types
:
[
python
]
#
- repo: local
#
hooks:
#
- id: flake8
#
name: flake8
#
entry: flake8
#
language: python
#
types: [python]
# - repo: local
# hooks:
...
...
discuss_data/core/views.py
View file @
ccd75776
...
...
@@ -138,12 +138,18 @@ def core_search_view(request, search_index, objects_on_page):
methods_of_data_collection
=
methods_of_data_collection
,
disciplines
=
disciplines
,
)
# search result ordering
order_by_filter
=
request
.
GET
.
get
(
"orderby"
)
if
order_by_filter
==
"alpha"
:
order_by
=
"title"
else
:
order_by
=
"-publication_date"
# only the dataset with the highest published version per dsmo will be listed in search results
# generate SQL join using Django F() expressions
# https://docs.djangoproject.com/en/3.0/topics/db/queries/#filters-can-reference-fields-on-the-model
queryset
=
queryset
.
filter
(
dataset_management_object__main_published_ds_id
=
F
(
"id"
)
)
)
.
order_by
(
order_by
)
elif
search_index
==
"user_index"
:
# default search index is user_index
...
...
@@ -199,6 +205,10 @@ def core_search_view(request, search_index, objects_on_page):
search_params
[
"disciplines"
]
=
disciplines
search_params
[
"methods_of_data_analysis"
]
=
methods_of_data_analysis
search_params
[
"methods_of_data_collection"
]
=
methods_of_data_collection
try
:
search_params
[
"orderby"
]
=
[
order_by_filter
]
except
UnboundLocalError
:
pass
return
render
(
request
,
...
...
discuss_data/templates/dddatasets/search_results.html
View file @
ccd75776
...
...
@@ -19,7 +19,21 @@
{# search object list #}
{% if object_list %}
<p>
{% if object_list.paginator %}{{ object_list.paginator.count }}{% else %}{{ object_list.count }}{% endif %} {% trans "Datasets found" %}
</p>
<div
class=
"row smallskip"
>
<div
class=
"col-md-7"
>
{% if object_list.paginator %}{{ object_list.paginator.count }}{% else %}{{ object_list.count }}{% endif %} {% trans "Datasets found" %}
</div>
<div
class=
"col-md-5 text-right"
>
<div
class=
"btn-group btn-group-toggle"
data-toggle=
"buttons"
>
<label
class=
"btn btn-secondary"
>
<input
type=
"radio"
value=
"pubdate"
name=
"orderby"
id=
"pubdate"
ic-get-from=
"{% url 'dddatasets:search' %}{{ search_params|add_url_search_params }}"
ic-push-url=
"true"
ic-include=
".search-middle"
ic-target=
"#content"
{%
if
search_params.orderby.0
!=
'
alpha
'
%}
checked
{%
endif
%}
>
{% trans "sort by publication date" %}
</label>
<label
class=
"btn btn-secondary"
>
<input
type=
"radio"
value=
"alpha"
name=
"orderby"
id=
"alpha"
ic-get-from=
"{% url 'dddatasets:search' %}{{ search_params|add_url_search_params }}"
ic-push-url=
"true"
ic-include=
".search-middle"
ic-target=
"#content"
{%
if
search_params.orderby.0 =
=
'
alpha
'
%}
checked
{%
endif
%}
>
{% trans "sort alphabetically" %}
</label>
</div>
</div>
</div>
{% for object in object_list %}
{% include "dddatasets/_dataset_card.html" with dataset=object prep=False %}
{% endfor %}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment