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

    @property
    def serialized_data(self):
        if 'captcha' in self.cleaned_data:
            del self.cleaned_data['captcha']
        return self.cleaned_data
示例#2
0
def get_recaptcha_widget():
    from captcha.widgets import (
        ReCaptchaV2Checkbox,
        ReCaptchaV2Invisible,
        ReCaptchaV3,
    )
    captcha_attrs = {}
    captcha_params = {}
    try:
        captcha_attrs = settings.EMAILER_RECAPTCHA_ATTRS
    except AttributeError:
        pass
    try:
        captcha_params = settings.EMAILER_RECAPTCHA_PARAMS
    except AttributeError:
        pass
    widget_dict = {
        1: ReCaptchaV2Checkbox(attrs=captcha_attrs, api_params=captcha_params),
        2: ReCaptchaV2Invisible(attrs=captcha_attrs,
                                api_params=captcha_params),
        3: ReCaptchaV3(attrs=captcha_attrs, api_params=captcha_params),
    }
    try:
        widget_type = settings.EMAILER_RECAPTCHA_TYPE
    except AttributeError:
        widget_type = 1
    return widget_dict[widget_type]
示例#3
0
class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()
    captcha = ReCaptchaField(widget=ReCaptchaV3())

    class Meta:
        model = User
        fields = ['username', 'email', 'captcha', 'password1', 'password2']
示例#4
0
    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)

        for field_name, field in self.fields.items():
            self.fields[field_name].widget.attrs['placeholder'] = self.fields[
                field_name].label
            self.fields[field_name].label = ''

        self.helper = FormHelper()
        self.helper.form_action = reverse('inventor:newsletter')
        self.helper.form_class = 'form-inline justify-content-md-end justify-content-center'
        self.helper.layout = Layout(
            Row(
                Div('email', css_class='col-sm'),
                Div(Submit('submit', _('Subscribe'), css_class='btn-primary'),
                    css_class='col-sm-auto d-flex justify-content-center')))

        self.cookies_accepted = request.COOKIES.get('isCookieAccepted',
                                                    'no') == 'yes'

        # TODO: when cookies accepted and form submitted on the same request, we need to skip captcha

        if not settings.DEBUG and self.cookies_accepted:
            # add captcha field dynamically because we have multiple forms on a single page
            self.fields['captcha'] = ReCaptchaField(label='',
                                                    widget=ReCaptchaV3())
            self.helper.layout.append('captcha')
示例#5
0
class ContactForm(forms.Form):
    name = forms.CharField(required=True)
    email = forms.CharField(required=True)
    message = forms.CharField(required=True)
    terms_and_conditions = forms.BooleanField(required=True)

    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs={
        "required_score": 0.3,
        "action": "help"
    }),
                             label="")

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

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

    def send_email(self):
        send_mail(
            f"Contact {self.cleaned_data.get('name')}",
            f"{self.cleaned_data.get('email')}: {self.cleaned_data.get('message')}",
            settings.NO_REPLY_EMAIL,
            (settings.DEFAULT_FROM_EMAIL, ),
        )
class InternationalContactForm(SerializeDataMixin, GovNotifyEmailActionMixin,
                               forms.Form):

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

    given_name = forms.CharField()
    family_name = forms.CharField()
    email = forms.EmailField(label='Email address')
    organisation_type = forms.ChoiceField(label_suffix='',
                                          widget=forms.RadioSelect(),
                                          choices=ORGANISATION_TYPE_CHOICES)
    organisation_name = forms.CharField(label='Your organisation name')
    country_name = forms.ChoiceField(choices=[('', 'Please select')] +
                                     choices.COUNTRY_CHOICES, )
    city = forms.CharField(label='City')
    comment = forms.CharField(
        label='Tell us how we can help',
        help_text=('Do not include personal information or anything of a '
                   'sensitive nature'),
        widget=Textarea,
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)
示例#7
0
class RegisterForm(forms.Form):
    username = forms.CharField(
        label="",
        max_length=128,
        widget=forms.TextInput(attrs={
            "size": 34,
            "placeholder": "Nazwa kawalerzysty"
        }))
    email = forms.EmailField(
        label="",
        max_length=128,
        widget=forms.EmailInput(attrs={
            "size": 34,
            "placeholder": "Adres email"
        }))
    password = forms.CharField(label="",
                               widget=forms.PasswordInput(
                                   {
                                       "size": 34,
                                       "placeholder": "Hasło"
                                   }, ))
    password2 = forms.CharField(label="",
                                widget=forms.PasswordInput(
                                    {
                                        "size": 34,
                                        "placeholder": "Powtórz hasło"
                                    }, ))
    captcha = ReCaptchaField(
        label="", widget=ReCaptchaV3(attrs={'required_score': 0.85}))
