Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
Add contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich Tier committed Jan 19, 2017
1 parent f651c0b commit 6ca91ed
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
40 changes: 38 additions & 2 deletions company/forms.py
@@ -1,10 +1,12 @@
from django import forms

from directory_validators.constants import choices

from django import forms

SELECT_LABEL = 'Please select an industry'


class PublicProfileSearchForm(forms.Form):
SELECT_LABEL = 'Please select an industry'
sectors = forms.ChoiceField(
label='Show UK companies in:',
choices=[['', SELECT_LABEL]] + list(choices.COMPANY_CLASSIFICATIONS),
Expand All @@ -25,3 +27,37 @@ def __init__(self, *args, **kwargs):

def clean_page(self):
return self.cleaned_data['page'] or self.fields['page'].initial


class ContactCompanyForm(forms.Form):
full_name = forms.CharField(
label='Your full name:',
max_length=255,
)
company_name = forms.CharField(
label='Your company name:',
max_length=255,
)
country = forms.CharField(
max_length=255,
)
email_address = forms.EmailField(
label='Your email address:',
)
sector = forms.ChoiceField(
label='Industry:',
choices=(
[['', SELECT_LABEL]] + list(choices.COMPANY_CLASSIFICATIONS)
),
)
subject = forms.CharField(
label='Enter a subject line for your message:',
help_text='Maximum 200 characters.',
max_length=200,
)
body = forms.CharField(
label='Enter your message to the UK company:',
help_text='Maximum 1000 characters.',
max_length=1000,
widget=forms.Textarea
)
22 changes: 22 additions & 0 deletions company/tests/test_forms.py
Expand Up @@ -42,3 +42,25 @@ def test_public_profile_search_form_valid_data():
form = forms.PublicProfileSearchForm(data=data)

assert form.is_valid() is True


def test_contact_company_form_required_fields():
form = forms.ContactCompanyForm()

assert form.fields['full_name'].required is True
assert form.fields['company_name'].required is True
assert form.fields['country'].required is True
assert form.fields['email_address'].required is True
assert form.fields['sector'].required is True
assert form.fields['subject'].required is True
assert form.fields['body'].required is True


def test_contact_company__form_length_of_fields():
form = forms.ContactCompanyForm()

assert form.fields['full_name'].max_length == 255
assert form.fields['company_name'].max_length == 255
assert form.fields['country'].max_length == 255
assert form.fields['subject'].max_length == 200
assert form.fields['body'].max_length == 1000

0 comments on commit 6ca91ed

Please sign in to comment.