class ExportVoucherForm(SerializeDataMixin, GovNotifyEmailActionMixin,
                        forms.Form):
    company_name = forms.CharField()
    companies_house_number = forms.CharField(
        label='Companies House number',
        required=False,
        container_css_classes='js-disabled-only',
    )
    first_name = forms.CharField(label='First name')
    last_name = forms.CharField(label='Last name')
    email = forms.EmailField()
    exported_to_eu = TypedChoiceField(
        label='Have you exported to the EU in the last 12 months?',
        label_suffix='',
        coerce=lambda x: x == 'True',
        choices=[(True, 'Yes'), (False, 'No')],
        widget=forms.RadioSelect(),
        required=False,
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)
Example #2
0
class ContactForm(forms.Form):
    contact_name = forms.CharField(
        label=(''),
        required=True,
        max_length=50,
        widget=forms.TextInput(attrs={'placeholder': 'Name'})
    )
    contact_email = forms.EmailField(
        label=(''),
        required=True,
        max_length=150,
        widget=forms.TextInput(attrs={'placeholder': 'Email'})
    )
    message = forms.CharField(
        label=(''),
        required=True,
        max_length=500,
        widget=forms.Textarea(attrs={'rows': 4, 'placeholder': 'Message'})
    )
    captcha = ReCaptchaField(
        widget=ReCaptchaV3(attrs={'required_score':0.75}),
        label=('')
    )
class CommentForm(forms.ModelForm):
    name = forms.CharField(required=True, max_length=20)
    text = forms.CharField(required=True, max_length=200)

    # captcha = ReCaptchaField()

    # captcha = ReCaptchaField(
    #     widget=ReCaptchaV2Checkbox(
    #         attrs={
    #             # 'data-theme': 'dark',
    #             "data-size": "compact",
    #         }
    #     )
    # )
    # captcha = ReCaptchaField(widget=ReCaptchaV2Invisible)

    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs={
        "required_score": 0.85,
    }))

    class Meta:
        model = Comment
        fields = ("name", "text", "captcha")
class BaseShortForm(forms.Form):
    comment = forms.CharField(
        label='Please give us as much detail as you can',
        widget=Textarea,
    )
    given_name = forms.CharField(label='First name')
    family_name = forms.CharField(label='Last name')
    email = forms.EmailField()
    company_type = forms.ChoiceField(
        label='Company type',
        label_suffix='',
        widget=forms.RadioSelect(),
        choices=COMPANY_TYPE_CHOICES,
    )
    company_type_other = forms.ChoiceField(
        label='Type of organisation',
        label_suffix='',
        choices=(('', 'Please select'), ) + COMPANY_TYPE_OTHER_CHOICES,
        required=False,
    )
    organisation_name = forms.CharField()
    postcode = forms.CharField()
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)
Example #5
0
class contact_f(forms.Form):

    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs={
        'required_score': 0.85,
    }))
