You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
django_recaptcha v4 has some improvements in flexibility, including adding a per instance action for the V3 recaptcha.
At the moment, the usual route in WagtailCaptcha to add any config to the widget seems to be to create a custom WagtailCaptchaFormBuilder. This route requires a custom FormBuilder to use anything other than V2 checkbox and a separate FormBuilder for each action.
It got me thinking that a preferable route would be the ability to add a default widget to the site, and an optional dictionary in the model to supply any per instance parameters.
Thought I'd open a discussion to see if people had thoughts on the below:
First thought: if the namespace is captcha, leave everything as is, the additional change is only for django_recaptcha v4+
Add an optional setting for site default widget:
RECAPTCHA_WIDGET='ReCaptchaV3'
Add an attribute to the model instance (recaptcha_attrs) which can be used to pass per instance settings through to the form builder. E.g.:
Add possible parameters to WagtailCaptchaFormBuilder. Set widget via instance > site default > V2 checkbox (django_recaptcha default), widget can be passed as object or string:
Modify the formfields property to conditionally (only if django_recaptcha namespace in use) build the field attributes. Field attributes include widget and keys (recaptcha keys can also be added per instance with django_recaptcha):
With no recaptcha_attrs or settings.RECAPTCHA_WIDGET defined, this will just return the default V2 checkbox as per current status.
If django-captcha is still on v3, no changes happen to the way the form builder sets the ReCaptchaField from the existing method.
With recaptcha_attrs, you get some flexibility with per instance without the need for custom form builders.
Ex, signup form with stronger required score and custom action (settings.RECAPTCHA_WIDGET='ReCaptchaV3'). This score will override settings.RECAPTCHA_REQUIRED_SCORE (ref)
Maybe one form on this site needs to use the V2 checkbox. Add the widget as a string, add the keys for the V2 api. Optionally set the V2 widget format:
django_recaptcha
v4 has some improvements in flexibility, including adding a per instance action for the V3 recaptcha.At the moment, the usual route in WagtailCaptcha to add any config to the widget seems to be to create a custom
WagtailCaptchaFormBuilder
. This route requires a custom FormBuilder to use anything other than V2 checkbox and a separate FormBuilder for each action.It got me thinking that a preferable route would be the ability to add a default widget to the site, and an optional dictionary in the model to supply any per instance parameters.
Thought I'd open a discussion to see if people had thoughts on the below:
First thought: if the namespace is
captcha
, leave everything as is, the additional change is only fordjango_recaptcha
v4+Add an optional setting for site default widget:
Add an attribute to the model instance (
recaptcha_attrs
) which can be used to pass per instance settings through to the form builder. E.g.:Modify the WagtailCaptcha models to look for this attribute and pass through to the form builder:
Add possible parameters to
WagtailCaptchaFormBuilder
. Set widget via instance > site default > V2 checkbox (django_recaptcha default), widget can be passed as object or string:Modify the
formfields
property to conditionally (only ifdjango_recaptcha
namespace in use) build the field attributes. Field attributes include widget and keys (recaptcha keys can also be added per instance withdjango_recaptcha
):With no
recaptcha_attrs
orsettings.RECAPTCHA_WIDGET
defined, this will just return the default V2 checkbox as per current status.If
django-captcha
is still on v3, no changes happen to the way the form builder sets the ReCaptchaField from the existing method.With
recaptcha_attrs
, you get some flexibility with per instance without the need for custom form builders.Ex, signup form with stronger required score and custom action (
settings.RECAPTCHA_WIDGET='ReCaptchaV3'
). This score will overridesettings.RECAPTCHA_REQUIRED_SCORE
(ref)Maybe one form on this site needs to use the V2 checkbox. Add the widget as a string, add the keys for the V2 api. Optionally set the V2 widget format:
On a multi-lingual site, ensure the widget display language matches the django activated language:
I can make a PR for this if there's appetite - thought I'd sound it out here for thoughts on improvements/feasibility first.
The text was updated successfully, but these errors were encountered: