Skip to content

Commit

Permalink
Fix issue with studies list page (#941)
Browse files Browse the repository at this point in the history
* Fix issue with studies list page

* Update existing tests
  • Loading branch information
okaycj authored Mar 15, 2022
1 parent 30c1cc1 commit 9e86053
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 36 deletions.
23 changes: 12 additions & 11 deletions web/templates/web/studies-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,25 @@
</div>

<div class="container-fluid study-list">
<div class="row">
{% for study in object_list %}

<div class="col-sm-2 col-md-3 col-lg-3">
<a href="{% url 'web:study-detail' uuid=study.uuid %}">
<img src="{{ study.image.url }}" class="img-responsive" alt="{{ study.name }}">
<p>{{ study.name }}</p>
<p>{{ study.preview_summary }}</p>
<p> Learn More &rarr;</p>
</a>
{% for study_row in object_list %}
<div class="row">
{% for study in study_row %}
<div class="col-sm-3 col-md-3 col-lg-3">
<a href="{% url 'web:study-detail' uuid=study.uuid %}">
<img src="{{ study.image.url }}" class="img-responsive" alt="{{ study.name }}">
<p>{{ study.name }}</p>
<p>{{ study.preview_summary }}</p>
<p> Learn More &rarr;</p>
</a>
</div>
{% endfor %}
</div>
{% empty %}
<div class="col-xs-12">
<p><em> {% trans "No studies found." %} </em></p>
</div>
{% endfor %}
</div>
</div>

<div class="panel-default">
<div class="panel-body">
Expand Down
33 changes: 9 additions & 24 deletions web/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,29 +403,14 @@ def test_study_list_view(self):
self.assertIn("PublicActiveStudy2", content)
self.assertNotIn("PrivateActiveStudy", content)
self.assertNotIn("PublicInactiveStudy", content)
self.assertTrue(
any(
s.uuid == self.public_active_study_1.uuid
for s in response.context["object_list"]
)
)
self.assertTrue(
any(
s.uuid == self.public_active_study_2.uuid
for s in response.context["object_list"]
)
)
self.assertFalse(
any(
s.uuid == self.private_active_study.uuid
for s in response.context["object_list"]
)
)

# flatten study list
studies = [s for ss in response.context["object_list"] for s in ss]
self.assertTrue(any(s.uuid == self.public_active_study_1.uuid for s in studies))
self.assertTrue(any(s.uuid == self.public_active_study_2.uuid for s in studies))
self.assertFalse(any(s.uuid == self.private_active_study.uuid for s in studies))
self.assertFalse(
any(
s.uuid == self.public_inactive_study.uuid
for s in response.context["object_list"]
)
any(s.uuid == self.public_inactive_study.uuid for s in studies)
)


Expand Down Expand Up @@ -526,7 +511,7 @@ def test_get_queryset_auth_user(
)
mock_sort_fn.assert_called_once_with()

self.assertListEqual(studies, mock_studies)
self.assertListEqual(studies, [mock_studies])

@patch("web.views.age_range_eligibility_for_study", return_value=True)
@patch.object(StudiesListView, "sort_fn")
Expand Down Expand Up @@ -562,7 +547,7 @@ def test_get_queryset_anon_user(
mock_age_range_eligibility_for_study.assert_called_once_with([1, 2], mock_study)
mock_sort_fn.assert_called_once_with()

self.assertListEqual(studies, mock_studies)
self.assertListEqual(studies, [mock_studies])

@patch.object(StudiesListView, "request", create=True)
def test_get_form_kwargs(self, mock_request):
Expand Down
3 changes: 2 additions & 1 deletion web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ def get_queryset(self):

studies = sorted(studies, key=self.sort_fn())

return studies
# convert studies in to a 3d list of four elements
return [studies[x : x + 4] for x in range(0, len(studies), 4)]

def filter_studies(self, studies: QuerySet) -> QuerySet:
session = self.request.session
Expand Down

0 comments on commit 9e86053

Please sign in to comment.