Skip to main content

基于 Django 简单数学验证码的 Wagtail 表单页面的简单数学验证码字段。

项目描述

基于 Django 简单数学验证码的 Wagtail 表单页面的简单数学验证码字段。

wagtail-simple-math-captcha 提供了一种以 Wagtail 形式集成 django-simple-math-captcha的方法 。该代码基于 wagtailsweetaptcha

安装

  1. 安装wagtail-simple-math-captcha

  2. wagtailsimplemathcaptcha添加到您的 settings.py中的INSTALLED_APPS中。

用法

当您安装wagtail-simple-math-captcha时,您不会在表单构建器的可用字段类型中获得验证码字段。要使用它,您需要继承 MathCaptchaFormMathCaptchaEmailForm (分别替换AbstractFormAbstractEmailForm )。完成后,验证码字段将出现在您的前端:

from modelcluster.fields import ParentalKey
from wagtail.wagtailadmin.edit_handlers import (FieldPanel, InlinePanel,
    MultiFieldPanel)
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField

from wagtailsimplemathcaptcha.models import MathCaptchaEmailForm

class FormField(AbstractFormField):
    page = ParentalKey('FormPage', related_name='form_fields')

class FormPage(MathCaptchaEmailForm):
    intro = RichTextField(blank=True)
    thank_you_text = RichTextField(blank=True)

    # wagtail-simple-math-captcha configuration
    captcha_label = ""
    captcha_help_text = "Answer this question to prove you're human."

FormPage.content_panels = [
    FieldPanel('title', classname="full title"),
    FieldPanel('intro', classname="full"),
    InlinePanel('form_fields', label="Form fields"),
    FieldPanel('thank_you_text', classname="full"),
    MultiFieldPanel([
        FieldPanel('to_address', classname="full"),
        FieldPanel('from_address', classname="full"),
        FieldPanel('subject', classname="full"),
    ], "Email")
]

您可以通过在类中包含captcha_labelcaptcha_help_text 属性或覆盖get_captcha_label()get_captcha_help_text()方法来配置字段的verbose_namehelp_text 属性:

from modelcluster.fields import ParentalKey
from wagtail.wagtailadmin.edit_handlers import (FieldPanel, InlinePanel,
    MultiFieldPanel)
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailforms.models import AbstractEmailForm, AbstractFormField

from wagtailsimplemathcaptcha.models import MathCaptchaEmailForm

class FormField(AbstractFormField):
    page = ParentalKey('FormPage', related_name='form_fields')

class FormPage(MathCaptchaEmailForm):
    intro = RichTextField(blank=True)
    thank_you_text = RichTextField(blank=True)

    # wagtail-simple-math-captcha configuration
    def get_captcha_label(self):
        return ""

    def get_captcha_help_text(self):
        return "Answer this question to prove you're human."

FormPage.content_panels = [
    FieldPanel('title', classname="full title"),
    FieldPanel('intro', classname="full"),
    InlinePanel('form_fields', label="Form fields"),
    FieldPanel('thank_you_text', classname="full"),
    MultiFieldPanel([
        FieldPanel('to_address', classname="full"),
        FieldPanel('from_address', classname="full"),
        FieldPanel('subject', classname="full"),
    ], "Email")
]

captcha_labelcaptcha_help_text的默认值都是空字符串。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

wagtail-simple-math-captcha-0.1.2.zip (10.7 kB 查看哈希

已上传 source