Example #1
0
class UserAccount(forms.Form):
    PASSWORD_HELP_TEXT = ('<p>Your password must:</p>'
                          '<ul class="list list-bullet">'
                          '<li>be at least 10 characters</li>'
                          '<li>contain at least one letter</li>'
                          '<li>contain at least one number</li>'
                          '<li>not contain the word "password"</li>'
                          '</ul>')
    MESSAGE_NOT_MATCH = "Passwords don't match"

    email = fields.EmailField(label='Your email')
    password = fields.CharField(help_text=mark_safe(PASSWORD_HELP_TEXT),
                                widget=PasswordInput)
    password_confirmed = fields.CharField(
        label='Confirm password',
        widget=PasswordInput,
    )
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = fields.BooleanField(label=mark_safe(
        'Tick this box to accept the '
        f'<a href="{urls.TERMS_AND_CONDITIONS}" target="_blank">terms and '
        'conditions</a> of the great.gov.uk service.'))

    def clean_password_confirmed(self):
        value = self.cleaned_data['password_confirmed']
        if value != self.cleaned_data['password']:
            raise ValidationError(self.MESSAGE_NOT_MATCH)
        return value
Example #2
0
class LeadGenerationForm(ZendeskActionMixin, forms.Form):
    error_css_class = 'input-field-container has-error'
    PLEASE_SELECT_LABEL = _('Please select an industry')
    TERMS_CONDITIONS_MESSAGE = _(
        'Tick the box to confirm you agree to the terms and conditions.')

    full_name = fields.CharField(label=_('Your name'))
    email_address = fields.EmailField(label=_('Email address'))
    company_name = fields.CharField(label=_('Organisation name'))
    country = fields.CharField(label=_('Country'))
    comment = fields.CharField(label=_('Describe what you need'),
                               help_text=_('Maximum 1000 characters.'),
                               max_length=1000,
                               widget=Textarea,
                               validators=[no_html, not_contains_url_or_email])
    terms = fields.BooleanField(
        error_messages={'required': TERMS_CONDITIONS_MESSAGE})
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )

    @property
    def serialized_data(self):
        # this data will be sent to zendesk. `captcha` and `terms_agreed` are
        # not useful to the zendesk user as those fields have to be present
        # for the form to be submitted.
        data = self.cleaned_data.copy()
        del data['captcha']
        del data['terms']
        return data
Example #3
0
class SoleTraderBusinessDetails(forms.Form):
    company_name = fields.CharField(label='Business name')
    postal_code = fields.CharField(label='Business postcode',
                                   required=False,
                                   disabled=True)
    address = fields.CharField(
        disabled=True,
        required=False,
        widget=Textarea(attrs={'rows': 3}),
    )
    industry = fields.ChoiceField(
        label='What industry is your business in?',
        choices=INDUSTRY_CHOICES,
    )
    website_address = fields.URLField(
        label='What\'s your business web address (optional)',
        help_text='The website address must start with http:// or https://',
        required=False,
    )

    def __init__(self, initial, *args, **kwargs):
        super().__init__(initial=initial, *args, **kwargs)
        # force the form to use the initial value rather than the value
        # the user submitted in previous sessions
        # on GET the data structure is a MultiValueDict. on POST the data
        # structure is a QueryDict
        if self.data and not isinstance(self.data, QueryDict):
            self.initial_to_data('company_name')
            self.initial_to_data('postal_code')
            self.initial_to_data('address')

    def initial_to_data(self, field_name):
        self.data.setlist(self.add_prefix(field_name),
                          [self.initial[field_name]])
