From 311a90fe09d438236cf6278e2f723ca8875ffc10 Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 26 Apr 2021 21:04:02 +0100 Subject: [PATCH] fix: hide map on detail pages when no location set --- people/models/organisation.py | 4 ++++ people/models/person.py | 4 ++++ people/templates/people/organisation/detail.html | 5 ++++- people/templates/people/person/detail_full.html | 7 ++++--- people/templates/people/person/detail_partial.html | 6 ++++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/people/models/organisation.py b/people/models/organisation.py index 3f9c76c..62bd70e 100644 --- a/people/models/organisation.py +++ b/people/models/organisation.py @@ -102,6 +102,10 @@ class OrganisationAnswerSet(AnswerSet): #: Answers to :class:`OrganisationQuestion`s question_answers = models.ManyToManyField(OrganisationQuestionChoice) + @property + def location_set(self) -> bool: + return self.latitude and self.longitude + def public_answers(self) -> models.QuerySet: """Get answers to questions which are public.""" return self.question_answers.filter(question__answer_is_public=True) diff --git a/people/models/person.py b/people/models/person.py index 08c76a8..d0f5d41 100644 --- a/people/models/person.py +++ b/people/models/person.py @@ -188,6 +188,10 @@ class PersonAnswerSet(AnswerSet): #: Longitude for displaying location on a map longitude = models.FloatField(blank=True, null=True) + @property + def location_set(self) -> bool: + return self.latitude and self.longitude + def public_answers(self) -> models.QuerySet: """Get answers to questions which are public.""" return self.question_answers.filter(question__answer_is_public=True) diff --git a/people/templates/people/organisation/detail.html b/people/templates/people/organisation/detail.html index 599ec56..d28ff0c 100644 --- a/people/templates/people/organisation/detail.html +++ b/people/templates/people/organisation/detail.html @@ -58,7 +58,10 @@
-
+ {% if organisation.current_answers.location_set %} +
+
+ {% endif %}
diff --git a/people/templates/people/person/detail_full.html b/people/templates/people/person/detail_full.html index ff80350..556e57a 100644 --- a/people/templates/people/person/detail_full.html +++ b/people/templates/people/person/detail_full.html @@ -79,9 +79,10 @@
-
- -
+ {% if person.current_answers.location_set %} +
+
+ {% endif %} {% include 'people/person/includes/relationships_full.html' %} diff --git a/people/templates/people/person/detail_partial.html b/people/templates/people/person/detail_partial.html index 84c6060..8379d8e 100644 --- a/people/templates/people/person/detail_partial.html +++ b/people/templates/people/person/detail_partial.html @@ -55,7 +55,9 @@
-
+ {% if person.current_answers.location_set %} +
+
+ {% endif %} -
{% endblock %}