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

@@ -106,10 +106,13 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
context_object_name = 'organisation'
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."""
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:
questions = questions.filter(answer_is_public=True)
@@ -139,6 +142,14 @@ class OrganisationDetailView(LoginRequiredMixin, DetailView):
'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

View File

@@ -123,6 +123,14 @@ class ProfileView(LoginRequiredMixin, DetailView):
context['question_answers'] = self.build_question_answers(answer_set)
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