示例#1
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)
示例#2
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)
示例#3
0
class RadioForm(PrefixIdMixin, forms.Form):
    radio = fields.ChoiceField(label='Q1: Radio select',
                               label_suffix='',
                               help_text='Some help text.',
                               widget=widgets.RadioSelect(
                                   use_nice_ids=True,
                                   attrs={'id': 'radio-one'}),
                               choices=(
                                   (True, 'Yes'),
                                   (False, 'No'),
                               ))
    radio_group = fields.ChoiceField(
        label='Q2: Radio select with option groups',
        label_suffix='',
        help_text='Some help text.',
        widget=widgets.RadioSelect(use_nice_ids=True,
                                   attrs={'id': 'radio-two'}),
        choices=(
            ('Colours', (
                ('red', 'Red'),
                ('green', 'Green'),
                ('blue', 'Blue'),
            )),
            ('Numbers', (
                ('4', 'Four'),
                ('5', 'Five'),
                ('6', 'Six'),
            )),
        ))
示例#4
0
class SellingOnlineOverseasBusinessDetails(forms.Form):
    TURNOVER_OPTIONS = (
        ('Under 100k', 'Under £100,000'),
        ('100k-500k', '£100,000 to £500,000'),
        ('500k-2m', '£500,001 and £2million'),
        ('2m+', 'More than £2million'),
    )

    turnover = fields.ChoiceField(
        label='Turnover last year',
        help_text=(
            'You may use 12 months rolling or last year\'s annual turnover.'),
        choices=TURNOVER_OPTIONS,
        widget=widgets.RadioSelect(),
    )
    sku_count = IntegerField(
        label='How many stock keeping units (SKUs) do you have?',
        help_text=(
            'A stock keeping unit is an individual item, such as a product '
            'or a service that is offered for sale.'))
    trademarked = TypedChoiceField(
        label='Are your products trademarked in your target countries?',
        help_text=(
            'Some marketplaces will only sell products that are trademarked.'),
        label_suffix='',
        coerce=lambda x: x == 'True',
        choices=[(True, 'Yes'), (False, 'No')],
        widget=widgets.RadioSelect(),
        required=False,
    )
示例#5
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]])
示例#6
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)
示例#7
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'}))
示例#8
0
class LocationRoutingForm(forms.Form):
    CHOICES = (
        (constants.DOMESTIC, 'The UK'),
        (constants.INTERNATIONAL, 'Outside the UK'),
    )
    choice = fields.ChoiceField(
        label='',
        widget=widgets.RadioSelect(),
        choices=CHOICES,
    )
示例#9
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,
        ])
示例#10
0
class InternationalRoutingForm(EuExitOptionFeatureFlagMixin, forms.Form):
    CHOICES = (
        (constants.INVESTING, 'Investing in the UK'),
        (constants.BUYING, 'Find a UK business partner'),
        (constants.EUEXIT, 'EU exit enquiries'),  # possibly removed by mixin
        (constants.OTHER, 'Other'),
    )
    choice = fields.ChoiceField(
        label='',
        widget=widgets.RadioSelect(),
        choices=CHOICES,  # possibly updated by mixin
    )
示例#11
0
class ExportOpportunitiesRoutingForm(forms.Form):
    CHOICES = (
        (constants.NO_RESPONSE,
         'I haven\'t had a response from the opportunity I applied for'),
        (constants.ALERTS, 'My daily alerts are not relevant to me'),
        (constants.OTHER, 'Other'),
    )
    choice = fields.ChoiceField(
        label='',
        widget=widgets.RadioSelect(),
        choices=CHOICES,
    )
示例#12
0
class GreatServicesRoutingForm(forms.Form):

    CHOICES = (
        (constants.EXPORT_OPPORTUNITIES, 'Export opportunities service'),
        (constants.GREAT_ACCOUNT, 'Your account on great.gov.uk'),
        (constants.OTHER, 'Other'),
    )
    choice = fields.ChoiceField(
        label='',
        widget=widgets.RadioSelect(),
        choices=CHOICES,
    )
