Skip to content

Commit

Permalink
fix: Make sure StudyStart remembers trajectory names
Browse files Browse the repository at this point in the history
  • Loading branch information
miggol committed Aug 16, 2024
1 parent 1d597ea commit 9911897
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions proposals/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,15 @@ def __init__(self, *args, **kwargs):

super(StudyStartForm, self).__init__(*args, **kwargs)

for field, name in self._get_study_names().items():
self.fields[field].initial = name

def _get_study_names(self,):
names = {}
for n, study in enumerate(self.proposal.study_set.all()):
study_name = "study_name_" + str(n + 1)
self.fields[study_name].initial = study.name
names[study_name] = study.name
return names

def clean(self):
"""
Expand All @@ -719,7 +725,10 @@ def clean(self):
- If studies_similar is set to False, make sure studies_number is set (and higher than 2)
- If studies_number is set, make sure the corresponding name fields are filled.
"""
cleaned_data = super(StudyStartForm, self).clean()
# Start with study names
cleaned_data = self._get_study_names()
# Update with provided form data
cleaned_data.update(super().clean())

if cleaned_data["studies_similar"] is None:
self.add_error(
Expand Down

0 comments on commit 9911897

Please sign in to comment.