Mezzanine + ReCaptcha

279 views
Skip to first unread message

Alexander Tyapkov

unread,
Dec 20, 2015, 1:54:30 PM12/20/15
to Mezzanine Users
I have updated Mezzanine to 4.0.1 and found out that the code which registers additional field for forms is not working anymore.
I also want to move to reCaptcha. For that I have downloaded django-recaptcha and have following code:

from captcha import fields as captcha_fields

GREATEST_ID = max(c[0] for c in mezzanine_fields.NAMES)
ID = GREATEST_ID + 1
NAME = 'CAPTCHA'
setattr(mezzanine_fields, NAME, ID)
mezzanine_fields.NAMES = list(mezzanine_fields.NAMES)
mezzanine_fields.NAMES.append((ID, _('Captcha')))

mezzanine_fields.NAMES = tuple(mezzanine_fields.NAMES)
mezzanine_fields.CLASSES[ID] = captcha_fields.ReCaptchaField

The problem is that registered field doesnt appear in admin. Can anybody suggest something?

P.S. Also I have found that it is possible to user FORM_EXTRA_FIELDS in settings but no good example is provided. Can that help? Can anybody post an example of usage?

Stephen McDonald

unread,
Dec 20, 2015, 6:00:43 PM12/20/15
to Mezzanine Users
Forms builder in Mezzanine is ported from (my own project) django-forms-builder, which shows an example in its README:


You'll see notes there about a more robust way of choosing the field IDs - your current approach would break if a new field was added to Mezzanine's code.

--
You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Stephen McDonald
http://jupo.org

Alexandre Busquets Triola

unread,
Jan 14, 2016, 9:53:44 AM1/14/16
to Mezzanine Users
Hi Alexander, 

I also need use recaptcha with mezzanine. Have you do it?



El diumenge, 20 desembre de 2015 19:54:30 UTC+1, Alexander Tyapkov va escriure:

Тяпков Александр

unread,
Jan 14, 2016, 1:26:19 PM1/14/16
to mezzani...@googlegroups.com
Yes, I have done it but not is the way I have expected. I didn't manage to register ReCaptcha field inside of Mezzanine.
Instead, I have created my own form in which I have included recaptcha field and afterwards used page_processors for every page where I needed recaptcha

Hope, this will help!

Best regards,
Alexander

--
You received this message because you are subscribed to a topic in the Google Groups "Mezzanine Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mezzanine-users/C9lyFkhV9wU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mezzanine-use...@googlegroups.com.
Message has been deleted
Message has been deleted
Message has been deleted

Alexandre Busquets Triola

unread,
Jan 15, 2016, 4:44:38 AM1/15/16
to Mezzanine Users
Well, it's easy, with django-recaptcha.

pip install django-recaptcha

and then in settings.py set

INSTALLED_APPS = (
...
    "captcha",
...
)

FORMS_EXTRA_FIELDS = (
    (100, "captcha.fields.ReCaptchaField", "ReCaptcha"),
)

RECAPTCHA_PUBLIC_KEY = ...
RECAPTCHA_PRIVATE_KEY = ...


Fins ara,
Alexandre


El dijous, 14 gener de 2016 19:26:19 UTC+1, Alexander Tyapkov va escriure:

Тяпков Александр

unread,
Jan 15, 2016, 7:57:06 AM1/15/16
to mezzani...@googlegroups.com
Thanks! I will try this approach later, but for me registering with EXTRA_FORM_FIELDS also didn't help. Probably your solution will help.

Alexandre Busquets Triola

unread,
Jan 15, 2016, 8:55:38 AM1/15/16
to Mezzanine Users
You have to add a ReCaptchaField to your page form.




El divendres, 15 gener de 2016 13:57:06 UTC+1, Alexander Tyapkov va escriure:

Dominique

unread,
May 24, 2017, 4:23:16 PM5/24/17
to Mezzanine Users
When using the FORMS_EXTRA_FIELDS technique, what is the recommended approach for keeping the captcha field/value from showing up in the form response emails?

Eduardo Rivas

unread,
May 24, 2017, 4:26:03 PM5/24/17
to mezzani...@googlegroups.com

My guess is you could check the field ID when looping in the email template. Somewhere around here: https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/forms/templates/email/form_response.html#L6-L11

You'll also need to edit the plain text version.

You received this message because you are subscribed to the Google Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mezzanine-use...@googlegroups.com.

Dominique

unread,
May 25, 2017, 10:26:56 AM5/25/17
to Mezzanine Users
Ok, that's what I did, though I had to check the label name which is not ideal since https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/forms/page_processors.py#L44:L45 doesn't pass the ID or field type. Being able to check the field type might be a good future enhancement.
Reply all
Reply to author
Forward
0 new messages