Example #4
0
class InternationalContactForm(SerializeDataMixin, GovNotifyActionMixin,
                               forms.Form):

    ORGANISATION_TYPE_CHOICES = (
        ('COMPANY', 'Company'),
        ('OTHER', 'Other type of organisation'),
    )

    given_name = fields.CharField(validators=anti_phising_validators)
    family_name = fields.CharField(validators=anti_phising_validators)
    email = fields.EmailField(label='Email address')
    organisation_type = fields.ChoiceField(label_suffix='',
                                           widget=widgets.RadioSelect(),
                                           choices=ORGANISATION_TYPE_CHOICES)
    organisation_name = fields.CharField(
        label='Your organisation name',
        validators=anti_phising_validators,
    )
    country_name = fields.ChoiceField(choices=[('', 'Please select')] +
                                      choices.COUNTRY_CHOICES, )
    city = fields.CharField(label='City', validators=anti_phising_validators)
    comment = fields.CharField(label='Tell us how we can help',
                               widget=Textarea,
                               validators=anti_phising_validators)
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = fields.BooleanField(label=TERMS_LABEL)
Example #5
0
class PersonalDetailsForm(forms.Form):

    first_name = fields.CharField(label='First name')
    last_name = fields.CharField(label='Last name')
    position = fields.CharField(label='Position in organisation')
    email = fields.EmailField(label='Email address')
    phone = fields.CharField(label='Phone')
Example #6
0
class CompaniesHouseSearch(forms.Form):
    MESSAGE_COMPANY_NOT_FOUND = (
        "<p>Your business name is not listed.</p>"
        "<p>Check that you've entered the right name.</p>"
        "<p>Or "
        "<a href='{url}'>change type of business</a>"
        " if your business is not registered with Companies House.</p>")
    MESSAGE_COMPANY_NOT_ACTIVE = 'Company not active.'

    company_name = fields.CharField(label='Registered company name')
    company_number = fields.CharField()

    def __init__(self, session, *args, **kwargs):
        self.session = session
        super().__init__(*args, **kwargs)

    def clean(self):
        cleaned_data = super().clean()
        if 'company_number' in cleaned_data:
            company_data = helpers.get_company_profile(
                number=self.cleaned_data['company_number'],
                session=self.session,
            )
            if company_data['company_status'] != 'active':
                raise ValidationError(
                    {'company_name': self.MESSAGE_COMPANY_NOT_ACTIVE})
        else:
            url = reverse('enrolment-business-type')
            message = self.MESSAGE_COMPANY_NOT_FOUND.format(url=url)
            raise ValidationError({'company_name': mark_safe(message)})
Example #7
0
class BaseShortForm(forms.Form):
    comment = fields.CharField(
        label='Please give us as much detail as you can',
        widget=Textarea,
        validators=anti_phising_validators)
    given_name = fields.CharField(
        label='First name',
        validators=anti_phising_validators,
    )
    family_name = fields.CharField(label='Last name',
                                   validators=anti_phising_validators)
    email = fields.EmailField()
    company_type = fields.ChoiceField(
        label_suffix='',
        widget=widgets.RadioSelect(),
        choices=COMPANY_TYPE_CHOICES,
    )
    company_type_other = fields.ChoiceField(
        label='Type of organisation',
        label_suffix='',
        choices=(('', 'Please select'), ) + COMPANY_TYPE_OTHER_CHOICES,
        required=False,
    )
    organisation_name = fields.CharField(validators=anti_phising_validators)
    postcode = fields.CharField(validators=anti_phising_validators)
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = fields.BooleanField(label=TERMS_LABEL)
Example #8
0
class SellingOnlineOverseasBusiness(forms.Form):
    company_name = fields.CharField(required=True)
    soletrader = fields.BooleanField(
        label='I don\'t have a company number',
        required=False,
    )
    company_number = fields.CharField(
        label='Companies House Number',
        help_text='The number you received when'
        'registering your company at Companies House.',
        required=False,  # Only need if soletrader false - see clean (below)
    )
    company_postcode = fields.CharField(required=True, )
    website_address = fields.CharField(
        label='Company website',
        help_text='Website address, where we can see your products online.',
        max_length=255,
        required=True,
    )

    def clean(self):
        cleaned_data = super().clean()
        soletrader = cleaned_data.get('soletrader')
        company_number = cleaned_data.get('company_number')
        if not soletrader and not company_number:
            self.add_error(
                'company_number',
                self.fields['company_number'].error_messages['required'])
