Commit fd479cfd authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE

Adding a button/shortcut to browse the NCBI data

parent b780f740
......@@ -126,7 +126,15 @@
class="homepage-lower-button bg-primary">
<h4 class="pt-4 pl-4 pr-4">
<i class="fa fa-download"></i> {% trans "Meta analysis"%}</h4>
<div class="pb-4 pl-1 pr-1">{% trans "Download all published responses on NCBI identified virus and host"%}</div>
<div class="pb-4 pl-1 pr-1">{% trans "Download all responses on NCBI identified viruses and hosts"%}</div>
</a>
</div>
<div class="col-12 col-md-4">
<a href="{% url 'viralhostrangedb:browse' %}?user_pref=False&only_host_ncbi_id=true&only_virus_ncbi_id=true&allow_overflow=on" role="button"
class="homepage-lower-button bg-primary">
<h4 class="pt-4 pl-4 pr-4">
<i class="fa fa-table"></i> {% trans "Meta analysis"%}</h4>
<div class="pb-4 pl-1 pr-1">{% trans "Explore all responses on NCBI identified viruses and hosts"%}</div>
</a>
</div>
</div>
......
......@@ -7,6 +7,7 @@ from basetheme_bootstrap.user_preferences import get_user_preferences_for_user
from django.contrib.auth import get_user_model
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db.models import Q, F
from django.http import QueryDict
from django.test import TestCase
from django.urls import reverse
from django.utils import timezone
......@@ -537,6 +538,51 @@ class BrowseTestCase(ViewTestCase):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
def test_allow_overflow_works(self):
url = reverse('viralhostrangedb:browse') + \
"?user_pref=False&only_host_ncbi_id=true&only_virus_ncbi_id=true&allow_overflow=on"
response_1 = self.client.get(url)
self.assertEqual(response_1.status_code, 302)
response_1 = self.client.get(url, follow=True)
target_2 = response_1.redirect_chain[0][0]
qd = QueryDict(target_2[target_2.index("?") + 1:])
expected_ds = set(models.ViralHostResponseValueInDataSource.objects.filter(
~Q(virus__identifier="")
& ~Q(host__identifier="")
& Q(data_source__public=True)).values_list("data_source__pk", flat=True))
expected_ds = set([str(i) for i in expected_ds])
self.assertEqual(set(qd.getlist("ds")), expected_ds)
def test_allow_overflow_works_with_auth(self):
self.client.force_login(self.user)
self.private_data_source_of_toto.allowed_users.add(self.user)
self.private_data_source_of_toto.save()
self.private_data_source_of_toto.virus_set.update(identifier="i")
self.private_data_source_of_toto.host_set.update(identifier="i")
url = reverse('viralhostrangedb:browse') + \
"?user_pref=False&only_host_ncbi_id=true&only_virus_ncbi_id=true&allow_overflow=on"
response_1 = self.client.get(url)
self.assertEqual(response_1.status_code, 302)
response_1 = self.client.get(url, follow=True)
target_2 = response_1.redirect_chain[0][0]
qd = QueryDict(target_2[target_2.index("?") + 1:])
expected_ds = set(models.ViralHostResponseValueInDataSource.objects.filter(
~Q(virus__identifier="")
& ~Q(host__identifier="")
& Q(
Q(data_source__public=True)
| Q(data_source__owner=self.user)
| Q(data_source__allowed_users=self.user)
)).values_list("data_source__pk", flat=True))
expected_ds = set([str(i) for i in expected_ds])
self.assertEqual(set(qd.get("ds").split(',')), expected_ds)
class HostListViewTestCase(ViewTestCase):
def test_works(self):
......
......@@ -582,6 +582,15 @@ def data_source_entry_delete(request, pk, entry_class, formset_class, entry_lowe
def browse(request):
request.GET = request.GET.copy()
if request.GET.get("allow_overflow") \
and "virus" not in request.GET \
and "host" not in request.GET \
and "ds" not in request.GET:
request.GET["format"] = "json"
response = views_api.DataSourceViewSet.as_view(actions={'get': 'list'})(request)
request.GET["ds"] = ",".join([str(d["id"]) for d in json.loads(response.rendered_content.decode('utf-8'))])
del request.GET["format"]
return HttpResponseRedirect(reverse('viralhostrangedb:browse') + "?" + request.GET.urlencode(safe=','))
for k in ["virus", "host", "ds"]:
try:
request.GET.setlist(k, request.GET[k].split(","))
......
Markdown is supported
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