Skip to content

Commit

Permalink
add new incorporation fields to form and sponsor model (#2351)
Browse files Browse the repository at this point in the history
* 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 <ewdurbin@gmail.com>
  • Loading branch information
jessiebelle and ewdurbin authored Jan 9, 2024
1 parent db9d241 commit 9b4dedd
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 43 deletions.
11 changes: 10 additions & 1 deletion sponsors/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,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 than mailing address", 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 @@ -373,6 +380,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/0100_auto_20240107_1054.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 2.2.24 on 2024-01-07 10:54

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


class Migration(migrations.Migration):

dependencies = [
('sponsors', '0099_auto_20231224_1854'),
]

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 @@ -73,8 +73,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 @@ -423,14 +423,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 @@ -440,6 +444,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_create_sponsor_with_svg_for_print_logo(
self,
Expand Down
126 changes: 91 additions & 35 deletions templates/sponsors/new_sponsorship_application_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
{% load boxes widget_tweaks %}
{% load humanize %}
{% load sponsors %}
{% block page_title %}Sponsorship Information{% endblock %}


{% block page_title %}Submit Sponsorship Information{% endblock %}

{% block content %}
<article id="new_sponsorship_application_container" class="text">
<h1>Submit Sponsorship Information</h1>

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

<h1>Submit Sponsorship Information</h1>
{% endif %}


{% if form.errors %}
<span class="error-message">The form has one or more errors</span>
{{ form.non_field_errors }}
Expand All @@ -53,6 +61,8 @@ <h1>Submit Sponsorship Information</h1>

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

<h2>Basics</h2>

<p class="form_field">
<label>{{ form.name.label }} <span class="error-message">{% if form.name.errors %}{{ form.name.errors.as_text }}</span>{% endif %}</label>
{% render_field form.name %}
Expand All @@ -62,6 +72,33 @@ <h1>Submit Sponsorship Information</h1>
{% endif %}
</p>


<div class="inline_fields">
<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>
<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>

<p class="form_field">
<label>{{ form.description.label }} <span class="error-message">{% if form.description.errors %}{{ form.description.errors.as_text }}</span>{% endif %}</label>
{% render_field form.description %}
Expand Down Expand Up @@ -95,14 +132,39 @@ <h1>Submit Sponsorship Information</h1>
</div>
</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 class="inline_fields">
<div>
<p class="form_field">
<label>{{ form.web_logo.label }} <span class="error-message">{% if form.web_logo.errors %}{{ form.web_logo.errors.as_text }}</span>{% endif %}</label>
{% render_field form.web_logo %}
{% if sponsor.web_logo %}
<p>Currently: <a href="{{ sponsor.web_logo.url }}">{{ sponsor.web_logo.name }}</a></p>
{% endif %}
{% if form.web_logo.help_text %}
<br/>
<span class="helptext">{{ form.web_logo.help_text }}</span>
{% endif %}
</p>
</div>

<div>
<p class="form_field">
<label>{{ form.print_logo.label }} <span class="error-message">{% if form.print_logo.errors %}{{ form.print_logo.errors.as_text }}</span>{% endif %}</label>
{% render_field form.print_logo %}
{% if sponsor.print_logo %}
<p>Currently: <a href="{{ sponsor.print_logo.url }}">{{ sponsor.print_logo.name }}</a></p>
{% endif %}
{% if form.print_logo.help_text %}
<br/>
<span class="helptext">{{ form.print_logo.help_text }}</span>
{% endif %}
</p>
</div>
</div>

<hr>

<h2>Mailing and Contact</h2>

<div class="inline_fields">
<div>
Expand Down Expand Up @@ -167,37 +229,26 @@ <h1>Submit Sponsorship Information</h1>

<div>
<p class="form_field">
<label>{{ form.primary_phone.label }} <span class="error-message">{% if form.primary_phone.errors %}{{ form.primary_phone.errors.as_text }}</span>{% endif %}</label>
{% render_field form.primary_phone %}
{% if form.primary_phone.help_text %}
<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.primary_phone.help_text }}</span>
<span class="helptext">{{ form.country.help_text }}</span>
{% endif %}
</p>
</div>
</div>

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

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

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

<button class="formset-btn add-form-row" type="button">Extra contact</button>
</div>

{% if sponsor %}
<div class="form-actions">
<input type="submit" name="submit-btn" value="Save"/>
</div>
{% else %}
</div>

<input id="submit-btn" type="submit" value="Apply">
</form>
{% endif %}
</article>

{% endblock content %}
Expand Down
55 changes: 52 additions & 3 deletions templates/users/sponsor_info_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{% block user_content %}
<div id="edit-sponsor-information">
<h1>Edit {{ sponsor }}</h1>
<h2>Basics</h2>

{% if form.errors %}
<span class="error-message">The form has one or more errors</span>
Expand All @@ -36,7 +37,31 @@ <h2>Sponsor Information</h2>
{% endif %}
{% render_field form.name %}
</p>
<div class="inline_fields">
<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>
<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>
<p class="form_field">
<label>{{ form.description.label }} <span class="error-message">{% if form.description.errors %}
{{ form.description.errors.as_text }}</span>{% endif %}</label>
Expand Down Expand Up @@ -69,16 +94,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 +169,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
2 changes: 1 addition & 1 deletion users/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def test_display_template_with_sponsor_info(self):
response = self.client.get(self.url)
context = response.context

self.assertTemplateUsed(response, "users/sponsor_info_update.html")
self.assertTemplateUsed(response, "sponsors/new_sponsorship_application_form.html")
self.assertEqual(context["sponsor"], self.sponsor)
self.assertIsInstance(context["form"], SponsorUpdateForm)

Expand Down
Loading

0 comments on commit 9b4dedd

Please sign in to comment.