Example #9
0
class PersonalDetailsForm(forms.Form):
    error_css_class = 'input-field-container has-error'

    firstname = fields.CharField(label='Your first name')
    lastname = fields.CharField(label='Your last name')
    position = fields.CharField(label='Position in company')
    email = fields.EmailField(label='Email address')
    phone = fields.CharField(label='Phone')
Example #10
0
class PersonalDetails(forms.Form):

    given_name = fields.CharField(label='First name', )
    family_name = fields.CharField(label='Last name', )
    job_title = fields.CharField()
    phone_number = fields.CharField(label='Phone number (optional)',
                                    required=False)
    confirmed_is_company_representative = fields.BooleanField(
        label=('I confirm that I have the right to act for this business. I '
               'understand that great.gov.uk might write to this business to '
               'confirm I can create an account.'))
Example #11
0
class PersonalDetails(forms.Form):

    given_name = fields.CharField(label='First name', )
    family_name = fields.CharField(label='Last name', )
    job_title = fields.CharField()
    phone_number = fields.CharField(label='Phone number (optional)',
                                    required=False)

    confirmed_is_company_representative = fields.BooleanField(
        label='I verify that I am an official representative of...')
    confirmed_background_checks = fields.BooleanField(
        label='I understand that DIT may run background checks...')
Example #12
0
class CaseStudyBasicInfoForm(forms.Form):
    title = fields.CharField(
        label='Showcase title',
        max_length=60,
        validators=[directory_validators.company.no_html],
    )
    short_summary = fields.CharField(
        label='Summary of your case study or project',
        help_text=(
            'Summarise your case study in 200 characters or fewer. This will'
            ' appear on your main business profile page.'),
        max_length=200,
        validators=[
            validators.does_not_contain_email,
            directory_validators.company.no_html,
        ],
        widget=Textarea,
    )
    description = fields.CharField(
        label='Describe your case study or project',
        help_text=(
            'Describe the project or case study in 1,000 characters or fewer. '
            'Use this space to demonstrate the value of your '
            'company to an international business audience.'),
        max_length=1000,
        validators=[
            validators.does_not_contain_email,
            directory_validators.company.no_html,
        ],
        widget=Textarea,
    )
    sector = fields.ChoiceField(
        label='Industry most relevant to your showcase',
        choices=[('', 'Select Sector')] + list(choices.INDUSTRIES))
    website = fields.URLField(
        label='The web address for your case study (optional)',
        help_text='Enter a full URL including http:// or https://',
        max_length=255,
        required=False,
    )
    keywords = fields.CharField(
        label=('Enter up to 10 keywords that describe your case study. '
               'Keywords should be separated by commas.'),
        help_text=(
            'These keywords will be used to help potential overseas buyers '
            'find your case study.'),
        max_length=1000,
        widget=Textarea,
        validators=[
            directory_validators.company.keywords_word_limit,
            directory_validators.company.keywords_special_characters,
            directory_validators.company.no_html,
        ])
Example #13
0
class PIRForm(forms.Form):
    name = fields.CharField(
        required=True,
        label=_('Name'),
    )
    company = fields.CharField(
        required=True,
        label=_('Company'),
    )

    email = fields.EmailField(
        required=True,
        label=_('Email'),
    )

    phone_number = fields.CharField(
        required=False,
        label=_('Phone number (optional)'),
        widget=TextInput(attrs={'type': 'tel'})
    )

    country = fields.ChoiceField(
        required=True,
        label=_('Country'),
        choices=sorted(
            [(k, v) for k, v in COUNTRIES.items()],
            key=lambda tup: tup[1]
        )
    )

    gdpr_optin = fields.BooleanField(initial=False, required=False)

    def __init__(self, *args, **kwargs):
        super(PIRForm, self).__init__(*args, **kwargs)
        self.client = PIRAPIClient(
            base_url=settings.PIR_API_URL,
            api_key=settings.PIR_API_KEY
        )

        options = self.client.get_options()

        sector_choices = [
            (
                o['value'],
                o['display_name']) for o in options['sector']['choices']
        ]

        self.fields['sector'] = fields.ChoiceField(
            label='Sector',
            choices=sector_choices
        )

        self.fields['captcha'] = NoReCaptchaField()
