From 719b11e79e43bff369981a5c121b6f6258dac658 Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 20 Apr 2020 13:30:15 +0100 Subject: [PATCH] fix: Fix broken relationship update form Did not get values from fields correctly Incorrectly marked answersets as expired immediately --- people/forms.py | 7 ++----- people/views/relationship.py | 7 +++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/people/forms.py b/people/forms.py index 1b242dc..7757847 100644 --- a/people/forms.py +++ b/people/forms.py @@ -69,11 +69,8 @@ class RelationshipAnswerSetForm(forms.ModelForm, DynamicAnswerSetBase): if commit: # Save answers to relationship questions for key, value in self.cleaned_data.items(): - if key.startswith('question_'): - question_id = key.replace('question_', '', 1) - answer = models.RelationshipQuestionChoice.objects.get(pk=value, - question__pk=question_id) - self.instance.question_answers.add(answer) + if key.startswith('question_') and value: + self.instance.question_answers.add(value) return self.instance diff --git a/people/views/relationship.py b/people/views/relationship.py index eeb2ea6..8709b99 100644 --- a/people/views/relationship.py +++ b/people/views/relationship.py @@ -118,13 +118,12 @@ class RelationshipUpdateView(permissions.UserIsLinkedPersonMixin, CreateView): """ Mark any previous answer sets as replaced. """ - previous_valid_answer_sets = self.relationship.answer_sets.filter(replaced_timestamp__isnull=True) - response = super().form_valid(form) + now_date = timezone.now().date() # Shouldn't be more than one after initial updates after migration - for answer_set in previous_valid_answer_sets: - answer_set.replaced_timestamp = timezone.now() + for answer_set in self.relationship.answer_sets.exclude(pk=self.object.pk): + answer_set.replaced_timestamp = now_date answer_set.save() return response