mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
fix: attr error if non-admin updates relationship
This commit is contained in:
@@ -41,10 +41,18 @@ class PersonListView(LoginRequiredMixin, ListView):
|
|||||||
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
context['existing_relationships'] = set(
|
existing_relationships = set()
|
||||||
|
try:
|
||||||
|
existing_relationships = set(
|
||||||
self.request.user.person.relationship_targets.values_list(
|
self.request.user.person.relationship_targets.values_list(
|
||||||
'pk', flat=True))
|
'pk', flat=True))
|
||||||
|
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
# No linked Person yet
|
||||||
|
pass
|
||||||
|
|
||||||
|
context['existing_relationships'] = existing_relationships
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +62,8 @@ class ProfileView(LoginRequiredMixin, DetailView):
|
|||||||
"""
|
"""
|
||||||
model = models.Person
|
model = models.Person
|
||||||
|
|
||||||
def get(self, request: HttpRequest, *args: typing.Any, **kwargs: typing.Any) -> HttpResponse:
|
def get(self, request: HttpRequest, *args: typing.Any,
|
||||||
|
**kwargs: typing.Any) -> HttpResponse:
|
||||||
try:
|
try:
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
@@ -64,7 +73,8 @@ class ProfileView(LoginRequiredMixin, DetailView):
|
|||||||
|
|
||||||
def get_template_names(self) -> typing.List[str]:
|
def get_template_names(self) -> typing.List[str]:
|
||||||
"""Return template depending on level of access."""
|
"""Return template depending on level of access."""
|
||||||
if (self.object.user == self.request.user) or self.request.user.is_superuser:
|
if (self.object.user
|
||||||
|
== self.request.user) or self.request.user.is_superuser:
|
||||||
return ['people/person/detail_full.html']
|
return ['people/person/detail_full.html']
|
||||||
|
|
||||||
return ['people/person/detail_partial.html']
|
return ['people/person/detail_partial.html']
|
||||||
@@ -82,9 +92,11 @@ class ProfileView(LoginRequiredMixin, DetailView):
|
|||||||
# pk was not provided in URL
|
# pk was not provided in URL
|
||||||
return self.request.user.person
|
return self.request.user.person
|
||||||
|
|
||||||
def build_question_answers(self, answer_set: models.PersonAnswerSet) -> typing.Dict[str, str]:
|
def build_question_answers(
|
||||||
|
self, answer_set: models.PersonAnswerSet) -> 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.object.user == self.request.user) or self.request.user.is_superuser
|
show_all = (self.object.user
|
||||||
|
== self.request.user) or self.request.user.is_superuser
|
||||||
questions = models.PersonQuestion.objects.filter(is_hardcoded=False)
|
questions = models.PersonQuestion.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)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class RelationshipUpdateView(permissions.UserIsLinkedPersonMixin, UpdateView):
|
|||||||
|
|
||||||
def get_test_person(self) -> models.Person:
|
def get_test_person(self) -> models.Person:
|
||||||
"""Get the person instance which should be used for access control checks."""
|
"""Get the person instance which should be used for access control checks."""
|
||||||
return self.object.source
|
return self.get_object().source
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user