class NGORegisterRequestForm(forms.ModelForm):
    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs={
        "required_score": 0.85,
    }),
                             label="")

    class Meta:
        model = models.RegisterNGORequest
        fields = [
            "name",
            "county",
            "city",
            "address",
            "email",
            "contact_name",
            "contact_phone",
            "social_link",
            "description",
            "past_actions",
            "resource_types",
            "has_netopia_contract",
            "avatar",
            "last_balance_sheet",
            "statute",
        ]
        widgets = {
            "email": EmailInput(),
            # # "has_netopia_contract": forms.CheckboxInput(),
            # "avatar": AdminResubmitImageWidget,
            # "last_balance_sheet": AdminResubmitFileWidget,
            # "statute": AdminResubmitFileWidget,
        }
示例#9
0
class EUExitDomesticContactForm(
        SerializeMixin,
        ZendeskActionMixin,
        ConsentFieldMixin,
        forms.Form,
):

    COMPANY = 'COMPANY'

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

    first_name = forms.CharField()
    last_name = forms.CharField()
    email = forms.EmailField()
    organisation_type = forms.ChoiceField(
        label='Business type',
        widget=forms.RadioSelect(),
        choices=COMPANY_CHOICES,
    )
    company_name = forms.CharField()
    comment = forms.CharField(
        label='Your question',
        help_text="Please don't share any commercially sensitive information.",
        widget=Textarea,
        validators=[
            no_html,
            not_contains_url_or_email,
        ],
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
示例#10
0
文件: forms.py 项目: panwaclaw/dolg
class CustomAuthenticationForm(AuthenticationForm):
    username = forms.CharField(
        max_length=32,
        required=True, 
        validators=[UnicodeUsernameValidator,],
        label=_('Username'),
        widget=forms.TextInput(
            attrs={'placeholder': _('Username'), "class": "form-control form-control-gold", 'autofocus': True}
        )
    )
    password = forms.CharField(
        max_length=32,
        required=True,
        label=_('Password'),
        strip=False,
        widget=forms.PasswordInput(
            attrs={'placeholder': _('Password'), "class": "form-control form-control-gold", 'autocomplete': 'current-password'}
        )
    )
    captcha = ReCaptchaField(widget=ReCaptchaV3())

    def confirm_login_allowed(self, user):
        if not user.is_active:
            raise ValidationError(
                _("This account is inactive. Please contact support.`"),
                code='inactive',
            )

        if not user.is_confirmed:
            raise ValidationError(
                _("Your account is not confirmed. Please check your e-mail for the letter with activation link."),
                code="banned",
            )
示例#11
0
class NGOHelperForm(forms.ModelForm):
    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs={
        "required_score": 0.85,
    }),
                             label="")

    class Meta:
        model = models.NGOHelper
        fields = ("name", "email", "message", "phone")
        widgets = {"email": EmailInput()}
示例#12
0
 class Meta:
     model = User
     fields = ('username', 'first_name', 'last_name', 'email')
     widgets = {
         'captcha':
         ReCaptchaV3(api_params={
             'hl': get_language()[:2],
             'badge': 'inline',
         }),
     }
