Skip to content

Commit

Permalink
Merge pull request #502 from thegreenwebfoundation/ca-card-184-serve-…
Browse files Browse the repository at this point in the history
…no-directory-results-template

Add conditionals for showing directory results
  • Loading branch information
hanopcan committed Aug 1, 2023
2 parents d1ae2c1 + d1a239c commit 823d5ba
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 48 deletions.
44 changes: 44 additions & 0 deletions apps/greencheck/tests/test_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,47 @@ def test_ordering_of_providers_in_directory(client, hosting_provider_factory):
# and: the providers are listed in order of their country name
assert res.context["ordered_results"][0] == danish_provider
assert res.context["ordered_results"][1] == german_provider


@pytest.mark.django_db
@override_flag("directory_listing", active=True)
def test_templates_in_filter_view(client, hosting_provider_factory):
"""
Check that we include the no_directoru results in our template
"""

# given: a hosting provider in Germany
hosting_provider_factory.create(country="DE", showonwebsite=True)

# when: we visit our directory
res = client.get(reverse("directory-index"))

# then: we should get a successful response
assert res.status_code == 200

# and: we should see the "has results" template in our list of templates
# in use
templates = [tpl.name for tpl in res.templates]
assert "greencheck/partials/_directory_results.html" in templates


@pytest.mark.django_db
@override_flag("directory_listing", active=True)
def test_fallback_when_no_filter_view_has_no_results(client, hosting_provider_factory):
"""
Check that we include the no_directoru results in our template
"""

# given: a hosting provider in Germany
hosting_provider_factory.create(country="DE", showonwebsite=True)

# when: we filter our directory by another country, Denmark
res = client.get(reverse("directory-index"), {"country": "DK"})

# then: we should get a successful response
assert res.status_code == 200

# and: we should see the "no results" template in our list of templates
# in use
templates = [tpl.name for tpl in res.templates]
assert "greencheck/partials/_no_directory_results.html" in templates
53 changes: 5 additions & 48 deletions apps/theme/templates/greencheck/directory_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,10 @@ <h1 class="text-disp-sm mt-12 pb-4">I am looking for</h1>
</section>
</div>
<section class="main-content container mx-auto">
{% regroup ordered_results by country.name as country_list %}
{% for country in country_list %}
<article class="md:grid md:grid-cols-5 lg:grid-cols-7 md:grid-rows-1 pt-4 pb-8 md:pt-8 md:pb-14">
<h2 class="text-2xl mb-2 mt-0">{{ country.grouper }}</h2>
<div class="col-span-3 lg:col-span-5">
{% for obj in country.list %}
<div class="border-b-2 border-neutral-200 mb-4">
<h4 class="mb-4 font-bold text-xl" id="{{ obj.id }}">{{ obj.name }}</h4>
<p class="text-neutral-700 mb-8 max-w-prose">
{% if obj.description %}
{{ obj.description }}
{% else %}
<small>If we had a description it would go here. So we need some graceful fallback copy to replace this.</small>
{% endif %}
<ul class="mb-4">
{% if obj.services.names %}
{% for service in obj.services.all %}<li class="service-label inline-block">{{ service.name }}</li>{% endfor %}
{% comment %}
Every host in our directory used to at least offer shared hosting.
Below is a placeholder to see how it would look with live data.
{% else %}
<li class="service-label inline-block">Compute: Shared Hosting for Websites</li>
{% endcomment %}
{% endif %}
</ul>
</p>
{% if obj.public_supporting_evidence %}
<details class="mb-4">
<summary>
<span class="">Published supporting evidence</span>
</summary>
<ul>
{% for evidence in obj.public_supporting_evidence %}
<li class="m-3">
<a class="py-2"href="{{ evidence.link }}">{{ evidence.title }}</a>
<div class="description py-2">
<small>{{ evidence.description|linebreaks }}</small>
</div>
</li>
{% endfor %}
</ul>
</details>
{% endif %}
</div>
{% endfor %}
</div>
</article>
{% endfor %}
{% if not ordered_results %}
{% include "greencheck/partials/_no_directory_results.html" %}
{% else %}
{% include "greencheck/partials/_directory_results.html" %}
{% endif %}
</section>
{% endblock %}
48 changes: 48 additions & 0 deletions apps/theme/templates/greencheck/partials/_directory_results.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% regroup ordered_results by country.name as country_list %}
{% for country in country_list %}
<article class="md:grid md:grid-cols-5 lg:grid-cols-7 md:grid-rows-1 pt-4 pb-8 md:pt-8 md:pb-14">
<h2 class="text-2xl mb-2 mt-0">{{ country.grouper }}</h2>
<div class="col-span-3 lg:col-span-5">
{% for obj in country.list %}
<div class="border-b-2 border-neutral-200 mb-4">
<h4 class="mb-4 font-bold text-xl" id="{{ obj.id }}">{{ obj.name }}</h4>
<p class="text-neutral-700 mb-8 max-w-prose">
{% if obj.description %}
{{ obj.description }}
{% else %}
<small>If we had a description it would go here. So we need some graceful fallback copy to replace this.</small>
{% endif %}
<ul class="mb-4">
{% if obj.services.names %}
{% for service in obj.services.all %}<li class="service-label inline-block">{{ service.name }}</li>{% endfor %}
{% comment %}
Every host in our directory used to at least offer shared hosting.
Below is a placeholder to see how it would look with live data.
{% else %}
<li class="service-label inline-block">Compute: Shared Hosting for Websites</li>
{% endcomment %}
{% endif %}
</ul>
</p>
{% if obj.public_supporting_evidence %}
<details class="mb-4">
<summary>
<span class="">Published supporting evidence</span>
</summary>
<ul>
{% for evidence in obj.public_supporting_evidence %}
<li class="m-3">
<a class="py-2"href="{{ evidence.link }}">{{ evidence.title }}</a>
<div class="description py-2">
<small>{{ evidence.description|linebreaks }}</small>
</div>
</li>
{% endfor %}
</ul>
</details>
{% endif %}
</div>
{% endfor %}
</div>
</article>
{% endfor %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<article class="px-1">
<h1 class="text-4xl">Sorry, we couldn't find any results for this filtered view.</h1>
<p>Enter copy here to provide an alternative thing to do.</p>
</article>

0 comments on commit 823d5ba

Please sign in to comment.