Example #14
0
class SellingOnlineOverseasContactDetails(forms.Form):
    contact_name = fields.CharField(validators=anti_phising_validators)
    contact_email = fields.EmailField(label='Email address')
    phone = fields.CharField(label='Telephone number')
    email_pref = fields.BooleanField(
        label='I prefer to be contacted by email',
        required=False,
    )
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = fields.BooleanField(label=TERMS_LABEL)
Example #15
0
class AnonymousSubscribeForm(forms.Form):
    error_css_class = 'input-field-container has-error'
    PLEASE_SELECT_LABEL = _('Please select an industry')
    TERMS_CONDITIONS_MESSAGE = _(
        'Tick the box to confirm you agree to the terms and conditions.')

    full_name = fields.CharField(label=_('Your name'))
    email_address = fields.EmailField(label=_('Email address'))
    sector = fields.ChoiceField(label=_('Industry'),
                                choices=([['', PLEASE_SELECT_LABEL]] +
                                         list(choices.INDUSTRIES)))
    company_name = fields.CharField(label=_('Company name'))
    country = fields.CharField(label=_('Country'))
    terms = fields.BooleanField(
        error_messages={'required': TERMS_CONDITIONS_MESSAGE})
Example #16
0
class UserAccount(forms.Form):
    PASSWORD_HELP_TEXT = ('<p>Your password must:</p>'
                          '<ul class="list list-bullet">'
                          '<li>be at least 10 characters</li>'
                          '<li>contain at least 1 letter</li>'
                          '<li>contain at least 1 number</li>'
                          '<li>not contain the word "password"</li>'
                          '</ul>')
    MESSAGE_NOT_MATCH = "Passwords don't match"
    MESSAGE_PASSWORD_INVALID = 'Invalid Password'

    email = fields.EmailField(label='Your email address')
    password = fields.CharField(help_text=mark_safe(PASSWORD_HELP_TEXT),
                                widget=PasswordInput)
    password_confirmed = fields.CharField(
        label='Confirm password',
        widget=PasswordInput,
    )

    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )

    terms_agreed = fields.BooleanField(label=mark_safe(
        'Tick this box to accept the '
        f'<a href="{urls.TERMS_AND_CONDITIONS}" target="_blank">terms and '
        'conditions</a> of the great.gov.uk service.'))

    def clean_password_confirmed(self):
        value = self.cleaned_data['password_confirmed']
        if value != self.cleaned_data['password']:
            raise ValidationError(self.MESSAGE_NOT_MATCH)
        return value

    def clean(self):
        cleaned_data = super().clean()
        try:
            cleaned_data['user_details'] = helpers.create_user(
                email=cleaned_data['email'],
                password=cleaned_data['password'],
            )
        except HTTPError as error:
            if error.response.status_code == 400:
                self.add_error('password', self.MESSAGE_PASSWORD_INVALID)
            else:
                raise
        return None
Example #17
0
class OtherDetailsForm(forms.Form):
    error_css_class = 'input-field-container has-error'
    other_details = fields.CharField(
        label='Do you want to tell us anything else \
        about your problem? (optional)',
        widget=Textarea,
        required=False)
Example #18
0
class FeedbackForm(SerializeDataMixin, ZendeskActionMixin, forms.Form):
    name = fields.CharField(validators=anti_phising_validators)
    email = fields.EmailField()
    comment = fields.CharField(label='Feedback',
                               widget=Textarea,
                               validators=anti_phising_validators)
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = fields.BooleanField(label=TERMS_LABEL)

    @property
    def full_name(self):
        assert self.is_valid()
        return self.cleaned_data['name']