Example #6
0
class CommentDetailsForm(CommentSecurityForm):
    """
    Handles the specific details of the comment (name, comment, etc.).
    """
    name = forms.CharField(label=pgettext_lazy("Person name", "Name"),
                           max_length=50)
    email = forms.EmailField(label=_("Email address"))
    url = forms.URLField(label=_("URL"), required=False)
    # Translators: 'Comment' is a noun here.
    comment = forms.CharField(label=_('Comment'),
                              widget=forms.Textarea,
                              max_length=COMMENT_MAX_LENGTH)
    captcha = ReCaptchaField(widget=ReCaptchaV3())  # /** custom change **\

    def get_comment_object(self, site_id=None):
        """
        Return a new (unsaved) comment object based on the information in this
        form. Assumes that the form is already validated and will throw a
        ValueError if not.

        Does not set any of the fields that would come from a Request object
        (i.e. ``user`` or ``ip_address``).
        """
        if not self.is_valid():
            raise ValueError(
                "get_comment_object may only be called on valid forms")

        CommentModel = self.get_comment_model()
        new = CommentModel(**self.get_comment_create_data(site_id=site_id))
        new = self.check_for_duplicate_comment(new)

        return new

    def get_comment_model(self):
        """
        Get the comment model to create with this form. Subclasses in custom
        comment apps should override this, get_comment_create_data, and perhaps
        check_for_duplicate_comment to provide custom comment models.
        """
        return get_model()

    def get_comment_create_data(self, site_id=None):
        """
        Returns the dict of data to be used to create a comment. Subclasses in
        custom comment apps that override get_comment_model can override this
        method to add extra fields onto a custom comment model.
        """
        return dict(
            content_type=ContentType.objects.get_for_model(self.target_object),
            object_pk=force_text(self.target_object._get_pk_val()),
            user_name=self.cleaned_data["name"],
            user_email=self.cleaned_data["email"],
            user_url=self.cleaned_data["url"],
            comment=self.cleaned_data["comment"],
            submit_date=timezone.now(),
            site_id=site_id or getattr(settings, "SITE_ID", None),
            is_public=True,
            is_removed=False,
        )

    def check_for_duplicate_comment(self, new):
        """
        Check that a submitted comment isn't a duplicate. This might be caused
        by someone posting a comment twice. If it is a dup, silently return the *previous* comment.
        """
        possible_duplicates = self.get_comment_model()._default_manager.using(
            self.target_object._state.db).filter(
                content_type=new.content_type,
                object_pk=new.object_pk,
                user_name=new.user_name,
                user_email=new.user_email,
                user_url=new.user_url,
            )
        for old in possible_duplicates:
            if old.submit_date.date() == new.submit_date.date(
            ) and old.comment == new.comment:
                return old

        return new

    def clean_comment(self):
        """
        If COMMENTS_ALLOW_PROFANITIES is False, check that the comment doesn't
        contain anything in PROFANITIES_LIST.
        """
        comment = self.cleaned_data["comment"]
        if (not getattr(settings, 'COMMENTS_ALLOW_PROFANITIES', False)
                and getattr(settings, 'PROFANITIES_LIST', False)):
            bad_words = [
                w for w in settings.PROFANITIES_LIST if w in comment.lower()
            ]
            if bad_words:
                raise forms.ValidationError(
                    ungettext(
                        "Watch your mouth! The word %s is not allowed here.",
                        "Watch your mouth! The words %s are not allowed here.",
                        len(bad_words)) % get_text_list([
                            '"%s%s%s"' % (i[0], '-' * (len(i) - 2), i[-1])
                            for i in bad_words
                        ], ugettext('and')))
        return comment