示例#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()
示例#14
0
class LanguageForm(forms.Form):
    language = fields.ChoiceField(
        widget=Select(attrs={'id': 'great-header-language-select'}),
        choices=[]  # set by __init__
    )

    def __init__(self, language_choices=settings.LANGUAGES, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['language'].choices = language_choices

    def is_language_available(self, language_code):
        language_codes = [code for code, _ in self.fields['language'].choices]
        return language_code in language_codes
class AboutForm(forms.Form):
    error_css_class = 'input-field-container has-error'
    CATEGORY_CHOICES = ('I’m an exporter or I want to export',
                        'I work for a trade association', 'Other')

    firstname = fields.CharField(
        label='First name',
        error_messages={'required': 'Enter your first name'})

    lastname = fields.CharField(
        label='Last name', error_messages={'required': 'Enter your last name'})

    jobtitle = fields.CharField(
        label='Job title', error_messages={'required': 'Enter your job title'})

    categories = fields.ChoiceField(
        label='Business type',
        widget=widgets.RadioSelect(
            attrs={'id': 'checkbox-single'},
            use_nice_ids=True,
        ),
        choices=((choice, choice) for choice in CATEGORY_CHOICES),
        error_messages={'required': 'Tell us your business type'})
    organisation_description = fields.CharField(
        label='Tell us about your organisation',
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False)

    company_name = fields.CharField(
        label='Business or organisation name',
        error_messages={
            'required': 'Enter your business or organisation name'
        })

    email = fields.EmailField(
        label='Email address',
        error_messages={'required': 'Enter your email address'})

    phone = fields.CharField(
        label='Telephone number',
        error_messages={'required': 'Enter your telephone number'})

    def clean(self):
        data = self.cleaned_data
        description = data.get('organisation_description')
        categories = data.get('categories')
        if categories == 'Other' and not description:
            self.add_error('organisation_description',
                           'Enter your organisation')
        else:
            return data
示例#16
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)
示例#17
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})
示例#18
0
class TextBoxForm(PrefixIdMixin, forms.Form):
    text_field1 = fields.CharField(label='Q1: Simple text field',
                                   help_text='Some help text')
    url_field = fields.URLField(label='Q2: URL field',
                                help_text='Some help text')
    email_field = fields.EmailField(
        label='Q3: Email field',
        help_text='Some email field help text',
    )
    choice_field = fields.ChoiceField(label='Q4: select field',
                                      help_text='Some help text',
                                      choices=[
                                          ('red', 'Red'),
                                          ('green', 'Green'),
                                          ('blue', 'Blue'),
                                      ])
示例#19
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)
示例#20
0
class DomesticRoutingForm(EuExitOptionFeatureFlagMixin, forms.Form):

    CHOICES = (
        (constants.TRADE_OFFICE, 'Find your local trade office'),
        (constants.EXPORT_ADVICE, 'Advice to export from the UK'),
        (constants.GREAT_SERVICES,
         'great.gov.uk account and services support'),
        (constants.FINANCE, 'UK Export Finance (UKEF)'),
        (constants.EUEXIT, 'EU exit enquiries'),  # possibly removed by mixin
        (constants.EVENTS, 'Events'),
        (constants.DSO, 'Defence and Security Organisation (DSO)'),
        (constants.OTHER, 'Other'),
    )
    choice = fields.ChoiceField(
        label='',
        widget=widgets.RadioSelect(),
        choices=CHOICES,  # possibly update by mixin
    )
class CurrentStatusForm(forms.Form):
    error_css_class = 'input-field-container has-error'
    STATUS_CHOICES = (
        (1, 'My perishable goods or livestock are blocked in transit'),
        (2, 'I’m at immediate risk of missing a commercial opportunity'),
        (3, 'I’m at immediate risk of not fulfilling a contract'),
        (4,
         'I need resolution quickly, but I’m not at immediate risk of loss'),
    )

    status = fields.ChoiceField(
        label='Select which option best applies to you',
        widget=widgets.RadioSelect(use_nice_ids=True,
                                   attrs={'id': 'radio-one'}),
        choices=STATUS_CHOICES,
        error_messages={
            'required': 'Choose the option that best describes your situation'
        })
示例#22
0
class CompanyDetailsForm(forms.Form):

    EXPORT_CHOICES = (
        'I have customers outside the UK',
        'I supply UK companies that sell overseas',
        'I don\'t currently export or supply businesses that export',
    )
    INDUSTRY_CHOICES = [('', '')] + [(value.replace('_', ' ').title(), label)
                                     for (value, label) in choices.INDUSTRIES
                                     ] + [('Other', 'Other')]

    error_css_class = 'input-field-container has-error'

    trading_name = fields.CharField(label='Trading name')
    company_number = fields.CharField(label='Companies House number',
                                      required=False)
    address_line_one = fields.CharField(label='Building and street')
    address_line_two = fields.CharField(label='', required=False)
    address_town_city = fields.CharField(label='Town or city')
    address_county = fields.CharField(label='County')
    address_post_code = fields.CharField(label='Postcode')
    industry = fields.ChoiceField(initial='thing', choices=INDUSTRY_CHOICES)
    industry_other = fields.CharField(
        label='Type in your industry',
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False,
    )

    export_status = fields.MultipleChoiceField(
        label='Do you currently export?',
        help_text='Select all that apply',
        widget=widgets.CheckboxSelectInlineLabelMultiple(
            attrs={'id': 'checkbox-multiple'},
            use_nice_ids=True,
        ),
        choices=((choice, choice) for choice in EXPORT_CHOICES),
    )

    def clean(self):
        cleaned_data = super().clean()
        return {
            **cleaned_data, 'not_companies_house':
            not cleaned_data.get('company_number')
        }
