mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
refactor: allow admin config of static questions
Text and visibility set in admin panel are now respected everywhere
This commit is contained in:
@@ -117,42 +117,25 @@ 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]:
|
||||
"""Collect answers to dynamic questions and join with commas."""
|
||||
show_all = self.request.user.is_superuser
|
||||
questions = models.OrganisationQuestion.objects.filter(
|
||||
is_hardcoded=False)
|
||||
if not show_all:
|
||||
questions = questions.filter(answer_is_public=True)
|
||||
|
||||
question_answers = {}
|
||||
try:
|
||||
for question in questions:
|
||||
answers = answer_set.question_answers.filter(question=question)
|
||||
question_answers[str(question)] = ', '.join(map(str, answers))
|
||||
|
||||
except AttributeError:
|
||||
# No AnswerSet yet
|
||||
pass
|
||||
|
||||
return question_answers
|
||||
|
||||
def get_context_data(self,
|
||||
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||
"""Add map marker to context."""
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
answerset = self.object.current_answers
|
||||
context['answer_set'] = answerset
|
||||
context['question_answers'] = self.build_question_answers(answerset)
|
||||
answer_set = self.object.current_answers
|
||||
context['answer_set'] = answer_set
|
||||
context['map_markers'] = [{
|
||||
'name': self.object.name,
|
||||
'lat': getattr(answerset, 'latitude', None),
|
||||
'lng': getattr(answerset, 'longitude', None),
|
||||
'lat': getattr(answer_set, 'latitude', None),
|
||||
'lng': getattr(answer_set, 'longitude', None),
|
||||
}]
|
||||
|
||||
context['question_answers'] = {}
|
||||
if answer_set is not None:
|
||||
show_all = self.request.user.is_superuser
|
||||
context['question_answers'] = answer_set.build_question_answers(
|
||||
show_all)
|
||||
|
||||
context['relationship'] = None
|
||||
try:
|
||||
relationship = models.OrganisationRelationship.objects.get(
|
||||
|
||||
@@ -94,34 +94,6 @@ class ProfileView(LoginRequiredMixin, DetailView):
|
||||
# pk was not provided in URL
|
||||
return self.request.user.person
|
||||
|
||||
def build_question_answers(
|
||||
self, answer_set: models.PersonAnswerSet) -> typing.Dict[str, str]:
|
||||
"""Collect answers to dynamic questions and join with commas."""
|
||||
show_all = ((self.object.user == self.request.user)
|
||||
or self.request.user.is_superuser)
|
||||
questions = models.PersonQuestion.objects.all()
|
||||
if not show_all:
|
||||
questions = questions.filter(answer_is_public=True)
|
||||
|
||||
question_answers = {}
|
||||
try:
|
||||
for question in questions:
|
||||
if question.is_hardcoded:
|
||||
question_answers[str(question)] = getattr(
|
||||
answer_set, question.text)
|
||||
|
||||
else:
|
||||
answers = answer_set.question_answers.filter(
|
||||
question=question)
|
||||
question_answers[str(question)] = ', '.join(
|
||||
map(str, answers))
|
||||
|
||||
except AttributeError:
|
||||
# No AnswerSet yet
|
||||
pass
|
||||
|
||||
return question_answers
|
||||
|
||||
def get_context_data(self,
|
||||
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||
"""Add current :class:`PersonAnswerSet` to context."""
|
||||
@@ -129,9 +101,15 @@ class ProfileView(LoginRequiredMixin, DetailView):
|
||||
|
||||
answer_set = self.object.current_answers
|
||||
context['answer_set'] = answer_set
|
||||
context['question_answers'] = self.build_question_answers(answer_set)
|
||||
context['map_markers'] = [get_map_data(self.object)]
|
||||
|
||||
context['question_answers'] = {}
|
||||
if answer_set is not None:
|
||||
show_all = ((self.object.user == self.request.user)
|
||||
or self.request.user.is_superuser)
|
||||
context['question_answers'] = answer_set.build_question_answers(
|
||||
show_all)
|
||||
|
||||
context['relationship'] = None
|
||||
try:
|
||||
relationship = models.Relationship.objects.get(
|
||||
|
||||
@@ -19,6 +19,23 @@ class RelationshipDetailView(permissions.UserIsLinkedPersonMixin, DetailView):
|
||||
template_name = 'people/relationship/detail.html'
|
||||
related_person_field = 'source'
|
||||
|
||||
def get_context_data(self,
|
||||
**kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
|
||||
"""Add current :class:`RelationshipAnswerSet` to context."""
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
answer_set = self.object.current_answers
|
||||
context['answer_set'] = answer_set
|
||||
|
||||
context['question_answers'] = {}
|
||||
if answer_set is not None:
|
||||
show_all = ((self.object.source == self.request.user)
|
||||
or self.request.user.is_superuser)
|
||||
context['question_answers'] = answer_set.build_question_answers(
|
||||
show_all)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class RelationshipCreateView(LoginRequiredMixin, RedirectView):
|
||||
"""View for creating a :class:`Relationship`.
|
||||
@@ -124,8 +141,7 @@ class OrganisationRelationshipEndView(RelationshipEndView):
|
||||
model = models.OrganisationRelationship
|
||||
|
||||
|
||||
class OrganisationRelationshipDetailView(permissions.UserIsLinkedPersonMixin,
|
||||
DetailView):
|
||||
class OrganisationRelationshipDetailView(RelationshipDetailView):
|
||||
"""View displaying details of an :class:`OrganisationRelationship`."""
|
||||
model = models.OrganisationRelationship
|
||||
template_name = 'people/organisation-relationship/detail.html'
|
||||
|
||||
Reference in New Issue
Block a user