class ExportSupportForm(GovNotifyEmailActionMixin, forms.Form):

    EMPLOYEES_NUMBER_CHOICES = (
        ('1-9', '1 to 9'),
        ('10-49', '10 to 49'),
        ('50-249', '50 to 249'),
        ('250-499', '250 to 499'),
        ('500plus', 'More than 500'),
    )

    first_name = forms.CharField(
        label='First name',
        min_length=2,
        max_length=50,
        error_messages={'required': 'Enter your first name'})
    last_name = forms.CharField(
        label='Last name',
        min_length=2,
        max_length=50,
        error_messages={'required': 'Enter your last name'})
    email = forms.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 = forms.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 a UK phone number',
            'invalid': 'Please enter a UK phone number',
        })
    job_title = forms.CharField(label='Job title',
                                max_length=50,
                                error_messages={
                                    'required': 'Enter your job title',
                                })
    company_name = forms.CharField(label='Business name',
                                   max_length=50,
                                   error_messages={
                                       'required': 'Enter your business name',
                                   })
    company_postcode = forms.CharField(
        label='Business postcode',
        max_length=50,
        error_messages={
            'required': 'Enter your business postcode',
            'invalid': 'Please enter a UK postcode'
        },
        validators=[is_valid_postcode],
    )
    annual_turnover = forms.ChoiceField(
        label='Annual turnover',
        help_text=
        ('This information will help us tailor our response and advice on the services we can provide.'
         ),
        choices=(('Less than £500K', 'Less than £500K'), ('£500K to £2M',
                                                          '£500K to £2M'),
                 ('£2M to £5M', '£2M to £5M'), ('£5M to £10M', '£5M to £10M'),
                 ('£10M to £50M', '£10M to £50M'), ('£50M or higher',
                                                    '£50M or higher')),
        widget=forms.RadioSelect,
        required=False,
    )
    employees_number = forms.ChoiceField(label='Number of employees',
                                         choices=EMPLOYEES_NUMBER_CHOICES,
                                         widget=forms.RadioSelect,
                                         error_messages={
                                             'required': 'Choose a number',
                                         })
    currently_export = forms.ChoiceField(
        label='Do you currently export?',
        choices=(('yes', 'Yes'), ('no', 'No')),
        widget=forms.RadioSelect,
        error_messages={'required': 'Please answer this question'})

    terms_agreed = forms.BooleanField(
        label=TERMS_LABEL,
        error_messages={
            'required':
            'You must agree to the terms and conditions before registering',
        })
    comment = forms.CharField(
        label='Please give us as much detail as you can on your enquiry',
        widget=Textarea,
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())

    def clean_phone_number(self):
        phone_number = self.cleaned_data['phone_number'].replace(' ', '')
        if not PHONE_NUMBER_REGEX.match(phone_number):
            raise ValidationError('Please enter a UK phone number')
        return phone_number

    def clean_company_postcode(self):
        return self.cleaned_data['company_postcode'].replace(' ', '').upper()

    @property
    def serialized_data(self):
        data = super().serialized_data
        employees_number_mapping = dict(self.EMPLOYEES_NUMBER_CHOICES)
        data['employees_number_label'] = employees_number_mapping.get(
            data['employees_number'])
        return data
Example #8
0
class UserLoginForm(AuthenticationForm):
    captcha = ReCaptchaField(widget=ReCaptchaV3())

    def __init__(self, *args, **kwargs):
        super(UserLoginForm, self).__init__(*args, **kwargs)
Example #9
0
class ContactFormCaptcha(ContactForm):
    """Recaptcha contact form."""

    captcha = ReCaptchaField(widget=ReCaptchaV3(api_params={"hl": "nl"}),
                             label="")
Example #10
0
class OrganizationCreateForm(forms.ModelForm):
    captcha = ReCaptchaField(
        widget=ReCaptchaV3(attrs={
            "required_score": 0.3,
            "action": "register"
        }),
        label="",
    )

    field_order = ORG_FIELD_ORDER

    class Meta:
        model = models.Organization
        exclude = [
            "user",
            "status",
            "status_changed",
            "report_2019",
            "report_2018",
            "report_2017",
            "fiscal_certificate",
            "statement",
            "politic_members",
        ]
        widgets = {
            "email":
            EmailInput(),
            "legal_representative_email":
            EmailInput(),
            "city":
            forms.Select(attrs={
                "data-url": reverse_lazy("city-autocomplete"),
            }),
        }

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

        if not settings.RECAPTCHA_PUBLIC_KEY:
            del self.fields["captcha"]

        self.fields["city"].queryset = models.City.objects.none()

        if "city" not in self.data:
            self.fields["city"].widget.attrs.update({"disabled": "true"})

        if "county" in self.data:
            try:
                county = self.data.get("county")
                self.fields["city"].queryset = models.City.objects.filter(
                    county__iexact=county)
            except (ValueError, TypeError):
                pass  # invalid input, fallback to empty queryset

        self.fields["accept_terms_and_conditions"].label = mark_safe(
            _('I agree to the <a href="https://votong.ro/ro/termeni/" target="_blank">Terms and Conditions</a> '
              "of the VotONG platform"))

    def clean_accept_terms_and_conditions(self):
        if not self.cleaned_data.get("accept_terms_and_conditions"):
            raise ValidationError(
                _("You need to accept terms and conditions."))
        return self.cleaned_data.get("accept_terms_and_conditions")
