feat: add rel create / update buttons to profiles

See #109
This commit is contained in:
James Graham
2021-03-18 17:52:14 +00:00
parent 2c68877cc8
commit c20b2b5a0a
5 changed files with 73 additions and 7 deletions

View File

@@ -24,8 +24,25 @@
<hr> <hr>
<a class="btn btn-success" <div class="row justify-content-md-center">
href="{% url 'people:organisation.update' pk=organisation.pk %}">Update</a> <div class="col-md-3">
<a class="btn btn-warning btn-block"
href="{% url 'people:organisation.update' pk=organisation.pk %}">Update Organisation</a>
</div>
<div class="col-md-3">
{% if relationship %}
<a class="btn btn-warning btn-block"
href="{% url 'people:organisation.relationship.create' organisation_pk=organisation.pk %}">Update Relationship
</a>
{% else %}
<a class="btn btn-success btn-block"
href="{% url 'people:organisation.relationship.create' organisation_pk=organisation.pk %}">New Relationship
</a>
{% endif %}
</div>
</div>
<hr> <hr>

View File

@@ -24,6 +24,23 @@
<hr> <hr>
<div class="row justify-content-md-center">
<div class="col-md-3">
{% if relationship %}
<a class="btn btn-warning btn-block"
href="{% url 'people:person.relationship.create' person_pk=person.pk %}">Update Relationship
</a>
{% else %}
<a class="btn btn-success btn-block"
href="{% url 'people:person.relationship.create' person_pk=person.pk %}">New Relationship
</a>
{% endif %}
</div>
</div>
<hr>
{% if person.user != request.user and request.user.is_superuser %} {% if person.user != request.user and request.user.is_superuser %}
<div class="alert alert-warning"> <div class="alert alert-warning">
<strong>NB:</strong> You are able to see the details of this person because you are an admin. <strong>NB:</strong> You are able to see the details of this person because you are an admin.

View File

@@ -22,9 +22,22 @@
<h1>{{ person.name }}</h1> <h1>{{ person.name }}</h1>
<a class="btn btn-success" <hr>
href="{% url 'people:person.relationship.create' person_pk=person.pk %}">New Relationship
</a> <div class="row justify-content-md-center">
<div class="col-md-3">
{% if relationship %}
<a class="btn btn-warning btn-block"
href="{% url 'people:person.relationship.create' person_pk=person.pk %}">Update Relationship
</a>
{% else %}
<a class="btn btn-success btn-block"
href="{% url 'people:person.relationship.create' person_pk=person.pk %}">New Relationship
</a>
{% endif %}
</div>
</div>
<hr> <hr>

View File

@@ -106,10 +106,13 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
context_object_name = 'organisation' context_object_name = 'organisation'
template_name = 'people/organisation/detail.html' template_name = 'people/organisation/detail.html'
def build_question_answers(self, answer_set: models.OrganisationAnswerSet) -> typing.Dict[str, str]: def build_question_answers(
self,
answer_set: models.OrganisationAnswerSet) -> typing.Dict[str, str]:
"""Collect answers to dynamic questions and join with commas.""" """Collect answers to dynamic questions and join with commas."""
show_all = self.request.user.is_superuser show_all = self.request.user.is_superuser
questions = models.OrganisationQuestion.objects.filter(is_hardcoded=False) questions = models.OrganisationQuestion.objects.filter(
is_hardcoded=False)
if not show_all: if not show_all:
questions = questions.filter(answer_is_public=True) questions = questions.filter(answer_is_public=True)
@@ -139,6 +142,14 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
'lng': getattr(answerset, 'longitude', None), 'lng': getattr(answerset, 'longitude', None),
}] }]
context['relationship'] = None
try:
context['relationship'] = models.OrganisationRelationship.objects.get(
source=self.request.user.person, target=self.object) # yapf: disable
except models.OrganisationRelationship.DoesNotExist:
pass
return context return context

View File

@@ -123,6 +123,14 @@ class ProfileView(LoginRequiredMixin, DetailView):
context['question_answers'] = self.build_question_answers(answer_set) context['question_answers'] = self.build_question_answers(answer_set)
context['map_markers'] = [get_map_data(self.object)] context['map_markers'] = [get_map_data(self.object)]
context['relationship'] = None
try:
context['relationship'] = models.Relationship.objects.get(
source=self.request.user.person, target=self.object)
except models.Relationship.DoesNotExist:
pass
return context return context