Example #19
0
class BusinessDetailsForm(forms.Form):
    TURNOVER_OPTIONS = (('', 'Please select'), ('0-25k', 'under £25,000'),
                        ('25k-100k', '£25,000 - £100,000'),
                        ('100k-1m', '£100,000 - £1,000,000'),
                        ('1m-5m', '£1,000,000 - £5,000,000'),
                        ('5m-25m', '£5,000,000 - £25,000,000'),
                        ('25m-50m',
                         '£25,000,000 - £50,000,000'), ('50m+',
                                                        '£50,000,000+'))

    company_type = fields.ChoiceField(
        label_suffix='',
        widget=widgets.RadioSelect(),
        choices=COMPANY_TYPE_CHOICES,
    )
    companies_house_number = fields.CharField(
        label='Companies House number',
        required=False,
    )
    company_type_other = fields.ChoiceField(
        label_suffix='',
        choices=(('', 'Please select'), ) + COMPANY_TYPE_OTHER_CHOICES,
        required=False,
    )
    organisation_name = fields.CharField(validators=anti_phising_validators)
    postcode = fields.CharField(validators=anti_phising_validators)
    industry = fields.ChoiceField(choices=INDUSTRY_CHOICES, )
    industry_other = fields.CharField(
        label='Type in your industry',
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False,
    )
    turnover = fields.ChoiceField(
        label='Annual turnover (optional)',
        choices=TURNOVER_OPTIONS,
        required=False,
    )
    employees = fields.ChoiceField(
        label='Number of employees (optional)',
        choices=(('', 'Please select'), ) + choices.EMPLOYEES,
        required=False,
    )
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = fields.BooleanField(label=TERMS_LABEL)
Example #20
0
class CompaniesHouseSearch(forms.Form):
    MESSAGE_COMPANY_NOT_FOUND = (
        "<p>Your company name can't be found.</p>"
        "<p>Check that you entered the registered company name correctly "
        "and select the matching company name from the list.</p>"
        "<p>If your company is not registered with Companies House "
        "<a href='{url}'>change type of business</a></p>")

    company_name = fields.CharField(label='Registered company name')
    company_number = fields.CharField()

    def clean(self):
        cleaned_data = super().clean()
        if 'company_number' not in cleaned_data:
            url = reverse('enrolment-business-type')
            message = self.MESSAGE_COMPANY_NOT_FOUND.format(url=url)
            raise ValidationError({'company_name': mark_safe(message)})
Example #21
0
class DomesticContactForm(FieldsMutationMixin, SerializeMixin,
                          ZendeskActionMixin, forms.Form):

    first_name = fields.CharField()
    last_name = fields.CharField()
    email = fields.EmailField()
    organisation_type = fields.ChoiceField(label_suffix='',
                                           widget=widgets.RadioSelect(),
                                           choices=COMPANY_CHOICES)
    company_name = fields.CharField()
    comment = fields.CharField(widget=Textarea,
                               validators=[no_html, not_contains_url_or_email])
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = fields.BooleanField(label=TERMS_LABEL)
Example #22
0
class SearchForm(forms.Form):

    term = fields.CharField(
        max_length=255,
        required=False,
    )
    sectors = fields.ChoiceField(required=False,
                                 choices=((('', _('All industries')), ) +
                                          choices.INDUSTRIES),
                                 widget=Select(attrs={'dir': 'ltr'}))
Example #23
0
class SoleTraderSearch(forms.Form):

    MESSAGE_INVALID_ADDRESS = 'Address should be at least two lines.'

    company_name = fields.CharField(label='Business name')
    postal_code = fields.CharField(label='Business postcode', )
    address = fields.CharField(
        help_text='Type your business address',
        widget=Textarea(attrs={'rows': 4}),
    )

    def clean_address(self):
        value = self.cleaned_data['address'].strip().replace(', ', '\n')
        postal_code = self.cleaned_data['postal_code']
        if value.count('\n') == 0:
            raise ValidationError(self.MESSAGE_INVALID_ADDRESS)
        if postal_code not in value:
            value = f'{value}\n{postal_code}'
        return value
