Ejemplo n.º 1
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...')
Ejemplo n.º 2
0
class CheckboxForm(PrefixIdMixin, forms.Form):
    checkbox1 = fields.BooleanField(
        label='Q1: Label text',
        help_text=(
            'This is some help text. This help text is very long so '
            'you can see how it wraps next to the form elements. Very very '
            'long boring text that doesn\'t say anything. Why are you '
            'reading this?'),
        widget=widgets.CheckboxWithInlineLabel(attrs={'id': 'checkbox-one'}))
    checkbox2 = fields.BooleanField(
        label='Q2: Label text with no help text',
        widget=widgets.CheckboxWithInlineLabel(attrs={'id': 'checkbox-two'}))
Ejemplo n.º 3
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)
Ejemplo n.º 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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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
Ejemplo n.º 7
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'])
Ejemplo n.º 8
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
Ejemplo n.º 9
0
class PublishForm(forms.Form):

    LABEL_UNPUBLISH = 'Untick to remove your profile from this service'
    LABEL_ISD = 'Publish profile on great.gov.uk ISD'
    LABEL_FAS = 'Publish profile on great.gov.uk/trade/'

    def __init__(self, company, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if company.get('is_published_investment_support_directory'):
            field = self.fields['is_published_investment_support_directory']
            field.widget.label = self.LABEL_UNPUBLISH
        if company.get('is_published_find_a_supplier'):
            field = self.fields['is_published_find_a_supplier']
            field.widget.label = self.LABEL_UNPUBLISH

    is_published_investment_support_directory = fields.BooleanField(
        label=LABEL_ISD, required=False)
    is_published_find_a_supplier = fields.BooleanField(label=LABEL_FAS,
                                                       required=False)
Ejemplo n.º 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.'))
Ejemplo n.º 11
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()
Ejemplo n.º 12
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()
Ejemplo n.º 13
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})
Ejemplo n.º 14
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
Ejemplo n.º 15
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']
Ejemplo n.º 16
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)
Ejemplo n.º 17
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)
Ejemplo n.º 18
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)
Ejemplo n.º 19
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,
    )
Ejemplo n.º 20
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'),
                               ))
Ejemplo n.º 21
0
class CommunityJoinForm(GovNotifyActionMixin, Form):
    name = fields.CharField(
        label=_('Full name'),
        min_length=2,
        max_length=50,
        error_messages={'required': _('Enter your full name')})
    email = fields.EmailField(
        label=_('Email address'),
        error_messages={
            'required':
            _('Enter an email address in the correct format,'
              ' like [email protected]'),
            'invalid':
            _('Enter an email address in the correct format,'
              ' like [email protected]'),
        })
    phone_number_regex = re.compile(r'^(\+\d{1,3}[- ]?)?\d{8,16}$')
    phone_number = fields.CharField(
        label=_('UK telephone number'),
        min_length=8,
        help_text=_('This can be a landline or mobile number'),
        error_messages={
            'max_length':
            _('Figures only, maximum 16 characters,'
              ' minimum 8 characters excluding spaces'),
            'min_length':
            _('Figures only, maximum 16 characters,'
              ' minimum 8 characters excluding spaces'),
            'required':
            _('Enter an UK phone number'),
            'invalid':
            _('Please enter an UK phone number')
        })
    company_name = fields.CharField(label=_('Business name'),
                                    max_length=50,
                                    error_messages={
                                        'required':
                                        _('Enter your business name'),
                                    })
    company_location = fields.CharField(label=_('Business  location'),
                                        max_length=50,
                                        error_messages={
                                            'required':
                                            _('Enter your business location'),
                                        })
    sector = fields.ChoiceField(label=_('Sector'),
                                choices=choices.COMPANY_SECTOR_CHOISES,
                                error_messages={
                                    'required': _('Choose a sector'),
                                })
    sector_other = fields.CharField(
        label=_('Please specify'),
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False,
    )
    company_website = fields.CharField(
        label=_('Website'),
        max_length=255,
        help_text=_('Enter the home page address'),
        error_messages={
            'required':
            _('Enter a website address in the correct format, '
              'like https://www.example.com or www.company.com'),
            'invalid':
            _('Enter a website address in the correct format, '
              'like https://www.example.com or www.company.com')
        },
        required=False)
    employees_number = fields.ChoiceField(
        label=_('Number of employees'),
        choices=choices.EMPLOYEES_NUMBER_CHOISES,
        error_messages={
            'required': _('Choose a number'),
        })
    currently_export = fields.ChoiceField(
        label=_('Do you currently export?'),
        choices=(('yes', 'Yes'), ('no', 'No')),
        widget=widgets.RadioSelect,
        error_messages={'required': _('Please answer this question')})
    advertising_feedback = fields.ChoiceField(
        label=_('Where did you hear about becoming an Export Advocate?'),
        choices=choices.HEARD_ABOUT_CHOISES,
        error_messages={
            'required':
            _('Please tell us where you heard about'
              ' becoming an Export Advocate'),
        })
    advertising_feedback_other = fields.CharField(
        label=_('Please specify'),
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False,
    )

    terms_agreed = fields.BooleanField(
        label=TERMS_LABEL,
        error_messages={
            'required':
            _('You must agree to the terms and conditions'
              ' before registering'),
        })
    captcha = ReCaptchaField(
        label='',
        label_suffix='',
        error_messages={
            'required': _('Check the box to confirm that you’re human')
        })

    def clean_phone_number(self):
        phone_number = self.cleaned_data.get('phone_number',
                                             '').replace(' ', '')
        if not self.phone_number_regex.match(phone_number):
            raise forms.ValidationError(_('Please enter an UK phone number'))
        return phone_number

    @property
    def serialized_data(self):
        data = super().serialized_data
        sector_mapping = dict(choices.COMPANY_SECTOR_CHOISES)
        employees_number_mapping = dict(choices.EMPLOYEES_NUMBER_CHOISES)
        advertising_feedback_mapping = dict(choices.HEARD_ABOUT_CHOISES)
        if data.get('sector_other'):
            sector_label = data.get('sector_other')
        else:
            sector_label = sector_mapping.get(data['sector'])
        data['sector_label'] = sector_label
        if data.get('advertising_feedback_other'):
            advertising_feedback_label = data.get('advertising_feedback_other')
        else:
            advertising_feedback_label = advertising_feedback_mapping.get(
                data['advertising_feedback'])
        data['advertising_feedback_label'] = advertising_feedback_label
        data['employees_number_label'] = employees_number_mapping.get(
            data['employees_number'])
        return data
