Beispiel #1
0
class PersonalDetails(forms.Form):

    given_name = forms.CharField(
        label='First name',
    )
    family_name = forms.CharField(
        label='Last name',
    )
    job_title = forms.CharField()
    phone_number = forms.CharField(
        label='Phone number (optional)',
        required=False
    )
    confirmed_is_company_representative = forms.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.'
        )
    )

    def __init__(self, ask_terms_agreed=False, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if ask_terms_agreed:
            self.fields['terms_agreed'] = forms.BooleanField(label=TERMS_LABEL)
class PersonalDetailsForm(forms.Form):

    first_name = forms.CharField(label='First name')
    last_name = forms.CharField(label='Last name')
    position = forms.CharField(label='Position in organisation')
    email = forms.EmailField(label='Email address')
    phone = forms.CharField(label='Phone')
class BusinessDetailsForm(fields.BindNestedFormMixin, forms.Form):
    company_type = forms.ChoiceField(
        label='Company type',
        label_suffix='',
        widget=forms.RadioSelect(),
        choices=COMPANY_TYPE_CHOICES,
    )
    company_name = forms.CharField(label='Company name')
    company_number = forms.CharField(
        required=False, container_css_classes='form-group js-disabled-only')
    sector = forms.ChoiceField(
        label='Which industry are you in?',
        choices=INDUSTRY_CHOICES,
    )
    employees = forms.ChoiceField(
        label='Number of employees',
        choices=(('', 'Please select'), ) + choices.EMPLOYEES,
        required=False,
    )
    turnover = forms.ChoiceField(
        label='Annual turnover for 2018-19',
        choices=TURNOVER_CHOICES,
        required=False,
    )
    employment_regions = fields.MultipleChoiceAutocomplateField(
        label='Where do you employ the most people?',
        choices=choices.EXPERTISE_REGION_CHOICES,
    )
class ProductSearchForm(forms.Form):
    MESSAGE_MISSING_PRODUCT = 'Please specify an affected product'

    term = forms.CharField(
        label='',
        help_text=
        "To feedback on other types of goods, you'll need to submit another form afterwards.",
        required=False,
        container_css_classes=
        'form-group text-input-with-submit-button-container',
        widget=fields.TextInputWithSubmitButton(attrs={'form': 'search-form'}),
    )
    commodity = forms.CharField(
        label='Commodity codes',
        help_text='Find the commodity codes via the commodity code browser.',
        widget=HiddenInput,
    )

    def clean(self):
        super().clean()
        if not self.cleaned_data.get('commodity'):
            self.add_error('term', self.MESSAGE_MISSING_PRODUCT)

    def clean_commodity(self):
        return json.loads(self.cleaned_data['commodity'])
Beispiel #5
0
class SellingOnlineOverseasContactDetails(forms.Form):
    contact_first_name = forms.CharField(label='First name', )
    contact_last_name = forms.CharField(label='Last name', )
    contact_email = forms.EmailField(
        label='Your email',
        disabled=True,
        required=False,
        container_css_classes=
        'border-active-blue read-only-input-container padding-bottom-0 margin-bottom-30',
    )
    phone = forms.CharField(label='Phone number', )
    email_pref = forms.BooleanField(
        label='I prefer to be contacted by email',
        required=False,
    )

    def _set_name_field_editability(self):
        # If cetain fields lack content, allow each one to be editable.
        for fieldname in [
                'contact_first_name',
                'contact_last_name',
        ]:
            if self.initial.get(fieldname):
                self.fields[fieldname].required = False
                self.fields[fieldname].disabled = True
                # note that we can't set .container_css_classes, but we can do this:
                self.fields[
                    fieldname]._container_css_classes = 'border-active-blue read-only-input-container'
            else:
                self.fields[fieldname].required = True
                self.fields[fieldname].disabled = False

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._set_name_field_editability()
class FeedbackForm(SaveOnlyInDatabaseAPIForm):
    result_found = forms.ChoiceField(
        label='Did you find what you were looking for on the site today?',
        widget=forms.RadioSelect(),
        choices=[('yes', 'Yes'), ('no', 'No')])
    search_target = forms.CharField(
        label=
        'Whether yes or no, please let us know what you were searching for',
        widget=Textarea(attrs={
            'rows': 4,
            'cols': 15
        }))
    from_search_query = forms.CharField(widget=HiddenInput(), required=False)
    from_search_page = IntegerField(widget=HiddenInput(), required=False)
    contactable = forms.ChoiceField(
        label=
        'May we contact you with some brief follow-up questions on your experience?',
        widget=forms.RadioSelect(),
        choices=[('yes', 'Yes'), ('no', 'No')])
    contact_name = forms.CharField(label='What is your name?', required=False)
    contact_email = forms.EmailField(label='What is your email address?',
                                     required=False)
    contact_number = forms.CharField(
        label='What is your phone number? (optional)', required=False)
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())

    @property
    def serialized_data(self):
        if 'captcha' in self.cleaned_data:
            del self.cleaned_data['captcha']
        return self.cleaned_data
