Skip to content

Commit

Permalink
Handle situation where council or twin has no plans
Browse files Browse the repository at this point in the history
  • Loading branch information
zarino committed Jun 28, 2023
1 parent 0e9d65e commit 3619007
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
8 changes: 8 additions & 0 deletions caps/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
)
from django.db.models.expressions import RawSQL
from django.forms import Select, TextInput
from django.utils.http import urlencode
from django.utils.text import slugify
from simple_history.models import HistoricalRecords
from caps.filters import DefaultSecondarySortFilter
Expand Down Expand Up @@ -580,6 +581,13 @@ def foe_slug(self):

return slug

@property
def feedback_form_url(self):
return "{}?{}".format(
settings.FEEDBACK_FORM,
urlencode({"usp": "pp_url", "entry.393810903": self.name}),
)

@classmethod
def country_description(cls, country_code):
codes_to_descriptions = dict(
Expand Down
2 changes: 1 addition & 1 deletion caps/templates/caps/council_cards/council-documents.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h2 class="mr-auto pr-3 mb-1 mb-sm-0">Climate documents</h2>
<strong>Are these plans out of date?</strong>
</p>
<small class="mb-0">
<a href="{{ feedback_form_url }}?usp=pp_url&entry.393810903={{ council.name }}">Fill in this form</a> to let us know where to find the latest plans from this council.
<a href="{{ council.feedback_form_url }}">Fill in this form</a> to let us know where to find the latest plans from this council.
</small>
</div>
{% endblock cardbody %}
52 changes: 42 additions & 10 deletions caps/templates/caps/twins.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,40 @@ <h3>Similarity index</h3>
<div class="card-header">
<h2>{{ council.short_name }}’s climate plans</h2>
</div>
{% if council.plandocument_set.all %}
<div class="card-body">
{% if twin.plandocument_set.all %}
<p>Topics covered by <a href="{% url 'council' council.slug %}">{{ council.short_name }}’s plans on CAPE</a> but not by {{ twin.short_name}}’s:</p>
{% else %}
<p>Some of the topics covered by <a href="{% url 'council' council.slug %}">{{ council.short_name }}’s plans on CAPE</a>:</p>
{% endif %}
{% if twin.plan_overlap.just_in_a %}
<ul class="list-inline d-flex flex-wrap mx-n1 mb-0">
{% for keyphrase in twin.plan_overlap.just_in_a %}
<li>{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=council %}
{% endfor %}
{% if twin.plandocument_set.all %}
{% for keyphrase in twin.plan_overlap.just_in_a %}
<li>{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=council %}
{% endfor %}
{% else %}
{% for keyphrase in twin.plan_overlap.just_in_a|randomize_and_limit:15 %}
<li>{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=council %}
{% endfor %}
{% endif %}
</ul>
{% else %}
<p class="px-3 text-muted">
<p class="px-3 mb-0 text-muted">
(No terms appear in just {{ twin.short_name }}’s plans.)
</p>
{% endif %}
</ul>
{% if twin.plan_overlap.overlap %}
<p class="mt-3 text-muted">Examples of topics that appear in both councils’ plans include:</p>
<ul class="list-inline d-flex flex-wrap mx-n1 mb-0">
{% for keyphrase in twin.plan_overlap.overlap|randomize_and_limit:10 %}
<li>{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=council %}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% if council.plandocument_set.all %}
<div class="card-body bg-purple-light flex-grow-0">
<form action="{% url 'search_results' %}" class="form-row flex-wrap align-items-center">
<div class="col-auto flex-shrink-1 flex-grow-1" style="max-width: 450px">
Expand All @@ -99,6 +111,10 @@ <h2>{{ council.short_name }}’s climate plans</h2>
</div>
</form>
</div>
{% else %}
<div class="card-body">
<p>We haven’t found any climate plans or documents for <a href="{% url 'council' council.slug %}">{{ council.name }}</a>. If you know where to find them, <a href="{{ council.feedback_form_url }}">please let us know</a>.</p>
</div>
{% endif %}
</div>
</div>
Expand All @@ -107,27 +123,39 @@ <h2>{{ council.short_name }}’s climate plans</h2>
<div class="card-header">
<h2>{{ twin.short_name }}’s climate plans</h2>
</div>
{% if twin.plandocument_set.all %}
<div class="card-body">
{% if council.plandocument_set.all %}
<p>Topics covered by <a href="{% url 'council' twin.slug %}">{{ twin.short_name }}’s plans on CAPE</a> but not by {{ council.short_name }}’s:</p>
{% else %}
<p>Some of the topics covered by <a href="{% url 'council' twin.slug %}">{{ twin.short_name }}’s plans on CAPE</a>:</p>
{% endif %}
{% if twin.plan_overlap.just_in_b %}
<ul class="list-inline d-flex flex-wrap mx-n1 mb-0">
{% for keyphrase in twin.plan_overlap.just_in_b %}
<li>{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=twin %}</li>
{% endfor %}
{% if council.plandocument_set.all %}
{% for keyphrase in twin.plan_overlap.just_in_b %}
<li>{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=twin %}</li>
{% endfor %}
{% else %}
{% for keyphrase in twin.plan_overlap.just_in_b|randomize_and_limit:15 %}
<li>{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=twin %}</li>
{% endfor %}
{% endif %}
</ul>
{% else %}
<p class="px-3 text-muted">
<p class="px-3 mb-0 text-muted">
(No terms appear in just {{ council.short_name }}’s plans.)
</p>
{% endif %}
{% if twin.plan_overlap.overlap %}
<p class="mt-3 text-muted">Examples of topics that appear in both councils’ plans include:</p>
<ul class="list-inline d-flex flex-wrap mx-n1 mb-0">
{% for keyphrase in twin.plan_overlap.overlap|randomize_and_limit:10 %}
{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=twin %}
{% endfor %}
</ul>
{% endif %}
</div>
{% if twin.plandocument_set.all %}
<div class="card-body bg-purple-light flex-grow-0">
<form action="{% url 'search_results' %}" class="form-row flex-wrap align-items-center">
<div class="col-auto flex-shrink-1 flex-grow-1" style="max-width: 450px">
Expand All @@ -143,6 +171,10 @@ <h2>{{ twin.short_name }}’s climate plans</h2>
</div>
</form>
</div>
{% else %}
<div class="card-body">
<p>We haven’t found any climate plans or documents for <a href="{% url 'council' council.slug %}">{{ council.name }}</a>. If you know where to find them, <a href="{{ council.feedback_form_url }}">please let us know</a>.</p>
</div>
{% endif %}
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion caps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ def get_context_data(self, **kwargs):
context["project_stats"] = project_stats

context["page_title"] = council.name
context["feedback_form_url"] = settings.FEEDBACK_FORM

if council.emergencydeclaration_set.count() > 0:
context["declared_emergency"] = council.emergencydeclaration_set.all()[0]
Expand Down

0 comments on commit 3619007

Please sign in to comment.