Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new incorporation fields to form and sponsor model #2351

Merged
merged 12 commits into from
Jan 9, 2024
11 changes: 10 additions & 1 deletion sponsors/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,17 @@ class SponsorshipApplicationForm(forms.Form):
state = forms.CharField(
label="State/Province/Region", max_length=64, required=False
)
state_of_incorporation = forms.CharField(
label="State of incorporation", help_text="US only, If different", max_length=64, required=False
)
postal_code = forms.CharField(
label="Zip/Postal Code", max_length=64, required=False
)
country = CountryField().formfield(required=False)
country = CountryField().formfield(required=False, help_text="For mailing/contact purposes")

country_of_incorporation = CountryField().formfield(
label="Country of incorporation", help_text="For contractual purposes", required=False
)

def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user", None)
Expand Down Expand Up @@ -371,6 +378,8 @@ def save(self):
landing_page_url=self.cleaned_data.get("landing_page_url", ""),
twitter_handle=self.cleaned_data["twitter_handle"],
print_logo=self.cleaned_data.get("print_logo"),
country_of_incorporation=self.cleaned_data.get("country_of_incorporation", ""),
state_of_incorporation=self.cleaned_data.get("state_of_incorporation", ""),
)
contacts = [f.save(commit=False) for f in self.contacts_formset.forms]
for contact in contacts:
Expand Down
29 changes: 29 additions & 0 deletions sponsors/migrations/0099_auto_20231224_1615.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 2.2.24 on 2023-12-24 16:15

from django.db import migrations, models
import django_countries.fields


class Migration(migrations.Migration):

dependencies = [
('sponsors', '0098_auto_20231219_1910'),
]

operations = [
migrations.AddField(
model_name='sponsor',
name='country_of_incorporation',
field=django_countries.fields.CountryField(blank=True, help_text='For contractual purposes', max_length=2, null=True, verbose_name='Country of incorporation (If different)'),
),
migrations.AddField(
model_name='sponsor',
name='state_of_incorporation',
field=models.CharField(blank=True, default='', max_length=64, null=True, verbose_name='US only: State of incorporation (If different)'),
),
migrations.AlterField(
model_name='sponsor',
name='country',
field=django_countries.fields.CountryField(default='', help_text='For mailing/contact purposes', max_length=2),
),
]
9 changes: 8 additions & 1 deletion sponsors/models/sponsors.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ class Sponsor(ContentManageable):
postal_code = models.CharField(
verbose_name="Zip/Postal Code", max_length=64, default=""
)
country = CountryField(default="")
country = CountryField(default="", help_text="For mailing/contact purposes")
assets = GenericRelation(GenericAsset)
country_of_incorporation = CountryField(
verbose_name="Country of incorporation (If different)", help_text="For contractual purposes", blank=True, null=True
)
state_of_incorporation = models.CharField(
verbose_name="US only: State of incorporation (If different)",
max_length=64, blank=True, null=True, default=""
)

class Meta:
verbose_name = "sponsor"
Expand Down
8 changes: 7 additions & 1 deletion sponsors/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,18 @@ def test_create_sponsor_with_valid_data(self):
def test_create_sponsor_with_valid_data_for_non_required_inputs(
self,
):
user = baker.make(settings.AUTH_USER_MODEL)

self.data["description"] = "Important company"
self.data["landing_page_url"] = "https://companyx.com"
self.data["twitter_handle"] = "@companyx"
self.data["country_of_incorporation"] = "US"
self.data["state_of_incorporation"] = "NY"
self.files["print_logo"] = get_static_image_file_as_upload(
"psf-logo_print.png", "logo_print.png"
)

form = SponsorshipApplicationForm(self.data, self.files)
form = SponsorshipApplicationForm(self.data, self.files, user=user)
self.assertTrue(form.is_valid(), form.errors)