示例#23
0
class BusinessType(forms.Form):
    CHOICES = (
        (constants.COMPANIES_HOUSE_COMPANY,
         ('My business is registered with Companies House.  '
          'For example, a limited company (Ltd), a public limited  '
          'company (PLC) or a Royal Charter company')),
        (constants.SOLE_TRADER,
         ('I\'m a sole trader or I represent another type of UK '
          'business not registered with Companies House')),
        (constants.NOT_COMPANY,
         ('I\'m a UK taxpayer but do not represent a business')),
        (constants.OVERSEAS_COMPANY,
         ('My business or organisation is not registered in the UK')),
    )
    choice = fields.ChoiceField(
        label='',
        widget=widgets.RadioSelect(),
        choices=CHOICES,
    )
示例#24
0
class SellingOnlineOverseasExperience(forms.Form):
    EXPERIENCE_OPTIONS = (('Not yet', 'Not yet'), ('Yes, sometimes',
                                                   'Yes, sometimes'),
                          ('Yes, regularly', 'Yes, regularly'))

    experience = fields.ChoiceField(
        label='Have you sold products online to customers outside the UK?',
        choices=EXPERIENCE_OPTIONS,
        widget=widgets.RadioSelect(),
    )

    description = fields.CharField(
        label='Pitch your business to this marketplace',
        help_text=(
            'Your pitch is important and the information you provide may be '
            'used to introduce you to the marketplace. You could describe '
            'your business, including your products, your customers and '
            'how you market your products in a few paragraphs.'),
        widget=Textarea,
        validators=anti_phising_validators)
示例#25
0
class GreatAccountRoutingForm(NewUserRegOptionFeatureFlagMixin, forms.Form):
    CHOICES = (
        (constants.NO_VERIFICATION_EMAIL,
         'I have not received my email confirmation'),
        (constants.PASSWORD_RESET, 'I need to reset my password'),
        (
            constants.COMPANY_NOT_FOUND,  # possibly update by mixin
            'I cannot find my company'),
        (constants.COMPANIES_HOUSE_LOGIN,
         'My Companies House login is not working'),
        (constants.VERIFICATION_CODE,
         'I do not know where to enter my verification code'),
        (constants.NO_VERIFICATION_LETTER,
         'I have not received my letter containing the verification code'),
        (constants.OTHER, 'Other'),
    )
    choice = fields.ChoiceField(
        label='',
        widget=widgets.RadioSelect(),
        choices=CHOICES,
    )
示例#26
0
    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()
示例#27
0
class DemoFormErrors(PrefixIdMixin, forms.Form):

    text_field1 = fields.CharField(label='Simple text field',
                                   help_text='Some help text',
                                   required=True)
    checkbox1 = fields.BooleanField(
        label='Label text',
        required=True,
        help_text=('Some help text.'),
        widget=widgets.CheckboxWithInlineLabel(attrs={'id': 'checkbox-one'}))
    multiple_choice = fields.MultipleChoiceField(
        label='Multiple choice checkboxes',
        required=True,
        help_text='Some help text.',
        widget=widgets.CheckboxSelectInlineLabelMultiple(
            attrs={'id': 'checkbox-multiple'},
            use_nice_ids=True,
        ),
        choices=(
            ('red', 'Red'),
            ('green', 'Green'),
            ('blue', 'Blue'),
        ),
    )

    radio = fields.ChoiceField(label='Radio select',
                               required=True,
                               label_suffix='',
                               help_text='Some help text.',
                               widget=widgets.RadioSelect(
                                   use_nice_ids=True,
                                   attrs={'id': 'radio-one'}),
                               choices=(
                                   (True, 'Yes'),
                                   (False, 'No'),
                               ))