Ejemplo n.º 22
0
class HighPotentialOpportunityForm(forms.Form):
    action_class = GovNotifyAction
    COMPANY_SIZE_CHOICES = [
        ('1 - 10', '1 - 10'),
        ('11 - 50', '11 - 50'),
        ('51 - 250', '51 - 250'),
        ('250+', '250+'),
    ]

    def __init__(self, field_attributes, opportunity_choices, *args, **kwargs):
        for field_name, field in self.base_fields.items():
            attributes = field_attributes.get(field_name)
            if attributes:
                field.__dict__.update(attributes)
        self.base_fields['opportunities'].choices = opportunity_choices
        return super().__init__(*args, **kwargs)

    full_name = fields.CharField()
    role_in_company = fields.CharField()
    email_address = fields.EmailField()
    phone_number = fields.CharField()
    company_name = fields.CharField()
    website_url = fields.CharField(required=False)
    country = fields.ChoiceField(
        choices=[('', 'Please select')] + choices.COUNTRY_CHOICES,
        widget=Select(attrs={'id': 'js-country-select'}),
    )
    company_size = fields.ChoiceField(choices=COMPANY_SIZE_CHOICES)
    opportunities = fields.MultipleChoiceField(
        widget=widgets.CheckboxSelectInlineLabelMultiple(
            attrs={'id': 'checkbox-multiple'},
            use_nice_ids=True,
        ),
        choices=[]  # set in __init__
    )
    comment = fields.CharField(widget=Textarea, required=False)
    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(
        label='',
        label_suffix='',
    )

    @property
    def serialized_data(self):
        formatted_opportunities = [
            '• {opportunity[1]}: {opportunity[0]}'.format(opportunity=item)
            for item in self.base_fields['opportunities'].choices
            if item[0] in self.cleaned_data['opportunities']
        ]

        return {
            **self.cleaned_data,
            'opportunity_urls':
            '\n'.join(formatted_opportunities),
        }

    def send_agent_email(self, form_url):
        sender = Sender(email_address=self.cleaned_data['email_address'],
                        country_code=self.cleaned_data['country'])
        action = self.action_class(
            template_id=settings.HPO_GOV_NOTIFY_AGENT_TEMPLATE_ID,
            email_address=settings.HPO_GOV_NOTIFY_AGENT_EMAIL_ADDRESS,
            form_url=form_url,
            sender=sender,
        )
        response = action.save(self.serialized_data)
        response.raise_for_status()

    def send_user_email(self, form_url):
        # no need to set `sender` as this is just a confirmation email.
        action = self.action_class(
            template_id=settings.HPO_GOV_NOTIFY_USER_TEMPLATE_ID,
            email_address=self.cleaned_data['email_address'],
            form_url=form_url,
            email_reply_to_id=settings.HPO_GOV_NOTIFY_USER_REPLY_TO_ID,
        )
        response = action.save(self.serialized_data)
        response.raise_for_status()

    def save(self, form_url):
        self.send_agent_email(form_url=form_url)
        self.send_user_email(form_url=form_url)