class CompaniesHouseBusinessDetailsForm(forms.Form):
    company_name = forms.CharField(label='Registered company name')
    company_number = forms.CharField(
        required=False,
        container_css_classes=
        'border-active-blue read-only-input-container js-disabled-only')
    sector = forms.ChoiceField(
        label='Which industry are you in?',
        choices=INDUSTRY_CHOICES,
        container_css_classes='govuk-!-margin-top-6 govuk-!-margin-bottom-6',
    )
    percentage_uk_market = forms.CharField(
        label=
        'What percentage of the total UK market do your sales represent? (optional)',
        required=False,
    )
    employees = forms.ChoiceField(
        label='Number of employees',
        choices=choices.EMPLOYEES,
        required=False,
        widget=forms.RadioSelect(),
    )
    turnover = forms.ChoiceField(
        label='Annual turnover for 2018-2019',
        choices=TURNOVER_CHOICES,
        required=False,
        widget=forms.RadioSelect(),
    )
class InternationalContactForm(SerializeDataMixin, GovNotifyEmailActionMixin,
                               forms.Form):

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

    given_name = forms.CharField()
    family_name = forms.CharField()
    email = forms.EmailField(label='Email address')
    organisation_type = forms.ChoiceField(label_suffix='',
                                          widget=forms.RadioSelect(),
                                          choices=ORGANISATION_TYPE_CHOICES)
    organisation_name = forms.CharField(label='Your organisation name')
    country_name = forms.ChoiceField(choices=[('', 'Please select')] +
                                     choices.COUNTRY_CHOICES, )
    city = forms.CharField(label='City')
    comment = forms.CharField(
        label='Tell us how we can help',
        help_text=('Do not include personal information or anything of a '
                   'sensitive nature'),
        widget=Textarea,
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)
class SellingOnlineOverseasContactDetails(forms.Form):
    contact_first_name = forms.CharField(
        label='First name',
        disabled=True,
        required=False,
        container_css_classes='border-active-blue read-only-input-container',
    )
    contact_last_name = forms.CharField(
        label='Last name',
        disabled=True,
        required=False,
        container_css_classes='border-active-blue read-only-input-container',
    )
    contact_email = forms.EmailField(
        label='Your email',
        disabled=True,
        required=False,
        container_css_classes=
        'border-active-blue read-only-input-container padding-bottom-0 margin-bottom-30',
    )
    phone = forms.CharField(label='Phone number', )
    email_pref = forms.BooleanField(
        label='I prefer to be contacted by email',
        required=False,
    )
class CompaniesHouseBusinessDetailsForm(forms.Form):
    name = forms.CharField(label='Trading name')
    number = forms.CharField(disabled=True, )
    date_of_creation = forms.DateField(
        label='Incorporated on',
        input_formats=['%d %B %Y'],
        disabled=True,
        required=False,
    )
    address = forms.CharField(
        disabled=True,
        required=False,
    )
    website = forms.URLField(
        label='Business URL (optional)',
        help_text='The website address must start with http:// or https://',
        required=False,
    )
    employees = forms.ChoiceField(
        choices=EMPLOYEES_CHOICES,
        label='How many employees are in your business?',
    )
    sectors = forms.ChoiceField(
        label='What industry is your business in?',
        choices=INDUSTRY_CHOICES,
    )

    def clean_sectors(self):
        return [self.cleaned_data['sectors']]

    def clean(self):
        super().clean()
        self.cleaned_data.pop('clean_number', None)
        self.cleaned_data.pop('date_of_creation', None)