Example #11
0
 def __init__(self, *args, **kwargs):
     super(AuthenticationFormWithCaptchaV3, self).__init__(*args, **kwargs)
     if not getattr(settings, 'DEBUG', False):
         self.fields['captcha'] = ReCaptchaField(widget=ReCaptchaV3())
Example #12
0
class MyResetPasswordForm(auth_forms.PasswordResetForm, BootstrapMixin):
    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs=captcha_attrs))
    pass
Example #13
0
class MyAuthenticationForm(auth_forms.AuthenticationForm, BootstrapMixin):
    """Authentication form which uses bootstrap CSS & ReCaptcha."""

    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs=captcha_attrs),
                             label='captcha')
Example #14
0
class CommunityJoinForm(GovNotifyEmailActionMixin, Form):
    name = forms.CharField(
        label=_('Full name'),
        min_length=2,
        max_length=50,
        error_messages={'required': _('Enter your full name')})
    email = forms.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 = forms.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 = forms.CharField(label=_('Business name'),
                                   max_length=50,
                                   error_messages={
                                       'required':
                                       _('Enter your business name'),
                                   })
    company_location = forms.CharField(label=_('Business  location'),
                                       max_length=50,
                                       error_messages={
                                           'required':
                                           _('Enter your business location'),
                                       })
    sector = forms.ChoiceField(label=_('Sector'),
                               choices=INDUSTRY_CHOICES,
                               error_messages={
                                   'required': _('Choose a sector'),
                               })
    sector_other = forms.CharField(
        label=_('Please specify'),
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False,
    )
    company_website = forms.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 = forms.ChoiceField(
        label=_('Number of employees'),
        choices=constants.EMPLOYEES_NUMBER_CHOISES,
        error_messages={
            'required': _('Choose a number'),
        })
    currently_export = forms.ChoiceField(
        label=_('Do you currently export?'),
        choices=(('yes', 'Yes'), ('no', 'No')),
        widget=forms.RadioSelect,
        error_messages={'required': _('Please answer this question')})
    advertising_feedback = forms.ChoiceField(
        label=_('Where did you hear about becoming an Export Advocate?'),
        choices=constants.HEARD_ABOUT_CHOISES,
        error_messages={
            'required':
            _('Please tell us where you heard about'
              ' becoming an Export Advocate'),
        })
    advertising_feedback_other = forms.CharField(
        label=_('Please specify'),
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False,
    )

    terms_agreed = forms.BooleanField(
        label=TERMS_LABEL,
        error_messages={
            'required':
            _('You must agree to the terms and conditions'
              ' before registering'),
        })
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())

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

    def clean_employees_number(self):
        value = self.cleaned_data['employees_number']
        self.cleaned_data[
            'employees_number_label'] = constants.EMPLOYEES_NUMBER_MAP[value]
        return value

    def clean_sector_other(self):
        if self.cleaned_data['sector_other']:
            self.cleaned_data['sector_label'] = self.cleaned_data[
                'sector_other']
        return self.cleaned_data['sector_other']

    def clean_advertising_feedback_other(self):
        if self.cleaned_data['advertising_feedback_other']:
            self.cleaned_data[
                'advertising_feedback_label'] = self.cleaned_data[
                    'advertising_feedback_other']
        return self.cleaned_data['advertising_feedback_other']

    def clean(self):
        data = super().clean()
        if 'sector_label' not in data and 'sector' in data:
            self.cleaned_data['sector_label'] = INDUSTRY_MAP[data['sector']]
        if 'advertising_feedback_label' not in data and 'advertising_feedback' in data:
            self.cleaned_data[
                'advertising_feedback_label'] = constants.HEARD_ABOUT_MAP[
                    data['advertising_feedback']]
        return data
