mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
fix: Fix broken relationship update form
Did not get values from fields correctly Incorrectly marked answersets as expired immediately
This commit is contained in:
@@ -69,11 +69,8 @@ class RelationshipAnswerSetForm(forms.ModelForm, DynamicAnswerSetBase):
|
|||||||
if commit:
|
if commit:
|
||||||
# Save answers to relationship questions
|
# Save answers to relationship questions
|
||||||
for key, value in self.cleaned_data.items():
|
for key, value in self.cleaned_data.items():
|
||||||
if key.startswith('question_'):
|
if key.startswith('question_') and value:
|
||||||
question_id = key.replace('question_', '', 1)
|
self.instance.question_answers.add(value)
|
||||||
answer = models.RelationshipQuestionChoice.objects.get(pk=value,
|
|
||||||
question__pk=question_id)
|
|
||||||
self.instance.question_answers.add(answer)
|
|
||||||
|
|
||||||
return self.instance
|
return self.instance
|
||||||
|
|
||||||
|
|||||||
@@ -118,13 +118,12 @@ class RelationshipUpdateView(permissions.UserIsLinkedPersonMixin, CreateView):
|
|||||||
"""
|
"""
|
||||||
Mark any previous answer sets as replaced.
|
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)
|
response = super().form_valid(form)
|
||||||
|
now_date = timezone.now().date()
|
||||||
|
|
||||||
# Shouldn't be more than one after initial updates after migration
|
# Shouldn't be more than one after initial updates after migration
|
||||||
for answer_set in previous_valid_answer_sets:
|
for answer_set in self.relationship.answer_sets.exclude(pk=self.object.pk):
|
||||||
answer_set.replaced_timestamp = timezone.now()
|
answer_set.replaced_timestamp = now_date
|
||||||
answer_set.save()
|
answer_set.save()
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|||||||
Reference in New Issue
Block a user