sponsor = form.save()
Expand All @@ -437,6 +441,8 @@ def test_create_sponsor_with_valid_data_for_non_required_inputs(
self.assertFalse(form.user_with_previous_sponsors)
self.assertEqual(sponsor.landing_page_url, "https://companyx.com")
self.assertEqual(sponsor.twitter_handle, "@companyx")
self.assertEqual(sponsor.country_of_incorporation, "US")
self.assertEqual(sponsor.state_of_incorporation, "NY")

def test_use_previous_user_sponsor(self):
contact = baker.make(SponsorContact, user__email="[email protected]")
Expand Down
30 changes: 28 additions & 2 deletions templates/sponsors/new_sponsorship_application_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ <h1>Submit Sponsorship Information</h1>
</p>
</div>
</div>

<div class="inline_fields">
<div>
<p class="form_field">
<label>{{ form.country.label }} <span class="error-message">{% if form.country.errors %}{{ form.country.errors.as_text }}</span>{% endif %}</label>
{% render_field form.country %}
Expand All @@ -103,6 +104,19 @@ <h1>Submit Sponsorship Information</h1>
<span class="helptext">{{ form.country.help_text }}</span>
{% endif %}
</p>
</div>
<div>
<p class="form_field">
<label>{{ form.country_of_incorporation.label }} <span class="error-message">{% if form.country_of_incorporation.errors %}
{{ form.country.errors.as_text }}</span>{% endif %}</label>
{% render_field form.country_of_incorporation %}
{% if form.country_of_incorporation.help_text %}
<br/>
<span class="helptext">{{ form.country_of_incorporation.help_text }}</span>
{% endif %}
</p>
</div>
</div>

<div class="inline_fields">
<div>
Expand Down Expand Up @@ -149,7 +163,19 @@ <h1>Submit Sponsorship Information</h1>
<span class="helptext">{{ form.state.help_text }}</span>
{% endif %}
</p>
</div>
</div>

<div>
<p class="form_field">
<label>{{ form.state_of_incorporation.label }} <span class="error-message">{% if form.state_of_incorporation.errors %}
{{ form.state_of_incorporation.errors.as_text }}</span>{% endif %}</label>
{% render_field form.state %}
{% if form.state_of_incorporation.help_text %}
<br/>
<span class="helptext">{{ form.state_of_incorporation.help_text }}</span>
{% endif %}
</p>
</div>
</div>


Expand Down
30 changes: 27 additions & 3 deletions templates/users/sponsor_info_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,29 @@ <h2>Sponsor Information</h2>
</p>
</div>
</div>

<div class="inline_fields">
<div>
<p class="form_field">
<label>{{ form.country.label }} <span class="error-message">{% if form.country.errors %}
{{ form.country.errors.as_text }}</span>{% endif %}</label>
{% render_field form.country %}
{% if form.country.help_text %}
<br/>
<span class="helptext">{{ form.country.help_text }}</span>
{% endif %}
</p>
</div>
<div>
<p class="form_field">
<label>{{ form.country_of_incorporation.label }} <span class="error-message">{% if form.country_of_incorporation.errors %}
{{ form.country.errors.as_text }}</span>{% endif %}</label>
{% render_field form.country_of_incorporation %}
{% if form.country_of_incorporation.help_text %}
<br/>
<span class="helptext">{{ form.country_of_incorporation.help_text }}</span>
{% endif %}
</p>
</div>
</div>

<div class="inline_fields">
<div>
Expand Down Expand Up @@ -131,8 +144,19 @@ <h2>Sponsor Information</h2>
<span class="helptext">{{ form.state.help_text }}</span>
{% endif %}
</p>
</div>
<div>
<p class="form_field">
<label>{{ form.state_of_incorporation.label }} <span class="error-message">{% if form.state_of_incorporation.errors %}
{{ form.state_of_incorporation.errors.as_text }}</span>{% endif %}</label>
{% render_field form.state %}
{% if form.state_of_incorporation.help_text %}
<br/>
<span class="helptext">{{ form.state_of_incorporation.help_text }}</span>
{% endif %}
</p>
</div>
</div>
</div>


<div class="inline_fields">
Expand Down