示例#13
0
class ContactUsHelpForm(GovNotifyEmailActionMixin, 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()
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)
示例#14
0
class HelpForm(ConsentFieldMixin, forms.Form):
    error_css_class = 'input-field-container has-error'

    comment = forms.CharField(
        label=
        'Tell us about your export experience, including any challenges you are facing.',
        help_text=("We're particularly interested in the markets you "
                   'have exported to and whether you have already '
                   'spoken to your bank or a broker. '),
        widget=Textarea(attrs={'class': 'margin-top-15'}),
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
示例#15
0
class ContactMessageForm(forms.Form):
    """Contact message form class."""

    label_class = 'contact-form-label'
    input_class = 'contact-form-input form-input'

    name = forms.CharField(
        max_length=40,
        widget=forms.TextInput(attrs={
            'class': input_class,
            'placeholder': _('How can I contact you'),
        }))

    email = forms.EmailField(
        max_length=254,
        widget=forms.EmailInput(
            attrs={
                'class': input_class,
                'placeholder': _('Where can I send a response'),
            }),
    )

    subject = forms.CharField(
        max_length=80,
        required=False,
        widget=forms.TextInput(attrs={
            'class': input_class,
            'placeholder': _('Can be blank'),
        }),
    )

    gotcha = forms.CharField(
        required=False,
        widget=forms.HiddenInput(attrs={
            'class': 'contact-form-gotcha',
        }))

    captcha = ReCaptchaField(
        widget=ReCaptchaV3(attrs={
            'data-theme': 'light',
            'data-size': 'invisible',
        }),
        label='',
    )

    message = forms.CharField(
        max_length=2000,
        widget=forms.Textarea(attrs={
            'rows': 7,
            'class': 'contact-form-textarea form-input'
        }),
    )
示例#16
0
class DomesticContactForm(FieldsMutationMixin, SerializeMixin,
                          ZendeskActionMixin, ConsentFieldMixin, forms.Form):

    first_name = forms.CharField()
    last_name = forms.CharField()
    email = forms.EmailField()
    organisation_type = forms.ChoiceField(label_suffix='',
                                          widget=forms.RadioSelect(),
                                          choices=COMPANY_CHOICES)
    company_name = forms.CharField()
    comment = forms.CharField(widget=Textarea,
                              validators=[no_html, not_contains_url_or_email])
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
示例#17
0
class FeedbackForm(SerializeDataMixin, ZendeskActionMixin, forms.Form):
    name = forms.CharField()
    email = forms.EmailField()
    comment = forms.CharField(
        label='Feedback',
        widget=Textarea,
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)

    @property
    def full_name(self):
        assert self.is_valid()
        return self.cleaned_data['name']
class CreateLinkForm(forms.ModelForm):
    def clean(self):
        full_url = self.cleaned_data.get('full_url')
        if URL.objects.filter(full_url=full_url).exists():
            raise ValidationError("raise an error")
        return self.cleaned_data

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

    class Meta:
        model = URL
        fields = ['full_url', 'captcha']
示例#19
0
class ResetForm(forms.Form):
    password = forms.CharField(label="",
                               widget=forms.PasswordInput(
                                   {
                                       "size": 34,
                                       "placeholder": "Nowe hasło"
                                   }, ))
    password2 = forms.CharField(label="",
                                widget=forms.PasswordInput(
                                    {
                                        "size": 34,
                                        "placeholder": "Powtórz hasło"
                                    }, ))
    captcha = ReCaptchaField(
        label="", widget=ReCaptchaV3(attrs={'required_score': 0.85}))
示例#20
0
class BusinessDetailsForm(ConsentFieldMixin, forms.Form):
    TURNOVER_OPTIONS = (('', 'Please select'), ('0-25k', 'under £25,000'),
                        ('25k-100k', '£25,000 - £100,000'),
                        ('100k-1m', '£100,000 - £1,000,000'),
                        ('1m-5m', '£1,000,000 - £5,000,000'),
                        ('5m-25m', '£5,000,000 - £25,000,000'),
                        ('25m-50m',
                         '£25,000,000 - £50,000,000'), ('50m+',
                                                        '£50,000,000+'))

    company_type = forms.ChoiceField(
        label_suffix='',
        widget=forms.RadioSelect(),
        choices=COMPANY_TYPE_CHOICES,
    )
    companies_house_number = forms.CharField(
        label='Companies House number',
        required=False,
    )
    company_type_other = forms.ChoiceField(
        label_suffix='',
        choices=(('', 'Please select'), ) + COMPANY_TYPE_OTHER_CHOICES,
        required=False,
    )
    organisation_name = forms.CharField()
    postcode = forms.CharField()
    industry = forms.ChoiceField(choices=INDUSTRY_CHOICES)
    industry_other = forms.CharField(
        label='Type in your industry',
        widget=TextInput(attrs={'class': 'js-field-other'}),
        required=False,
    )
    turnover = forms.ChoiceField(
        label='Annual turnover (optional)',
        choices=TURNOVER_OPTIONS,
        required=False,
    )
    employees = forms.ChoiceField(
        label='Number of employees (optional)',
        choices=(('', 'Please select'), ) + choices.EMPLOYEES,
        required=False,
    )
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())

    def clean_industry(self):
        industry = self.cleaned_data['industry']
        self.cleaned_data['industry_label'] = INDUSTRY_MAP[industry]
        return industry