class SellingOnlineOverseasApplicantNonCH(forms.Form):

    company_name = forms.CharField(
        label='Company name',
        disabled=True,
        required=False,
        container_css_classes='border-active-blue read-only-input-container',
    )
    company_address = forms.CharField(
        label='Address',
        disabled=True,
        required=False,
        container_css_classes=
        'border-active-blue read-only-input-container padding-bottom-0 margin-bottom-30',
    )
    website_address = forms.CharField(
        label='Your business web address',
        help_text='Website address, where we can see your products online.',
        max_length=255,
    )
    turnover = forms.ChoiceField(
        label='Your business turnover last year',
        help_text=(
            'You may use 12 months rolling or last year\'s annual turnover.'),
        choices=SOO_TURNOVER_OPTIONS,
        widget=forms.RadioSelect(),
    )
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>")
    MESSAGE_COMPANY_NOT_ACTIVE = 'Company not active.'
    company_name = forms.CharField(label='Registered company name', )
    company_number = forms.CharField(validators=[company_number_validator], )

    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:
            try:
                company_type_validator(cleaned_data['company_number'])
            except ValidationError as error:
                raise ValidationError({'company_name': error})
            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})
        elif 'company_name' in cleaned_data:
            raise ValidationError(
                {'company_name': mark_safe(self.MESSAGE_COMPANY_NOT_FOUND)})
Beispiel #13
0
class PersonalDetailsForm(forms.Form):
    error_css_class = 'input-field-container has-error'

    firstname = forms.CharField(label='Your first name')
    lastname = forms.CharField(label='Your last name')
    position = forms.CharField(label='Position in company')
    email = forms.EmailField(label='Email address')
    phone = forms.CharField(label='Phone')
class ConsumerGroupForm(forms.Form):
    given_name = forms.CharField(label='Given name', )
    family_name = forms.CharField(label='Family name')
    email = forms.EmailField(label='Email address')
    organisation_name = forms.CharField(label='Organisation name', )
    consumer_regions = fields.MultipleChoiceAutocomplateField(
        label='Where are most of your consumers based?',
        choices=choices.EXPERTISE_REGION_CHOICES,
        required=False,
    )
class ConsumerPersonalDetailsForm(forms.Form):
    given_name = forms.CharField(label='Given name', )
    family_name = forms.CharField(label='Family name')
    email = forms.EmailField(label='Email address')
    income_bracket = forms.ChoiceField(
        label='Personal income before tax (optional)',
        required=False,
        choices=INCOME_BRACKET_CHOICES)
    consumer_region = forms.ChoiceField(
        label='Where do you live (optional)?',
        choices=[('', 'Please select')] + choices.EXPERTISE_REGION_CHOICES,
        required=False,
    )
Beispiel #16
0
class DomesticContactForm(FieldsMutationMixin, SerializeMixin,
                          ZendeskActionMixin, ConsentFieldMixin, forms.Form):

    first_name = forms.CharField()
    last_name = forms.CharField()
    email = forms.EmailField()
    organisation_type = forms.ChoiceField(label_suffix='',
                                          widget=forms.RadioSelect(),
                                          choices=COMPANY_CHOICES)
    company_name = forms.CharField()
    comment = forms.CharField(widget=Textarea,
                              validators=[no_html, not_contains_url_or_email])
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
class CaseStudyBasicInfoForm(forms.Form):
    title = forms.CharField(
        label='Title of your case study or project',
        max_length=60,
        validators=[directory_validators.company.no_html],
    )
    short_summary = forms.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 = forms.CharField(
        label='Describe your case study or project',
        help_text=('Describe your project or case study in greater detail. '
                   'You have up to 1,000 characters to use.'),
        max_length=1000,
        validators=[
            validators.does_not_contain_email,
            directory_validators.company.no_html,
        ],
        widget=Textarea,
    )
    sector = forms.ChoiceField(
        label='Industry most relevant to your case study or project',
        choices=INDUSTRY_CHOICES)
    website = forms.URLField(
        label='The web address for your case study or project (optional)',
        help_text='Enter a full URL including http:// or https://',
        max_length=255,
        required=False,
    )
    keywords = forms.CharField(
        label=('Enter up to 10 keywords that describe your case '
               'study or project. Keywords should be separated by '
               'commas.'),
        help_text=('These keywords will 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,
        ])
