Skip to content

Commit 9b4dedd

Browse files
add new incorporation fields to form and sponsor model (#2351)
* adding new fields to form and sponsor model * adding new optional fields to update sponsor application form * fix migrations * modifying existing tests to assert new fields are correctly saved * Re-structure and re-order sponsor information form * update and refactor of new_sponsorship_application_form to be usable for editing * remove migration * new migration file added * merge * add migration * fix tests to reflect update in template --------- Co-authored-by: Ee Durbin <[email protected]>
1 parent db9d241 commit 9b4dedd

File tree

8 files changed

+199
-43
lines changed

8 files changed

+199
-43
lines changed

sponsors/forms.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,17 @@ class SponsorshipApplicationForm(forms.Form):
253253
state = forms.CharField(
254254
label="State/Province/Region", max_length=64, required=False
255255
)
256+
state_of_incorporation = forms.CharField(
257+
label="State of incorporation", help_text="US only, If different than mailing address", max_length=64, required=False
258+
)
256259
postal_code = forms.CharField(
257260
label="Zip/Postal Code", max_length=64, required=False
258261
)
259-
country = CountryField().formfield(required=False)
262+
country = CountryField().formfield(required=False, help_text="For mailing/contact purposes")
263+
264+
country_of_incorporation = CountryField().formfield(
265+
label="Country of incorporation", help_text="For contractual purposes", required=False
266+
)
260267

261268
def __init__(self, *args, **kwargs):
262269
self.user = kwargs.pop("user", None)
@@ -373,6 +380,8 @@ def save(self):
373380
landing_page_url=self.cleaned_data.get("landing_page_url", ""),
374381
twitter_handle=self.cleaned_data["twitter_handle"],
375382
print_logo=self.cleaned_data.get("print_logo"),
383+
country_of_incorporation=self.cleaned_data.get("country_of_incorporation", ""),
384+
state_of_incorporation=self.cleaned_data.get("state_of_incorporation", ""),
376385
)
377386
contacts = [f.save(commit=False) for f in self.contacts_formset.forms]
378387
for contact in contacts:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 2.2.24 on 2024-01-07 10:54
2+
3+
from django.db import migrations, models
4+
import django_countries.fields
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('sponsors', '0099_auto_20231224_1854'),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name='sponsor',
16+
name='country_of_incorporation',
17+
field=django_countries.fields.CountryField(blank=True, help_text='For contractual purposes', max_length=2, null=True, verbose_name='Country of incorporation (If different)'),
18+
),
19+
migrations.AddField(
20+
model_name='sponsor',
21+
name='state_of_incorporation',
22+
field=models.CharField(blank=True, default='', max_length=64, null=True, verbose_name='US only: State of incorporation (If different)'),
23+
),
24+
migrations.AlterField(
25+
model_name='sponsor',
26+
name='country',
27+
field=django_countries.fields.CountryField(default='', help_text='For mailing/contact purposes', max_length=2),
28+
),
29+
]

sponsors/models/sponsors.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,15 @@ class Sponsor(ContentManageable):
7373
postal_code = models.CharField(
7474
verbose_name="Zip/Postal Code", max_length=64, default=""
7575
)
76-
country = CountryField(default="")
76+
country = CountryField(default="", help_text="For mailing/contact purposes")
7777
assets = GenericRelation(GenericAsset)
78+
country_of_incorporation = CountryField(
79+
verbose_name="Country of incorporation (If different)", help_text="For contractual purposes", blank=True, null=True
80+
)
81+
state_of_incorporation = models.CharField(
82+
verbose_name="US only: State of incorporation (If different)",
83+
max_length=64, blank=True, null=True, default=""
84+
)
7885

7986
class Meta:
8087
verbose_name = "sponsor"

sponsors/tests/test_forms.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -423,14 +423,18 @@ def test_create_sponsor_with_valid_data(self):
423423
def test_create_sponsor_with_valid_data_for_non_required_inputs(
424424
self,
425425
):
426+
user = baker.make(settings.AUTH_USER_MODEL)
427+
426428
self.data["description"] = "Important company"
427429
self.data["landing_page_url"] = "https://companyx.com"
428430
self.data["twitter_handle"] = "@companyx"
431+
self.data["country_of_incorporation"] = "US"
432+
self.data["state_of_incorporation"] = "NY"
429433
self.files["print_logo"] = get_static_image_file_as_upload(
430434
"psf-logo_print.png", "logo_print.png"
431435
)
432436

