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
hub
ViralHostRangeDB
Commits
ccfbd803
Commit
ccfbd803
authored
Oct 02, 2019
by
Bryan BRANCOTTE
Browse files
keeping displayed order in the export, wip
#105
parent
61a766d5
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/viralhostrange/test_data/download_responses/three_reponse_simple_2_order.csv
0 → 100644
View file @
ccfbd803
Unnamed: 0,C4,C3,C2,C1
r3,1,0.0,2.0,0.0
r2,0,1.0,0.0,0.0
r1,1,0.0,1.0,1.0
,,,,
,,,,
,Legend,,,
0,No lysis,,,
1,Weak,,,
2,Lysis,,,
src/viralhostrange/viralhostrangedb/static/js/browse.js
View file @
ccfbd803
...
...
@@ -620,4 +620,45 @@ function refresh_infection_ratio(){
function
toggle_pin_advanced_holder
()
{
$
(
"
#advanced_holder
"
).
toggleClass
(
"
pinned
"
);
}
function
trigger_download
(){
var
no_selected_virus
=
false
,
no_selected_host
=
false
,
virus_select
=
$
(
'
#form_filter select[name="virus"]
'
),
host_select
=
$
(
'
#form_filter select[name="host"]
'
);
if
(
$
(
'
select[name="virus"]
'
).
parent
().
find
(
'
input[type="checkbox"]:checked
'
).
length
==
0
){
no_selected_virus
=
true
;
}
if
(
$
(
'
select[name="virus"]
'
).
parent
().
find
(
'
input[type="checkbox"]:checked
'
).
length
==
0
){
no_selected_host
=
true
;
}
$
(
"
#grid_host tbody th[data-row]
"
).
map
(
function
(
i
,
n
){
let
o
=
virus_select
.
find
(
'
option[value="
'
+
$
(
n
).
attr
(
"
data-row
"
)
+
'
"]
'
);
if
(
no_selected_virus
){
o
.
prop
(
"
selected
"
,
true
);
}
o
.
appendTo
(
o
.
parent
())
})
$
(
"
#grid_host thead [data-col]
"
).
map
(
function
(
i
,
n
){
let
o
=
host_select
.
find
(
'
option[value="
'
+
$
(
n
).
attr
(
"
data-col
"
)
+
'
"]
'
);
if
(
no_selected_host
){
o
.
prop
(
"
selected
"
,
true
);
}
o
.
appendTo
(
o
.
parent
())
})
$
(
'
#form_filter
'
).
submit
();
if
(
no_selected_virus
){
$
(
"
#grid_host tbody th[data-row]
"
).
map
(
function
(
i
,
n
){
let
o
=
virus_select
.
find
(
'
option[value="
'
+
$
(
n
).
attr
(
"
data-row
"
)
+
'
"]
'
);
o
.
prop
(
"
selected
"
,
false
);
})
}
if
(
no_selected_host
){
$
(
"
#grid_host thead [data-col]
"
).
map
(
function
(
i
,
n
){
let
o
=
host_select
.
find
(
'
option[value="
'
+
$
(
n
).
attr
(
"
data-col
"
)
+
'
"]
'
);
o
.
prop
(
"
selected
"
,
false
);
})
}
}
\ No newline at end of file
src/viralhostrange/viralhostrangedb/templates/viralhostrangedb/browse.html
View file @
ccfbd803
...
...
@@ -23,7 +23,7 @@
{%trans "Copy link into clipboard" %} {%trans "(recommended)" %}
</button>
<button
class=
"dropdown-item"
type=
"button"
onclick=
"
$('#form_filter').submit
()"
onclick=
"
trigger_download
()"
>
<i
class=
"fa fa-download"
></i>
{%trans "Download displayed data in a spreadsheet" %}
...
...
src/viralhostrange/viralhostrangedb/tests/test_views.py
View file @
ccfbd803
...
...
@@ -2284,6 +2284,17 @@ class DownloadBrowsedDataTestCase(DownloadXXXDataTestCase):
agreed_infection
=
True
,
)
def
test_order_kept
(
self
):
self
.
actual_test
(
user
=
self
.
user
,
ds
=
models
.
DataSource
.
objects
.
filter
(
pk
=
self
.
private_data_source_of_user_mapped
.
pk
),
virus
=
models
.
Virus
.
objects
.
filter
(
data_source__pk
=
self
.
private_data_source_of_user_mapped
.
pk
)
.
order_by
(
"-name"
),
host
=
models
.
Host
.
objects
.
filter
(
data_source__pk
=
self
.
private_data_source_of_user_mapped
.
pk
)
.
order_by
(
"-name"
),
filename
=
"three_reponse_simple_2_order.csv"
,
)
class
DownloadHostDataTestCase
(
DownloadXXXDataTestCase
):
file_location
=
"download_responses_host_virus"
...
...
src/viralhostrange/viralhostrangedb/views.py
View file @
ccfbd803
...
...
@@ -695,12 +695,18 @@ def download_responses(request):
response
=
views_api
.
AggregatedResponseViewSet
.
as_view
()(
request
)
aggregated_responses
=
json
.
loads
(
response
.
rendered_content
.
decode
(
'utf-8'
))
virus
=
form
.
cleaned_data
[
"virus"
]
if
not
virus
.
exists
():
if
virus
.
exists
():
actual_order
=
dict
((
int
(
o
),
i
)
for
i
,
o
in
enumerate
(
request
.
GET
.
getlist
(
"virus"
)))
virus
=
sorted
(
virus
,
key
=
lambda
o
:
actual_order
[
o
.
pk
])
else
:
virus
=
models
.
Virus
.
objects
.
filter
(
pk__in
=
aggregated_responses
.
keys
()
).
order_by
(
'pk'
)
host
=
form
.
cleaned_data
[
"host"
]
if
not
host
.
exists
():
if
host
.
exists
():
actual_order
=
dict
((
int
(
o
),
i
)
for
i
,
o
in
enumerate
(
request
.
GET
.
getlist
(
"host"
)))
host
=
sorted
(
host
,
key
=
lambda
o
:
actual_order
[
o
.
pk
])
else
:
host
=
models
.
Host
.
objects
.
filter
(
pk__in
=
itertools
.
chain
(
*
[
d
.
keys
()
for
d
in
aggregated_responses
.
values
()])
).
order_by
(
'pk'
)
...
...
@@ -719,11 +725,11 @@ def download_responses(request):
# get at which position each host is, mandatory if data are sparse
col_pos
=
dict
([(
pk
,
i
)
for
i
,
pk
in
enumerate
(
host
.
values_list
(
'pk'
,
flat
=
True
)
,
[
o
.
pk
for
o
in
host
]
,
start
=
virus_infection_ratio_shift
,
)])
row_pos
=
dict
([(
pk
,
i
)
for
i
,
pk
in
enumerate
(
virus
.
values_list
(
'pk'
,
flat
=
True
)
,
[
o
.
pk
for
o
in
virus
]
,
start
=
host_infection_ratio_shift
,
)])
...
...
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