示例#21
0
class MyUserCreationForm(auth_forms.UserCreationForm, BootstrapMixin):
    """Signup form which uses bootstrap css, ReCaptcha and adds some Member fields"""

    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs=captcha_attrs))

    first_name = forms.CharField(max_length=64,
                                 label="Förnamn",
                                 widget=forms.TextInput({
                                     'class':
                                     'form-control',
                                     'placeholder':
                                     'Förnamn'
                                 }))
    last_name = forms.CharField(max_length=64,
                                label="Efternamn",
                                widget=forms.TextInput({
                                    'class':
                                    'form-control',
                                    'placeholder':
                                    'Efternamn'
                                }))

    phone_number = forms.CharField(
        max_length=15,
        label="Telefonnummer",
        widget=forms.TextInput(
            {
                'class': 'form-control',
                'placeholder': 'Telefonnummer'
            }, ),
        required=False,
        help_text="Måste vara på format: +46123456789")

    def _post_clean(self):
        super()._post_clean()

        if not self.cleaned_data.get('first_name'):
            self.add_error('first_name', "Ange förnamn!")

        if not self.cleaned_data.get('last_name'):
            self.add_error('last_name', "Ange efternamn!")

        phone_number = self.cleaned_data.get('phone_number')
        if phone_number and not re.match(r"\+[0-9]{10,15}", phone_number):
            self.add_error(
                'last_name',
                "Måste börja med landskod (+46) och sen bara innehålla siffror!"
            )
示例#22
0
class ContactForm(forms.Form):
    name = forms.CharField(max_length=100, required=True)
    email = forms.EmailField(max_length=100, required=True)
    phone = forms.CharField(max_length=30, required=True)
    collectionPostcode = forms.CharField(max_length=10, required=True)
    deliveryPostcode = collectionPostcode = forms.CharField(
        max_length=10, required=False)
    startDate = forms.DateField(required=False)
    jobType = forms.ChoiceField(choices=([('Home move', 'Home move'), (
        'Office move', 'Office move'), ('Handyman services', 'Handyman services')]), required=True)
    details = forms.CharField(widget=forms.Textarea, required=False)
    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs={'data-badge': 'bottomleft'}))

    def seng_grid_go(self):

        daysUntil = self.cleaned_data["startDate"] - datetime.now().date()

        if daysUntil.days < 14:
            label = 'urgent'
        else:
            label = 'normal'

        send_mail(
            # subject
            'Query from pieceofcake.solutions website',

            # message
            f'',

            # from
            f'*****@*****.**',

            # to
            [config('DEFAULT_TO_EMAIL'), f'{self.cleaned_data["email"]}'],

            html_message=f'A new query from <a href="https://pieceofcake.solutions/">pieceofcake.solutions</a> has been received<br>' +
            f'These are the details:<br><br>' +
            f'<strong>Name:</strong> {self.cleaned_data["name"]}<br>' +
            f'<strong>Email:</strong> {self.cleaned_data["email"]}<br>' +
            f'<strong>Phone:</strong> {self.cleaned_data["phone"]}<br>' +
            f'<strong>Collection post code:</strong> {self.cleaned_data["collectionPostcode"]}<br>' +
            f'<strong>Delivery post code:</strong> {self.cleaned_data["deliveryPostcode"]}<br>' +
            f'<strong>Would like to commence the job on:</strong> {self.cleaned_data["startDate"].strftime("%A, %d %B, %Y")} (in {daysUntil.days} days)<br>' +
            f'<strong>Job type:</strong> {self.cleaned_data["jobType"]}<br>' +
            f'<strong>Label:</strong> {label}<br>' +
            f'<strong>Optional details:</strong> {self.cleaned_data["details"]}',
            fail_silently=False,
        )
