Source
@@ -45,34 +63,40 @@
-
Update
-
{% with relationship.current_answers as answer_set %}
-
-
-
- | Question |
- Answer |
-
-
+ {% if answer_set is None %}
+
+ This relationship has ended. You can start it again by updating it.
+
-
- {% for answer in answer_set.question_answers.all %}
+ {% else %}
+
+
- | {{ answer.question }} |
- {{ answer }} |
+ Question |
+ Answer |
+
- {% empty %}
-
- | No records |
-
- {% endfor %}
-
-
+
+ {% for answer in answer_set.question_answers.all %}
+
+ | {{ answer.question }} |
+ {{ answer }} |
+
- Last updated: {{ answer_set.timestamp }}
+ {% empty %}
+
+ | No records |
+
+ {% endfor %}
+
+
+
+
+ Last updated: {{ answer_set.timestamp }}
+
+ {% endif %}
{% endwith %}
{% endblock %}
diff --git a/people/urls.py b/people/urls.py
index e38621b..25e526f 100644
--- a/people/urls.py
+++ b/people/urls.py
@@ -78,6 +78,10 @@ urlpatterns = [
views.relationship.OrganisationRelationshipUpdateView.as_view(),
name='organisation.relationship.update'),
+ path('organisation-relationships/
/end',
+ views.relationship.OrganisationRelationshipEndView.as_view(),
+ name='organisation.relationship.end'),
+
############
# Data views
path('map',
diff --git a/people/views/organisation.py b/people/views/organisation.py
index db1b46a..9a2df8e 100644
--- a/people/views/organisation.py
+++ b/people/views/organisation.py
@@ -2,6 +2,7 @@ import typing
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
+from django.core.exceptions import ObjectDoesNotExist
from django.utils import timezone
from django.views.generic import CreateView, DetailView, ListView, UpdateView
@@ -93,9 +94,19 @@ class OrganisationListView(LoginRequiredMixin, ListView):
context['orgs_by_country'] = self.sort_organisation_countries(
orgs_by_country)
- context['existing_relationships'] = set(
- self.request.user.person.organisation_relationship_targets.
- values_list('pk', flat=True))
+ existing_relationships = set()
+ try:
+ existing_relationships = set(
+ self.request.user.person.organisation_relationships_as_source.filter(
+ answer_sets__replaced_timestamp__isnull=True
+ ).values_list('target_id', flat=True)
+ )
+
+ except ObjectDoesNotExist:
+ # No linked Person yet
+ pass
+
+ context['existing_relationships'] = existing_relationships
return context
@@ -144,8 +155,11 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
context['relationship'] = None
try:
- context['relationship'] = models.OrganisationRelationship.objects.get(
- source=self.request.user.person, target=self.object) # yapf: disable
+ relationship = models.OrganisationRelationship.objects.get(
+ source=self.request.user.person, target=self.object)
+
+ if relationship.is_current:
+ context['relationship'] = relationship
except models.OrganisationRelationship.DoesNotExist:
pass
diff --git a/people/views/relationship.py b/people/views/relationship.py
index 3e638ec..fb6a5ee 100644
--- a/people/views/relationship.py
+++ b/people/views/relationship.py
@@ -116,6 +116,14 @@ class RelationshipEndView(permissions.UserIsLinkedPersonMixin,
return relationship.target.get_absolute_url()
+class OrganisationRelationshipEndView(RelationshipEndView):
+ """View for marking an organisation relationship as ended.
+
+ Sets `replaced_timestamp` on all answer sets where this is currently null.
+ """
+ model = models.OrganisationRelationship
+
+
class OrganisationRelationshipDetailView(permissions.UserIsLinkedPersonMixin,
DetailView):
"""View displaying details of an :class:`OrganisationRelationship`."""