class UKEFContactForm(GovNotifyEmailActionMixin, forms.Form):
    full_name = forms.CharField(
        label=_('Full name'),
        min_length=2,
        max_length=50,
        error_messages={'required': _('Enter your full name')})
    job_title = forms.CharField(label=_('Job title'),
                                max_length=50,
                                error_messages={
                                    'required': _('Enter your job title'),
                                })
    email = forms.EmailField(
        label=_('Business 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]'),
        })
    business_name = forms.CharField(label=_('Business name'),
                                    max_length=50,
                                    error_messages={
                                        'required':
                                        _('Enter your business name'),
                                    })
    business_website = forms.CharField(
        label=_('Business website'),
        max_length=255,
        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)
    country = forms.ChoiceField(label=_('Which country are you based in?'),
                                widget=Select(),
                                choices=COUNTRIES)
    like_to_discuss = forms.ChoiceField(label=_(
        'Do you have a specific project or proposal you’d like to discuss?'),
                                        choices=(
                                            ('no', 'No'),
                                            ('yes', 'Yes'),
                                        ),
                                        widget=forms.RadioSelect,
                                        error_messages={
                                            'required':
                                            _('Please answer this question')
                                        })
    like_to_discuss_other = forms.ChoiceField(
        label=_('Which country is the project located in?'),
        widget=Select(),
        choices=COUNTRIES,
        required=False)
    how_can_we_help = forms.CharField(
        label=_('How can we help?'),
        help_text=_(
            'Please tell us briefly what type of support you’re looking for'),
        widget=Textarea)
    terms_agreed = forms.BooleanField(
        label=TERMS_LABEL,
        error_messages={
            'required':
            _('You must agree to the terms and conditions'
              ' before registering'),
        })
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())

    @property
    def serialized_data(self):
        data = super().serialized_data
        countries_mapping = dict(COUNTRY_CHOICES)
        country_label = countries_mapping.get(data['country'])
        data['country_label'] = country_label
        data['like_to_discuss_country'] = ''
        if data.get('like_to_discuss') == 'yes':
            data['like_to_discuss_country'] = countries_mapping.get(
                data['like_to_discuss_other'])
        return data
Example #16
0
class CreateForm(forms.Form):
    def validate_username(value):
        try:
            u = User.objects.get(username=value)
        except User.DoesNotExist:
            return value
        raise ValidationError(_("A user with that username already exists."))


    def validate_unique_email(value):
        try:
            u = User.objects.get(email=value)
        except User.DoesNotExist:
            return value
        raise ValidationError(_("A user with that e-mail already exists."))


    def validate_referral_id(value):
        try:
            u = User.objects.get(referral_id=value)
        except User.DoesNotExist:
            raise ValidationError(_("There's no user with such referral ID"))
        return value

    last_name = forms.CharField(
        max_length=30,
        required=True,
        label=_('Last name'),
        widget=forms.TextInput(
            attrs={'placeholder': _('Last name'), "class": "form-control form-control-gold"}
        )
    )
    first_name = forms.CharField(
        max_length=30,
        required=True,
        label=_('First name'),
        widget=forms.TextInput(
            attrs={'placeholder': _('First name'), "class": "form-control form-control-gold"}
        )
    )
    middle_name = forms.CharField(
        max_length=30,
        required=True,
        label=_('Last name'),
        widget=forms.TextInput(
            attrs={'placeholder': _('Last name'), "class": "form-control form-control-gold"}
        )
    )
    username = forms.CharField(
        max_length=32,
        required=True, 
        validators=[UnicodeUsernameValidator, validate_username,],
        label=_('Username'),
        widget=forms.TextInput(
            attrs={'placeholder': _('Username'), "class": "form-control form-control-gold"}
        )
    )
    email = forms.EmailField(
        required=True,
        validators=[validate_unique_email,],
        label=_('E-mail'),
        widget=forms.EmailInput(
            attrs={'placeholder': _('E-mail'), "class": "form-control form-control-gold"}
        )
    )
    password = PasswordField(
        max_length=32,
        required=True,
        label=_('Password'),
        widget=PasswordStrengthInput(
            attrs={'placeholder': _('Password'), "class": "form-control form-control-gold"}
        )
    )
    rules_accepted = forms.BooleanField(required=True)
    captcha = ReCaptchaField(widget=ReCaptchaV3())
Example #17
0
class Captcha(forms.Form):
    captcha = ReCaptchaField(widget=ReCaptchaV3())