8000 Default primary contact field to True for first contact (#2648) · python/pythondotorg@1da2a8a · GitHub
[go: up one dir, main page]

Skip to content

Commit 1da2a8a

Browse files
Default primary contact field to True for first contact (#2648)
Co-authored-by: Jacob Coffee <jacob@z7x.org>
1 parent c68d9e4 commit 1da2a8a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sponsors/forms.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,10 @@ def __init__(self, *args, **kwargs):
285285
if self.data:
286286
self.contacts_formset = SponsorContactFormSet(self.data, **formset_kwargs)
287287
else:
288-
self.contacts_formset = SponsorContactFormSet(**formset_kwargs)
288+
self.contacts_formset = SponsorContactFormSet(
289+
initial=[{"primary": True}],
290+
**formset_kwargs
291+
)
289292

290293
def clean(self):
291294
cleaned_data = super().clean()

sponsors/tests/test_forms.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,15 @@ def test_invalidate_form_if_no_primary_contact(self):
534534
msg = "You have to mark at least one contact as the primary one."
535535
self.assertIn(msg, form.errors["__all__"])
536536

537+
def test_initial_primary_contact(self):
538+
form = SponsorshipApplicationForm()
539+
formset = form.contacts_formset
540+
541+
self.assertTrue(
542+
formset.forms[0].initial.get("primary"),
543+
"The primary field in the first contact form should be initially set to True."
544+
)
545+
537546

538547
class SponsorContactFormSetTests(TestCase):
539548
def setUp(self):

0 commit comments

Comments
 (0)
0