class FeedbackForm(SerializeDataMixin, ZendeskActionMixin, forms.Form):
    name = forms.CharField()
    email = forms.EmailField()
    comment = forms.CharField(
        label='Feedback',
        widget=Textarea,
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)

    @property
    def full_name(self):
        assert self.is_valid()
        return self.cleaned_data['name']
class UserAccountVerification(forms.Form):

    MESSAGE_INVALID_CODE = 'Invalid code'
    # email field can be overridden in __init__ to allow user to enter email
    email = forms.CharField(label='', widget=HiddenInput, disabled=True)
    code = forms.CharField(label='Confirmation Code',
                           min_length=5,
                           max_length=5,
                           error_messages={'required': MESSAGE_INVALID_CODE})

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if self.initial.get('email') is None:
            self.fields['email'] = forms.EmailField(label='Your email address')
class CompaniesHouseAddressSearch(CleanAddressMixin, forms.Form):

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

    company_name = forms.CharField(label='Registered company name', disabled=True)
    postal_code = forms.CharField(
        label='Business postcode',
        widget=PostcodeInput(attrs={'id': 'id_postal_code'}),  # template js relies on this ID
        required=False,
    )
    address = forms.CharField(
        help_text='Type your business address',
        widget=Textarea(attrs={'rows': 6, 'id': 'id_address'}),  # template js relies on this ID
        required=False,
    )
class BusinessDetailsForm(ConsentFieldMixin, 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 = forms.ChoiceField(
        label_suffix='',
        widget=forms.RadioSelect(),
        choices=COMPANY_TYPE_CHOICES,
    )
    companies_house_number = forms.CharField(
        label='Companies House number',
        required=False,
    )
    company_type_other = forms.ChoiceField(
        label_suffix='',
        choices=(('', 'Please select'), ) + COMPANY_TYPE_OTHER_CHOICES,
        required=False,
    )
    organisation_name = forms.CharField()
    postcode = forms.CharField()
    industry = forms.ChoiceField(choices=INDUSTRY_CHOICES)
    industry_other = forms.CharField(
        label='Type in your industry',
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False,
    )
    turnover = forms.ChoiceField(
        label='Annual turnover (optional)',
        choices=TURNOVER_OPTIONS,
        required=False,
    )
    employees = forms.ChoiceField(
        label='Number of employees (optional)',
        choices=(('', 'Please select'), ) + choices.EMPLOYEES,
        required=False,
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())

    def clean_industry(self):
        industry = self.cleaned_data['industry']
        self.cleaned_data['industry_label'] = INDUSTRY_MAP[industry]
        return industry
class NonTariffRelatedCommentForm(forms.Form):
    other_non_tariff_related_changes = forms.CharField(
        label=
        "Do not include any sensitive or personal information. If you're unsure, leave this blank",
        widget=Textarea(attrs={'rows': 6}),
        required=False,
    )
class ExpertiseProductsServicesForm(forms.Form):

    CHOICES_MAP = {
        constants.FINANCIAL: expertise.FINANCIAL,
        constants.MANAGEMENT_CONSULTING: expertise.MANAGEMENT_CONSULTING,
        constants.HUMAN_RESOURCES: expertise.HUMAN_RESOURCES,
        constants.LEGAL: expertise.LEGAL,
        constants.PUBLICITY: expertise.PUBLICITY,
        constants.BUSINESS_SUPPORT: expertise.BUSINESS_SUPPORT,
    }

    expertise_products_services = forms.CharField(
        label='Choose your products or services',
        validators=[
            directory_validators.company.keywords_word_limit,
            directory_validators.company.no_html,
        ],
        widget=Textarea(attrs={'placeholder': 'Please select'}),
        max_length=1000,
        required=False,
    )

    def __init__(self, category, *args, **kwargs):
        super().__init__(*args, **kwargs)
        widget = self.fields['expertise_products_services'].widget
        widget.attrs['data-choices'] = '|'.join(self.CHOICES_MAP[category])

    def clean_expertise_products_services(self):
        return self.cleaned_data['expertise_products_services'].split('|')
class UserAccount(forms.Form):
    PASSWORD_HELP_TEXT = (
        '<p>Your password must:</p>'
        '<ul class="list list-bullet margin-l-30-m">'
        '<li>be at least 10 characters</li>'
        '<li>have at least 1 letter</li>'
        '<li>have at least 1 number</li>'
        '<li>not contain the words which are easy to guess such as "password"'
        '</li>'
        '</ul>')
    MESSAGE_NOT_MATCH = "Passwords don't match"
    MESSAGE_PASSWORD_INVALID = 'Invalid Password'

    email = forms.EmailField(label='Your email address')
    password = forms.CharField(label='Set a password',
                               help_text=mark_safe(PASSWORD_HELP_TEXT),
                               widget=PasswordInput)
    password_confirmed = forms.CharField(
        label='Confirm password',
        widget=PasswordInput,
    )
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
    )
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)

    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()
        if not self.errors:
            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
