Example #1
0
class SocialLinksForm(forms.Form):
    HELP_URLS = 'Use a full web address (URL) including http:// or https://'

    facebook_url = fields.URLField(
        label='URL for your Facebook company page (optional):',
        help_text=HELP_URLS,
        max_length=255,
        required=False,
        validators=[
            directory_validators.company.case_study_social_link_facebook
        ],
    )
    twitter_url = fields.URLField(
        label='URL for your Twitter company profile (optional):',
        help_text=HELP_URLS,
        max_length=255,
        required=False,
        validators=[
            directory_validators.company.case_study_social_link_twitter
        ],
    )
    linkedin_url = fields.URLField(
        label='URL for your LinkedIn company profile (optional):',
        help_text=HELP_URLS,
        max_length=255,
        required=False,
        validators=[
            directory_validators.company.case_study_social_link_linkedin
        ],
    )
Example #2
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 #3
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 #4
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'),
                                      ])
Example #5
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']