Ejemplo n.º 23
0
class ContactForm(GovNotifyActionMixin, forms.Form):
    def __init__(self, industry_choices, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields['terms_agreed'].widget.label = mark_safe(
            ugettext('I agree to the <a href="{url}" target="_blank">'
                     'great.gov.uk terms and conditions</a>').format(
                         url=urls.TERMS_AND_CONDITIONS))
        self.fields['sector'].choices = industry_choices

    full_name = fields.CharField(
        label=_('Full name'),
        max_length=255,
        validators=[not_contains_url_or_email],
        widget=TextInput(attrs={'dir': 'auto'}),
    )
    email_address = fields.EmailField(
        label=_('Email address'),
        widget=TextInput(attrs={'dir': 'auto'}),
    )
    phone_number = fields.CharField(
        label=_('Phone number'),
        widget=TextInput(attrs={'dir': 'auto'}),
    )
    sector = fields.ChoiceField(
        label=_('Your industry'),
        choices=[],  # set in __init__
    )
    organisation_name = fields.CharField(
        label=_('Your organisation name'),
        max_length=255,
        validators=[not_contains_url_or_email],
        widget=TextInput(attrs={'dir': 'auto'}),
    )
    organisation_size = fields.ChoiceField(
        label=_('Size of your organisation'),
        choices=choices.EMPLOYEES,
        required=False,
    )
    country = fields.CharField(
        label=_('Your country'),
        max_length=255,
        validators=[not_contains_url_or_email],
        widget=TextInput(attrs={'dir': 'auto'}),
    )
    body = fields.CharField(
        label=_('Describe what products or services you need'),
        help_text=_('Maximum 1000 characters.'),
        max_length=1000,
        widget=Textarea(attrs={'dir': 'auto'}),
        validators=[not_contains_url_or_email],
    )
    source = fields.ChoiceField(
        label=_('Where did you hear about great.gov.uk?'),
        choices=(('', ''), ) + constants.MARKETING_SOURCES,
        required=False,
        initial=' ',  # prevent "other" being selected by default
        widget=Select(attrs={'class': 'js-field-other-selector'}))
    source_other = fields.CharField(
        label=_("Other source (optional)"),
        required=False,
        widget=TextInput(attrs={
            'class': 'js-field-other',
            'dir': 'auto',
        }),
        validators=[not_contains_url_or_email],
    )
    terms_agreed = fields.BooleanField()
    captcha = ReCaptchaField()

    @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_agreed']
        return data
Ejemplo n.º 24
0
class ContactCompanyForm(GovNotifyActionMixin, forms.Form):

    TERMS_CONDITIONS_LABEL = (
        '<p>I agree to the great.gov.uk terms and conditions and I '
        'understand that:</p>'
        '<ul class="list list-bullet">'
        '<li>the Department for International Trade (DIT) has reasonably '
        'tried to ensure that businesses listed in the UK Investment Support '
        'Directory are appropriately qualified and that the information in '
        'this directory is accurate and up to date</li>'
        '<li>DIT is not endorsing the character, ability, goods or services '
        'of members of the directory</li>'
        '<li>there is no legal relationship between DIT and directory '
        'members</li>'
        '<li>DIT is not liable for any direct or indirect loss or damage that '
        'might happen after a directory member provides a good or service</li>'
        '<li>directory members will give 1 hour’s free consultation to '
        'businesses that contact them through this service</li>'
        '</ul>')
    TERMS_CONDITIONS_MESSAGE = (
        'Tick the box to confirm you agree to the terms and conditions.')
    given_name = fields.CharField(
        label='Given name',
        max_length=255,
        validators=[not_contains_url_or_email],
    )
    family_name = fields.CharField(
        label='Family name',
        max_length=255,
        validators=[not_contains_url_or_email],
    )
    company_name = fields.CharField(
        label='Your organisation name',
        max_length=255,
        validators=[not_contains_url_or_email],
    )
    email_address = fields.EmailField(label='Email address', )
    sector = fields.ChoiceField(
        label='Industry',
        choices=([['', 'Please select your industry']] +
                 list(choices.INDUSTRIES)),
    )
    subject = fields.CharField(
        label='Enter a subject line for your message',
        max_length=200,
        validators=[not_contains_url_or_email],
    )
    body = fields.CharField(
        label='Enter your message to the UK company',
        help_text='Maximum 1000 characters.',
        max_length=1000,
        widget=Textarea,
        validators=[not_contains_url_or_email],
    )
    has_contact = fields.ChoiceField(label=(
        'Do you currently have a contact at Department of international '
        'trade'),
                                     widget=widgets.RadioSelect(
                                         use_nice_ids=True,
                                         attrs={'id': 'radio-one'}),
                                     choices=(
                                         (True, 'Yes'),
                                         (False, 'No'),
                                     ))
    terms = fields.BooleanField(
        label=mark_safe(TERMS_CONDITIONS_LABEL),
        error_messages={'required': TERMS_CONDITIONS_MESSAGE},
    )
    captcha = ReCaptchaField(label='')