Example #24
0
class OfficeFinderForm(forms.Form):
    MESSAGE_NOT_FOUND = 'The postcode you entered does not exist'

    postcode = fields.CharField(
        label='Enter your postcode',
        help_text='For example SW1A 2AA',
    )

    def clean_postcode(self):
        return self.cleaned_data['postcode'].replace(' ', '')
Example #25
0
class UserAccountVerification(forms.Form):
    MESSAGE_INVALID_CODE = 'Invalid code'

    email = fields.CharField(label='', widget=HiddenInput, disabled=True)
    code = fields.CharField(label='', min_length=5, max_length=5)

    def clean_code(self):
        try:
            response = helpers.confirm_verification_code(
                email=self.cleaned_data['email'],
                verification_code=self.cleaned_data['code'],
            )
        except HTTPError as error:
            if error.response.status_code == 400:
                self.add_error('code', self.MESSAGE_INVALID_CODE)
            else:
                raise
        else:
            self.cleaned_data['cookies'] = helpers.parse_set_cookie_header(
                response.headers['set-cookie'])
        return None
Example #26
0
class DescriptionForm(forms.Form):
    summary = fields.CharField(
        label='Brief summary to make your company stand out to buyers:',
        help_text='Maximum 250 characters.',
        max_length=250,
        widget=Textarea(attrs={'rows': 5}),
        validators=[
            validators.does_not_contain_email,
            directory_validators.company.no_html,
        ],
    )
    description = fields.CharField(
        label='Describe your business to overseas buyers:',
        help_text='Maximum 2,000 characters.',
        max_length=2000,
        widget=Textarea(attrs={'rows': 5}),
        validators=[
            validators.does_not_contain_email,
            directory_validators.company.no_html,
        ],
    )
Example #27
0
class HelpForm(forms.Form):
    error_css_class = 'input-field-container has-error'

    comment = fields.CharField(
        label='',
        help_text='Your export plans and any challenges you are facing',
        widget=Textarea,
    )
    terms_agreed = fields.BooleanField(label=mark_safe(
        'Tick this box to accept the '
        f'<a href="{urls.TERMS_AND_CONDITIONS}" target="_blank">terms and '
        'conditions</a> of the great.gov.uk service.'))
    captcha = ReCaptchaField()
Example #28
0
class InternationalContactForm(FieldsMutationMixin, SerializeMixin,
                               ZendeskActionMixin, forms.Form):
    first_name = fields.CharField()
    last_name = fields.CharField()
    email = fields.EmailField()
    organisation_type = fields.ChoiceField(
        label_suffix='',
        widget=widgets.RadioSelect(),
        choices=COMPANY_CHOICES,
    )
    company_name = fields.CharField()
    country = fields.ChoiceField(
        choices=[('', 'Please select')] + choices.COUNTRY_CHOICES,
        widget=Select(attrs={'id': 'js-country-select'}),
    )
    city = fields.CharField()
    comment = fields.CharField(widget=Textarea,
                               validators=[no_html, not_contains_url_or_email])
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = fields.BooleanField(label=TERMS_LABEL)
Example #29
0
class SellingOnlineOverseasBusiness(forms.Form):
    company_name = fields.CharField(
        validators=anti_phising_validators,
        required=False,
    )
    soletrader = fields.BooleanField(
        label='I don\'t have a company number',
        required=False,
    )
    company_number = fields.CharField(
        label=('The number you received when registering your company at '
               'Companies House.'),
        required=False,
    )
    company_postcode = fields.CharField(
        validators=anti_phising_validators,
        required=False,  # in js hide if company number is inputted
    )
    website_address = fields.CharField(
        label='Company website',
        help_text='Website address, where we can see your products online.',
        max_length=255,
        required=False,
    )
Example #30
0
class CompanyHomeSearchForm(forms.Form):

    q = fields.CharField(
        label='',
        max_length=255,
        required=False,
        widget=TextInput(
            attrs={
                'autofocus':
                'autofocus',
                'dir':
                'auto',
                'placeholder': ('Enter the name of the skills or service '
                                'you’re looking for')
            }),
    )