Wagtail表单页面的一种简单的ReCaptcha字段。
项目描述
Wagtail ReCaptcha
带有ReCaptcha表单字段/小部件集成应用的Wagtail表单。Wagtail ReCaptcha提供了在Wagtail表单构建器中使用django-recaptcha字段的一种简单方式。
查看Awesome Wagtail以获取更多来自Wagtail社区的优秀包和资源。
安装
通过pip安装wagtailcaptcha pip install wagtail-django-recaptcha 或将wagtailcaptcha添加到Python路径。
将wagtailcaptcha添加到INSTALLED_APPS设置。
按此处所述配置django-recaptcha。
使用
字段
将验证码字段添加到Wagtail表单页面的最快方法是从提供的两种选项中继承,即WagtailCaptchaForm或WagtailCaptchaEmailForm。第一个选项从AbstractForm继承,而第二个则从AbstractEmailForm继承。无论哪种方式,您的页面都将在表单末尾显示验证码字段。
示例
from wagtail.contrib.forms.models import AbstractFormField
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.fields import RichTextField
from modelcluster.fields import ParentalKey
from wagtailcaptcha.models import WagtailCaptchaEmailForm
class SubmitFormField(AbstractFormField):
page = ParentalKey('SubmitFormPage', related_name='form_fields')
class SubmitFormPage(WagtailCaptchaEmailForm):
body = RichTextField(blank=True, help_text='Edit the content you want to see before the form.')
thank_you_text = RichTextField(blank=True, help_text='Set the message users will see after submitting the form.')
class Meta:
verbose_name = "Form submission page"
SubmitFormPage.content_panels = [
FieldPanel('title', classname="full title"),
FieldPanel('body', classname="full"),
FieldPanel('thank_you_text', classname="full"),
InlinePanel('form_fields', label="Form fields"),
MultiFieldPanel([
FieldPanel('to_address'),
FieldPanel('from_address'),
FieldPanel('subject'),
], "Email notification")
]
验证码字段无法从管理界面添加,但将作为表单字段的最后一项出现在前端。
如果您需要自定义表单构建器的行为,请确保从wagtailcaptcha.forms.WagtailCaptchaFormBuilder继承,而不是使用Wagtail的默认表单构建器,然后在页面模型中声明它。
from wagtailcaptcha.forms import WagtailCaptchaFormBuilder
from wagtailcaptcha.models import WagtailCaptchaForm
class CustomFormBuilder(WagtailCaptchaFormBuilder):
# Some custom behaviour...
class FormPage(WagtailCaptchaForm):
form_builder = CustomFormBuilder
# The rest of the page definition as usual...
有关更详细的示例,请参阅用Wagtail制作 (github.com/springload/madewithwagtail),这是一个使用该模块的开源网站。
开发
安装
要求:virtualenv、pyenv、twine
git clone git@github.com:springload/wagtail-django-recaptcha.git
cd wagtail-django-recaptcha/
virtualenv .venv
source ./.venv/bin/activate
make init
命令
使用make help获取命令列表。
发布
为新的版本发布创建一个新分支。
更新变更日志。
在wagtailcaptcha/__init__.py中更新版本号,遵循semver。
提交PR并合并。
PR合并到master后,使用make publish(确认并输入您的密码)。
最后,前往GitHub并为新版本创建发布和标签。
完成!
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。