class NonCompaniesHouseSearch(forms.Form):

    MESSAGE_INVALID_ADDRESS = 'Address should be at least two lines.'
    COMPANY_TYPES = [
        ('', 'Please select'),
    ] + [(value, label) for value, label in choices.COMPANY_TYPES
         if value != 'COMPANIES_HOUSE']

    company_type = forms.ChoiceField(label='Business category',
                                     choices=COMPANY_TYPES)
    company_name = forms.CharField(label='Business name')
    postal_code = forms.CharField(
        label='Business postcode',
        widget=PostcodeInput,
        required=False,
    )
    address = forms.CharField(
        help_text='Type your business address',
        widget=Textarea(attrs={'rows': 4}),
        required=False,
    )
    sectors = forms.ChoiceField(
        label='What industry is your business in?',
        choices=INDUSTRY_CHOICES,
    )
    website = forms.URLField(
        label='What\'s your business web address (optional)',
        help_text='The website address must start with http:// or https://',
        required=False,
    )

    def clean_sectors(self):
        return [self.cleaned_data['sectors']]

    def clean_address(self):
        value = self.cleaned_data['address'].strip().replace(', ', '\n')
        parts = value.split('\n')

        postal_code = self.cleaned_data.get('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}'
        self.cleaned_data['address_line_1'] = parts[0].strip()
        self.cleaned_data['address_line_2'] = parts[1].strip()
        return value
Beispiel #26
0
class RadioNestedForm(forms.BindNestedFormMixin, forms.Form):
    OTHER = 'OTHER'
    parent_field = forms.RadioNested(
        choices=[('KG', 'Kilograms'), ('HANDS', 'Hands'), (OTHER, 'other')],
        nested_form_class=PaddedTestForm,
        nested_form_choice=OTHER,
    )
    other_field = forms.CharField()
class EquivalendUKGoodsDetailsForm(forms.Form):
    equivalent_uk_goods_details = forms.CharField(
        label="Tell us more ",
        help_text=(
            'Use this opportunity to give us any other supporting information.'
            'Do not include any sensetive information.'),
        widget=Textarea(attrs={'rows': 6}),
    )
class OfficeFinderForm(forms.Form):
    MESSAGE_NOT_FOUND = 'The postcode you entered does not exist'

    postcode = forms.CharField(label='Enter your postcode',
                               help_text='For example SW1A 2AA',
                               validators=[is_valid_postcode])

    def clean_postcode(self):
        return self.cleaned_data['postcode'].replace(' ', '')
class IndividualPersonalDetails(forms.Form):
    given_name = forms.CharField(
        label='First name',
    )
    family_name = forms.CharField(
        label='Last name',
    )
    job_title = forms.CharField()
    phone_number = forms.CharField(
        label='Phone number (optional)',
        required=False,
        widget=TextInput(attrs={'type': 'tel'})
    )

    def __init__(self, ask_terms_agreed=False, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if ask_terms_agreed:
            self.fields['terms_agreed'] = forms.BooleanField(label=TERMS_LABEL)
class ImportedProductsUsageDetailsForm(forms.Form):
    imported_good_sector = forms.ChoiceField(
        label='Industry of product or service',
        choices=[('', 'Please select')] + choices.SECTORS,
    )
    imported_good_sector_details = forms.CharField(
        label="Description of products or service",
        widget=Textarea(attrs={'rows': 6}),
    )