Skip to content

Commit 6ed24d9

Browse files
authored
Merge pull request #560 from iMMAP/iMMAP/fix/create_project_domains_issue
[Fix] - retain selections of activity domains during failed post request
2 parents 0724d71 + b591352 commit 6ed24d9

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/rh/forms.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ def __init__(self, *args, **kwargs):
106106
self.fields["activity_domains"].choices = (
107107
self.fields["activity_domains"]
108108
.queryset.filter(
109-
clusters__in=self.instance.clusters.all(), is_active=True, countries=user.profile.country
109+
clusters__in=self.data.getlist("clusters") or self.instance.clusters.all(),
110+
is_active=True,
111+
countries=user.profile.country,
110112
)
111113
.order_by("name")
112114
.values_list("id", "name")
@@ -122,8 +124,17 @@ def __init__(self, *args, **kwargs):
122124
pk__in=user_clusters.union(project_clusters).values("pk")
123125
)
124126
else:
125-
# Create mode
126-
self.fields["activity_domains"].choices = []
127+
# Create mode and POST mode: Ensure activity_domains is populated
128+
self.fields["activity_domains"].choices = (
129+
self.fields["activity_domains"]
130+
.queryset.filter(
131+
clusters__in=self.data.getlist("clusters") or user.profile.clusters.all(),
132+
is_active=True,
133+
countries=user.profile.country,
134+
)
135+
.order_by("name")
136+
.values_list("id", "name")
137+
)
127138

128139

129140
class TargetLocationForm(forms.ModelForm):

0 commit comments

Comments
 (0)