示例#23
0
class LoginForm(forms.Form):
    username = forms.CharField(
        label="",
        max_length=128,
        widget=forms.TextInput(attrs={
            "size": 34,
            "placeholder": "Nazwa kawalerzysty"
        }))
    password = forms.CharField(label="",
                               widget=forms.PasswordInput(
                                   {
                                       "size": 34,
                                       "placeholder": "Hasło"
                                   }, ))
    captcha = ReCaptchaField(
        label="", widget=ReCaptchaV3(attrs={'required_score': 0.85}))
示例#24
0
class PaymentOrderForm(forms.ModelForm):
    captcha = ReCaptchaField(widget=ReCaptchaV3(attrs={
        "required_score": 0.85,
    }),
                             label="")

    class Meta:
        model = models.PaymentOrder
        test = forms.CheckboxInput()
        fields = ("amount", "first_name", "last_name", "phone", "email",
                  "address", "show_name")
        widgets = {
            "email": EmailInput(),
            "amount": forms.NumberInput(attrs={"class": "input"}),
            "show_name": forms.CheckboxInput(),
        }
示例#25
0
class ContactForm(forms.ModelForm):

    class Meta:
        model = Contact
        fields = ('first_name', 'last_name', 'email', 'message')

    captcha = ReCaptchaField(
        widget=ReCaptchaV3(
            attrs={
                'data-theme': 'light',
                'data-size': 'invisible',
            }
        )
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
示例#26
0
class FileUploadModelForm(forms.ModelForm):
    class Meta:
        model = File
        labels = {'file': ''}
        fields = ['file']
        widgets = {
            'file': forms.ClearableFileInput(attrs={'class': 'form-control'})
        }

    def clean_file(self):
        file = self.cleaned_data['file']
        ext = file.name.split('.')[-1].lower()
        if ext != "xls":
            raise forms.ValidationError(".xls以外の拡張子ファイルはアップロードいただけません。")
        # return cleaned data is very important.
        return file

    captcha = ReCaptchaField(label='',
                             widget=ReCaptchaV3(attrs={'required_score': 0.7}))
示例#27
0
class InternationalContactForm(FieldsMutationMixin, SerializeMixin,
                               ZendeskActionMixin, forms.Form):
    first_name = forms.CharField()
    last_name = forms.CharField()
    email = forms.EmailField()
    organisation_type = forms.ChoiceField(
        label_suffix='',
        widget=forms.RadioSelect(),
        choices=COMPANY_CHOICES,
    )
    company_name = forms.CharField()
    country = forms.ChoiceField(
        choices=[('', 'Please select')] + choices.COUNTRY_CHOICES,
        widget=Select(),
    )
    city = forms.CharField()
    comment = forms.CharField(widget=Textarea,
                              validators=[no_html, not_contains_url_or_email])
    captcha = ReCaptchaField(label='', label_suffix='', widget=ReCaptchaV3())
    terms_agreed = forms.BooleanField(label=TERMS_LABEL)
示例#28
0
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)
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")
示例#30
0
文件: forms.py 项目: D1ang/Portfolio
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=('')
    )