From 3619007a5b2b4ae56b27b573251118bd7afeb211 Mon Sep 17 00:00:00 2001
From: Zarino Zappia
Date: Wed, 28 Jun 2023 16:00:59 +0100
Subject: [PATCH] Handle situation where council or twin has no plans
---
caps/models.py | 8 +++
.../caps/council_cards/council-documents.html | 2 +-
caps/templates/caps/twins.html | 52 +++++++++++++++----
caps/views.py | 1 -
4 files changed, 51 insertions(+), 12 deletions(-)
diff --git a/caps/models.py b/caps/models.py
index acab24aca..ed5ec1712 100755
--- a/caps/models.py
+++ b/caps/models.py
@@ -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
@@ -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(
diff --git a/caps/templates/caps/council_cards/council-documents.html b/caps/templates/caps/council_cards/council-documents.html
index f46131b58..9dd05fe34 100644
--- a/caps/templates/caps/council_cards/council-documents.html
+++ b/caps/templates/caps/council_cards/council-documents.html
@@ -65,7 +65,7 @@ Climate documents
Are these plans out of date?
+ {% if twin.plandocument_set.all %}
Topics covered by {{ council.short_name }}’s plans on CAPE but not by {{ twin.short_name}}’s:
+ {% else %}
+
Some of the topics covered by {{ council.short_name }}’s plans on CAPE:
+ {% endif %}
{% if twin.plan_overlap.just_in_a %}
- {% for keyphrase in twin.plan_overlap.just_in_a %}
- - {% 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 %}
+
- {% 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 %}
+
- {% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=council %}
+ {% endfor %}
+ {% endif %}
{% else %}
-
+
(No terms appear in just {{ twin.short_name }}’s plans.)
{% endif %}
+ {% if twin.plan_overlap.overlap %}
Examples of topics that appear in both councils’ plans include:
{% for keyphrase in twin.plan_overlap.overlap|randomize_and_limit:10 %}
- {% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=council %}
{% endfor %}
+ {% endif %}
- {% if council.plandocument_set.all %}
+ {% else %}
+
+
We haven’t found any climate plans or documents for {{ council.name }}. If you know where to find them, please let us know.
+
{% endif %}
@@ -107,27 +123,39 @@
+ {% if council.plandocument_set.all %}
Topics covered by {{ twin.short_name }}’s plans on CAPE but not by {{ council.short_name }}’s:
+ {% else %}
+
Some of the topics covered by {{ twin.short_name }}’s plans on CAPE:
+ {% endif %}
{% if twin.plan_overlap.just_in_b %}
- {% for keyphrase in twin.plan_overlap.just_in_b %}
- - {% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=twin %}
- {% endfor %}
+ {% if council.plandocument_set.all %}
+ {% for keyphrase in twin.plan_overlap.just_in_b %}
+ - {% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=twin %}
+ {% endfor %}
+ {% else %}
+ {% for keyphrase in twin.plan_overlap.just_in_b|randomize_and_limit:15 %}
+ - {% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=twin %}
+ {% endfor %}
+ {% endif %}
{% else %}
-
+
(No terms appear in just {{ council.short_name }}’s plans.)
{% endif %}
+ {% if twin.plan_overlap.overlap %}
Examples of topics that appear in both councils’ plans include:
{% for keyphrase in twin.plan_overlap.overlap|randomize_and_limit:10 %}
{% include "caps/includes/twin-keyphrase-badge.html" with keyphrase=keyphrase council=twin %}
{% endfor %}
+ {% endif %}
- {% if twin.plandocument_set.all %}
+ {% else %}
+
+
We haven’t found any climate plans or documents for {{ council.name }}. If you know where to find them, please let us know.
+
{% endif %}
diff --git a/caps/views.py b/caps/views.py
index 99e450ad5..7042574eb 100755
--- a/caps/views.py
+++ b/caps/views.py
@@ -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]