示例#28
0
class ProblemDetailsForm(forms.Form):

    # Country choices is a list of tuples that follow the structure
    # (country_code, country_name). We don't want this
    # structure because the choice needs to always be human
    # readable for the summary and zendesk. This creates a new
    # tuple that makes tuples with the same value.
    def change_country_tuples(country_list):
        return [(country_name, country_name)
                for country_code, country_name in country_list]

    error_css_class = 'input-field-container has-error'

    product_service = fields.CharField(
        label='What goods or services do you want to export?',
        help_text='Or tell us about an investment you want to make',
        error_messages={
            'required':
            'Tell us what you’re \
            trying to export or invest in'
        })
    country = fields.ChoiceField(
        label='Which country do you want to export to?',
        choices=[('', 'Select a country')] +
        change_country_tuples(choices.COUNTRY_CHOICES),
        widget=Select(attrs={'id': 'js-country-select'}),
        error_messages={
            'required': 'Select the country you’re trying to export to'
        })
    problem_summary = fields.CharField(
        label=mark_safe('<p>Tell us about your problem, including: </p> \
            <ul class="list list-bullet"> \
              <li>what’s affecting your export or investment</li> \
              <li>when you became aware of the problem</li> \
              <li>how you became aware of the problem</li> \
              <li>if it’s a one off</li> \
              <li> \
                any information you’ve been given or \
                correspondence you’ve had \
              </li> \
              <li> \
                the HS (Harmonized System) code for your goods, \
                if you know it \
              </li> \
            </ul>'),
        widget=Textarea,
        error_messages={'required': 'Tell us about the barrier you’re facing'})
    impact = fields.CharField(
        label='How has the problem affected your business?',
        widget=Textarea,
        error_messages={
            'required':
            'Tell us how your business is being affected by the \
            barrier'
        })
    resolve_summary = fields.CharField(
        label=mark_safe('<p>Tell us about any steps you’ve taken \
            to resolve the problem, including: </p> \
            <ul class="list list-bullet"> \
              <li>people you’ve contacted</li> \
              <li>when you contacted them</li> \
              <li>what happened</li> \
            </ul>'),
        widget=Textarea,
        error_messages={
            'required':
            'Tell us what you’ve done to resolve your \
            problem, even if this is your first step'
        })
    eu_exit_related = fields.ChoiceField(
        label='Is your problem caused by or related to EU Exit?',
        widget=widgets.RadioSelect(use_nice_ids=True,
                                   attrs={'id': 'radio-one'}),
        choices=(('Yes', 'Yes'), ('No', 'No')),
        error_messages={
            'required': 'Tell us if your problem is related to EU Exit'
        })
示例#29
0
class CompaniesHouseBusinessDetails(forms.Form):
    company_name = fields.CharField(label='Registered company name')
    company_number = fields.CharField(
        disabled=True,
        required=False,
    )
    sic = fields.CharField(
        label='Nature of business',
        disabled=True,
        required=False,
    )
    date_of_creation = DateField(
        label='Incorporated on',
        input_formats=['%m %B %Y'],
        disabled=True,
        required=False,
    )
    postal_code = fields.CharField(
        label='Business postcode',
        required=False,
    )
    address = fields.CharField(
        disabled=True,
        required=False,
    )
    industry = fields.ChoiceField(
        label='What industry is your company 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,
                 company_data=None,
                 is_enrolled=False,
                 *args,
                 **kwargs):
        super().__init__(initial=initial, *args, **kwargs)
        if company_data:
            self.set_form_initial(company_data)
        if is_enrolled:
            self.delete_already_enrolled_fields()
        # 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')
            if not self.data.get('postal_code'):
                self.initial_to_data('postal_code')

    def delete_already_enrolled_fields(self):
        del self.fields['industry']
        del self.fields['website_address']

    def set_form_initial(self, company_profile):
        company = helpers.CompanyProfileFormatter(company_profile)
        self.initial['company_name'] = company.name
        self.initial['company_number'] = company.number
        self.initial['sic'] = company.sic_code
        self.initial['date_of_creation'] = company.date_created
        self.initial['address'] = company.address
        self.initial['postal_code'] = company.postcode

    def initial_to_data(self, field_name):
        self.data.setlist(self.add_prefix(field_name),
                          [self.initial[field_name]])

    def clean_date_of_creation(self):
        return self.cleaned_data['date_of_creation'].isoformat()

    def clean_address(self):
        address_parts = self.cleaned_data['address'].split(',')
        self.cleaned_data['address_line_1'] = address_parts[0].strip()
        self.cleaned_data['address_line_2'] = address_parts[1].strip()
        return self.cleaned_data['address']
class CountryForm(forms.Form):
    country = fields.ChoiceField(
        label='Country',
        widget=Select(attrs={'id': 'js-country-select'}),
        choices=COUNTRIES)