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:
|
||||
# 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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user