コード例 #1
0
ファイル: forms.py プロジェクト: nathreed/courtlistener
class DonationForm(ModelForm):
    reference = forms.CharField(
        widget=forms.TextInput(attrs={"class": "form-control"}),
        required=False,
    )
    frequency = forms.ChoiceField(
        widget=forms.RadioSelect,
        choices=FREQUENCIES.NAMES,
        required=False,
        initial="monthly",
    )
    amount = DecimalOrOtherChoiceField(widget=forms.RadioSelect,
                                       choices=AMOUNTS,
                                       initial="50")
    placeholder = f"Amount (min ${settings.MIN_DONATION['docket_alerts']})"
    amount_other = forms.DecimalField(
        required=False,
        widget=forms.TextInput(attrs={
            "placeholder": placeholder,
            "class": "form-control"
        }),
    )
    payment_provider = forms.ChoiceField(
        widget=forms.RadioSelect,
        choices=PROVIDERS.ACTIVE_NAMES,
        initial=PROVIDERS.CREDIT_CARD,
    )
    hcaptcha = hCaptchaField()

    class Meta:
        model = Donation
        fields = (
            "amount_other",
            "amount",
            "frequency",
            "payment_provider",
            "send_annual_reminder",
            "referrer",
            "reference",
            "hcaptcha",
        )
        widgets = {
            "referrer": forms.HiddenInput(),
        }

    def clean(self):
        """
        Handles validation fixes that need to be performed across fields.
        """
        # 1. Set the amount field to amount_other field's value
        if self.cleaned_data.get("amount") == "other":
            self.cleaned_data["amount"] = self.cleaned_data.get("amount_other")
        return self.cleaned_data
コード例 #2
0
class AllAuthSignupForm(forms.Form):
    captcha = hCaptchaField()
    terms = forms.BooleanField(label=_('Accept Terms and Privacy'))

    def __init__(self, **kwargs):
        super(AllAuthSignupForm, self).__init__(**kwargs)
        if settings.PRIVACY_URL == '' and settings.TERMS_URL == '':
            self.fields.pop('terms')
        if settings.HCAPTCHA_SECRET == '':
            self.fields.pop('captcha')

    def signup(self, request, user):
        pass
コード例 #3
0
ファイル: forms.py プロジェクト: mattdahl/courtlistener
class ContactForm(forms.Form):
    name = forms.CharField(
        widget=forms.TextInput(attrs={"class": "form-control"})
    )

    email = forms.EmailField(
        widget=forms.TextInput(attrs={"class": "form-control"})
    )

    # This is actually the "Subject" field, but we call it the phone_number
    # field to defeat spam.
    phone_number = forms.CharField(
        max_length=150,
        widget=forms.TextInput(
            attrs={"class": "form-control", "autocomplete": "off"}
        ),
    )

    message = forms.CharField(
        min_length=20, widget=forms.Textarea(attrs={"class": "form-control"})
    )

    hcaptcha = hCaptchaField()

    def clean(self) -> Dict[str, Any]:
        cleaned_data = super().clean()
        subject = cleaned_data.get("phone_number", "")
        message = cleaned_data.get("message", "")
        regex = re.compile(
            r"block (from)?search engines?|block pages|ccpa|de-index|"
            r"delete link|expunge|opt out|no ?index|remov(e|al)|"
            r"take down request",
            re.I,
        )
        if re.search(regex, subject) and "http" not in message.lower():
            msg = (
                "This appears to be a removal request, but you did not "
                "include a link. You must include a link for a request to be "
                "valid."
            )
            self.add_error("message", msg)
        return cleaned_data
コード例 #4
0
class CaptchaSignupForm(SignupForm):
    hcaptcha = hCaptchaField()
    field_order = ['username', 'email', 'password1', 'password2', 'hcaptcha']

    def save(self, request):
        return super(CaptchaSignupForm, self).save(request)
コード例 #5
0
class CaptchaRegistrationForm(RegistrationForm):
    hcaptcha = hCaptchaField()