433-
form = SponsorshipApplicationForm(self.data, self.files)
437+
form = SponsorshipApplicationForm(self.data, self.files, user=user)
434438
self.assertTrue(form.is_valid(), form.errors)
435439

436440
sponsor = form.save()
@@ -440,6 +444,8 @@ def test_create_sponsor_with_valid_data_for_non_required_inputs(
440444
self.assertFalse(form.user_with_previous_sponsors)
441445
self.assertEqual(sponsor.landing_page_url, "https://companyx.com")
442446
self.assertEqual(sponsor.twitter_handle, "@companyx")
447+
self.assertEqual(sponsor.country_of_incorporation, "US")
448+
self.assertEqual(sponsor.state_of_incorporation, "NY")
443449

444450
def test_create_sponsor_with_svg_for_print_logo(
445451
self,

templates/sponsors/new_sponsorship_application_form.html

+91-35
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
{% load boxes widget_tweaks %}
33
{% load humanize %}
44
{% load sponsors %}
5+
{% block page_title %}Sponsorship Information{% endblock %}
56

67

7-
{% block page_title %}Submit Sponsorship Information{% endblock %}
88

99
{% block content %}
1010
<article id="new_sponsorship_application_container" class="text">
11-
<h1>Submit Sponsorship Information</h1>
1211

13-
<div id="sponsorship-info-container" class="user-feedback level-general">
12+
{% if sponsor %}
13+
<div>
14+
<h1> Edit {{sponsor}}</h1>
15+
</div>
16+
{% else %}
17+
<div id="sponsorship-info-container" class="user-feedback level-general">
1418
{% if sponsorship_package %}
1519
<p>
1620
You selected the <b>{{ sponsorship_package.name }}</b> package {% if sponsorship_price %}costing ${{ sponsorship_price|intcomma }} USD {% endif %}and the following benefits:
@@ -34,6 +38,10 @@ <h1>Submit Sponsorship Information</h1>
3438
<span class="remove"><label id="close-info-container">Close</label> | <a href="{% url 'select_sponsorship_application_benefits' %}">Back to select benefits</a></span>
3539
</div>
3640

41+
<h1>Submit Sponsorship Information</h1>
42+
{% endif %}
43+
44+
3745
{% if form.errors %}
3846
<span class="error-message">The form has one or more errors</span>
3947
{{ form.non_field_errors }}
@@ -53,6 +61,8 @@ <h1>Submit Sponsorship Information</h1>
5361

5462
<div id="new-appication-fields" {% if form.user_with_previous_sponsors and not form.errors %}style="display: none"{% endif %}>
5563

64+
<h2>Basics</h2>
65+
5666
<p class="form_field">
5767
<label>{{ form.name.label }} <span class="error-message">{% if form.name.errors %}{{ form.name.errors.as_text }}</span>{% endif %}</label>
5868
{% render_field form.name %}
@@ -62,6 +72,33 @@ <h1>Submit Sponsorship Information</h1>
6272
{% endif %}
6373
</p>
6474

75+
76+
<div class="inline_fields">
77+
<div>
78+
<p class="form_field">
79+
<label>{{ form.country_of_incorporation.label }} <span class="error-message">{% if form.country_of_incorporation.errors %}
80+
{{ form.country.errors.as_text }}</span>{% endif %}</label>
81+
{% render_field form.country_of_incorporation %}
82+
{% if form.country_of_incorporation.help_text %}
83+
<br/>
84+
<span class="helptext">{{ form.country_of_incorporation.help_text }}</span>
85+
{% endif %}
86+
</p>
87+
</div>
88+
89+
<div>
90+
<p class="form_field">
91+
<label>{{ form.state_of_incorporation.label }} <span class="error-message">{% if form.state_of_incorporation.errors %}
92+
{{ form.state_of_incorporation.errors.as_text }}</span>{% endif %}</label>
93+
{% render_field form.state %}
94+
{% if form.state_of_incorporation.help_text %}
95+
<br/>
96+
<span class="helptext">{{ form.state_of_incorporation.help_text }}</span>
97+
{% endif %}
98+
</p>
99+
</div>
100+
</div>
101+
65102
<p class="form_field">
66103
<label>{{ form.description.label }} <span class="error-message">{% if form.description.errors %}{{ form.description.errors.as_text }}</span>{% endif %}</label>
67104
{% render_field form.description %}
@@ -95,14 +132,39 @@ <h1>Submit Sponsorship Information</h1>
95132
</div>
96133
</div>
97134

98-
<p class="form_field">
99-
<label>{{ form.country.label }} <span class="error-message">{% if form.country.errors %}{{ form.country.errors.as_text }}</span>{% endif %}</label>
100-
{% render_field form.country %}
101-
{% if form.country.help_text %}
102-
<br/>
103-
<span class="helptext">{{ form.country.help_text }}</span>
104-
{% endif %}
105-
</p>
135+
<div class="inline_fields">
136+
<div>
137+
<p class="form_field">
138+
<label>{{ form.web_logo.label }} <span class="error-message">{% if form.web_logo.errors %}{{ form.web_logo.errors.as_text }}</span>{% endif %}</label>
139+
{% render_field form.web_logo %}
140+
{% if sponsor.web_logo %}
141+
<p>Currently: <a href="{{ sponsor.web_logo.url }}">{{ sponsor.web_logo.name }}</a></p>
142+
{% endif %}
143+
{% if form.web_logo.help_text %}
144+
<br/>
145+
<span class="helptext">{{ form.web_logo.help_text }}</span>
146+
{% endif %}
147+
</p>
148+
</div>
149+
150+
<div>
151+
<p class="form_field">
152+
<label>{{ form.print_logo.label }} <span class="error-message">{% if form.print_logo.errors %}{{ form.print_logo.errors.as_text }}</span>{% endif %}</label>
153+
{% render_field form.print_logo %}
154+
{% if sponsor.print_logo %}
155+
<p>Currently: <a href="{{ sponsor.print_logo.url }}">{{ sponsor.print_logo.name }}</a></p>
156+
{% endif %}
157+
{% if form.print_logo.help_text %}
158+
<br/>
159+
<span class="helptext">{{ form.print_logo.help_text }}</span>
160+
{% endif %}
161+
</p>
162+
</div>
163+
</div>
164+
165+
<hr>
166+
167+
<h2>Mailing and Contact</h2>
106168

107169
<div class="inline_fields">
108170
<div>
@@ -167,37 +229,26 @@ <h1>Submit Sponsorship Information</h1>
167229

168230
<div>
169231
<p class="form_field">
170-
<label>{{ form.primary_phone.label }} <span class="error-message">{% if form.primary_phone.errors %}{{ form.primary_phone.errors.as_text }}</span>{% endif %}</label>
171-
{% render_field form.primary_phone %}
172-
{% if form.primary_phone.help_text %}
232+
<label>{{ form.country.label }} <span class="error-message">{% if form.country.errors %}{{ form.country.errors.as_text }}</span>{% endif %}</label>
233+
{% render_field form.country %}
234+
{% if form.country.help_text %}
173235
<br/>
174-
<span class="helptext">{{ form.primary_phone.help_text }}</span>
236+
<span class="helptext">{{ form.country.help_text }}</span>
175237
{% endif %}
176238
</p>
177239
</div>
178240
</div>
179241

180242
<div class="inline_fields">
181243
<div>
182-
<p class="form_field">
183-
<label>{{ form.web_logo.label }} <span class="error-message">{% if form.web_logo.errors %}{{ form.web_logo.errors.as_text }}</span>{% endif %}</label>
184-
{% render_field form.web_logo %}
185-
{% if form.web_logo.help_text %}
186-
<br/>
187-
<span class="helptext">{{ form.web_logo.help_text }}</span>
188-
{% endif %}
189-
</p>
190-
</div>
191-
192-
<div>
193-
<p class="form_field">
194-
<label>{{ form.print_logo.label }} <span class="error-message">{% if form.print_logo.errors %}{{ form.print_logo.errors.as_text }}</span>{% endif %}</label>
195-
{% render_field form.print_logo %}
196-
{% if form.print_logo.help_text %}
197-
<br/>
198-
<span class="helptext">{{ form.print_logo.help_text }}</span>
199-
{% endif %}
200-
</p>
244+
<p class="form_field">
245+
<label>{{ form.primary_phone.label }} <span class="error-message">{% if form.primary_phone.errors %}{{ form.primary_phone.errors.as_text }}</span>{% endif %}</label>
246+
{% render_field form.primary_phone %}
247+
{% if form.primary_phone.help_text %}
248+
<br/>
249+
<span class="helptext">{{ form.primary_phone.help_text }}</span>
250+
{% endif %}
251+
</p>
201252
</div>
202253
</div>
203254

@@ -216,11 +267,16 @@ <h1>Contacts</h1>
216267

217268
<button class="formset-btn add-form-row" type="button">Extra contact</button>
218269
</div>
219-
270+
{% if sponsor %}
271+
<div class="form-actions">
272+
<input type="submit" name="submit-btn" value="Save"/>
273+
</div>
274+
{% else %}
220275
</div>
221276

222277
<input id="submit-btn" type="submit" value="Apply">
223278
</form>
279+
{% endif %}
224280
</article>
225281

226282
{% endblock content %}

templates/users/sponsor_info_update.html

+52-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
{% block user_content %}
1818
<div id="edit-sponsor-information">
1919
<h1>Edit {{ sponsor }}</h1>
20+
<h2>Basics</h2>
2021

2122
{% if form.errors %}
2223
<span class="error-message">The form has one or more errors</span>
@@ -36,7 +37,31 @@ <h2>Sponsor Information</h2>
3637
{% endif %}
3738
{% render_field form.name %}
3839
</p>
40+
<div class="inline_fields">
41+
<div>
42+
<p class="form_field">
43+
<label>{{ form.country_of_incorporation.label }} <span class="error-message">{% if form.country_of_incorporation.errors %}
44+
{{ form.country.errors.as_text }}</span>{% endif %}</label>
45+
{% render_field form.country_of_incorporation %}
46+
{% if form.country_of_incorporation.help_text %}
47+
<br/>
48+
<span class="helptext">{{ form.country_of_incorporation.help_text }}</span>
49+
{% endif %}
50+
</p>
51+
</div>
3952

53+
<div>
54+
<p class="form_field">
55+
<label>{{ form.state_of_incorporation.label }} <span class="error-message">{% if form.state_of_incorporation.errors %}
56+
{{ form.state_of_incorporation.errors.as_text }}</span>{% endif %}</label>
57+
{% render_field form.state %}
58+
{% if form.state_of_incorporation.help_text %}
59+
<br/>
60+
<span class="helptext">{{ form.state_of_incorporation.help_text }}</span>
61+
{% endif %}
62+
</p>
63+
</div>
64+
</div>
4065
<p class="form_field">
4166
<label>{{ form.description.label }} <span class="error-message">{% if form.description.errors %}
4267
{{ form.description.errors.as_text }}</span>{% endif %}</label>
@@ -69,16 +94,29 @@ <h2>Sponsor Information</h2>
6994
</p>
7095
</div>
7196
</div>
72-
97+
<div class="inline_fields">
98+
<div>
7399
<p class="form_field">
74100
<label>{{ form.country.label }} <span class="error-message">{% if form.country.errors %}
75101
{{ form.country.errors.as_text }}</span>{% endif %}</label>
76102
{% render_field form.country %}
77103
{% if form.country.help_text %}
78-
<br/>
79104
<span class="helptext">{{ form.country.help_text }}</span>
80105
{% endif %}
81106
</p>
107+
</div>
108+
<div>
109+
<p class="form_field">
110+
<label>{{ form.country_of_incorporation.label }} <span class="error-message">{% if form.country_of_incorporation.errors %}
111+
{{ form.country.errors.as_text }}</span>{% endif %}</label>
112+
{% render_field form.country_of_incorporation %}
113+
{% if form.country_of_incorporation.help_text %}
114+
<br/>
115+
<span class="helptext">{{ form.country_of_incorporation.help_text }}</span>
116+
{% endif %}
117+
</p>
118+
</div>
119+
</div>
82120

83121
<div class="inline_fields">
84122
<div>
@@ -131,8 +169,19 @@ <h2>Sponsor Information</h2>
131169
<span class="helptext">{{ form.state.help_text }}</span>
132170
{% endif %}
133171
</p>
172+
</div>
173+
<div>
174+
<p class="form_field">
175+
<label>{{ form.state_of_incorporation.label }} <span class="error-message">{% if form.state_of_incorporation.errors %}
176+
{{ form.state_of_incorporation.errors.as_text }}</span>{% endif %}</label>
177+
{% render_field form.state %}
178+
{% if form.state_of_incorporation.help_text %}
179+
<br/>
180+
<span class="helptext">{{ form.state_of_incorporation.help_text }}</span>
181+
{% endif %}
182+
</p>
183+
</div>
134184
</div>
135-
</div>
136185

137186

138187
<div class="inline_fields">

users/tests/test_views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def test_display_template_with_sponsor_info(self):
489489
response = self.client.get(self.url)
490490
context = response.context
491491

492-
self.assertTemplateUsed(response, "users/sponsor_info_update.html")
492+
self.assertTemplateUsed(response, "sponsors/new_sponsorship_application_form.html")
493493
self.assertEqual(context["sponsor"], self.sponsor)
494494
self.assertIsInstance(context["form"], SponsorUpdateForm)
495495

0 commit comments

Comments
 (0)