class ContactForm(forms.ModelForm): fullName = forms.CharField( widget=forms.TextInput(attrs={ "placeholder": "Your Full Name", "type": "text" }), label="", ) phone = forms.CharField(widget=forms.TextInput({ "placeholder": "Phone Number", "type": "tel" }), label="") email = forms.CharField( widget=forms.TextInput({ "placeholder": "Email Address", "type": "email" }), label="", ) message = forms.CharField(widget=forms.Textarea( {"placeholder": "Your Message"}), label="") number = HoneypotField() class Meta: model = Contact fields = ("fullName", "phone", "email", "message")
class ContactoForm(forms.Form): nombre = forms.CharField() correo = forms.EmailField() ubicacion = forms.ModelChoiceField(queryset=Ubicacion.objects.all(), empty_label='UbicaciĆ³n') mensaje = forms.CharField(widget=forms.Textarea({'rows': 6})) spam_honeypot_field = HoneypotField() captcha = ReCAPTCHA()
class ContactForm(forms.Form): from_email = forms.EmailField(required=True) subject = forms.CharField(required=True) message = forms.CharField(widget=forms.Textarea, required=True) spam_honeypot_field = HoneypotField() captcha = ReCaptchaField(widget=ReCaptchaV2Invisible)
def test_validate(self): field = HoneypotField() field.validate('') with self.assertRaises(ValidationError): field.validate('v')
class ContactoRecursosHumanosForm(forms.Form): nombre = forms.CharField() correo = forms.EmailField() ubicacion = forms.ModelChoiceField(queryset=Ubicacion.objects.all(), empty_label='UbicaciĆ³n') mensaje = forms.CharField(widget=forms.Textarea) departamento = forms.ChoiceField() archivo = forms.FileField() spam_honeypot_field = HoneypotField() captcha = ReCAPTCHA() def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) choices = [("", "Departamento")] for choice in kwargs['initial']['departamento']: choices += [(choice.id, choice.nombre)] self.fields["departamento"].choices = choices
class FeedbackForm(UserKwargModelFormMixin, ModelForm): spam = HoneypotField() def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = getattr(self, "helper", FormHelper()) self.helper.add_input( Submit("action", _("Submit feedback"), css_class="btn-primary")) self.fields["url"].widget = HiddenInput() self.helper.form_action = reverse("tasty_feedback:submit") def save(self, *args, **kwargs): if not self.user.is_anonymous: self.instance.user = self.user return super().save(*args, **kwargs) class Meta: model = Feedback fields = ( "text", "url", )
class ContactForm(forms.Form): name = forms.CharField(label='Name') email = forms.EmailField(label='Email address') message = forms.CharField(label='Message', widget=forms.Textarea) spam_honeypot_field = HoneypotField() referrer = forms.CharField(label='Referrer', required=False, widget=forms.HiddenInput) def __init__(self, *args, **kwargs): self.request = kwargs.pop('request', None) super().__init__(*args, **kwargs) def clean(self): if self.request and self.is_valid( ) and 'seen_cookie_message' not in self.request.COOKIES and akismet.check( request=akismet.Request.from_django_request(self.request), comment=akismet.Comment( content=self.cleaned_data['message'], type='comment', author=akismet.Author(name=self.cleaned_data['name'], email=self.cleaned_data['email']))): raise ValidationError('Spam detected', code='spam-protection')
def test_not_required(self): self.assertFalse(HoneypotField().required) with self.assertRaises(AssertionError): HoneypotField(required=False)