Adding captcha for comments

parent 5f069bcb
mezzanine-captcha
=================
Wat (not the one in Angkor)
---------------------------
Adds a Captcha field to Mezzanine's form builder.
Caveat
------
This is a hack which looks at the field types in your Mezzanine installation and infers
a safe-enough ID number to use. If, by any reason at all, you were to make apps like
this one, and get the IDs wrong, your forms will see weird side-effects.
A registry for custom fields in Mezzanine would be more worth-while!
Installation
------------
Running ``setup.py`` should install ``django-simplecaptcha``, which is required.
The application needs to be before ``mezzanine.forms`` in ``INSTALLED_APPS``.
I use it between the django and mezzanine ones::
'django.contrib.staticfiles',
'captcha', # \__ the new ones
'mezzacaptcha', # /
'mezzanine.boot',
You also need to configure ``urls.py`` in your Mezzanine app::
url("^captcha/", include('captcha.urls')), # Slap it in before the catch-all
url("^", include("mezzanine.urls")),
Run also migrations::
python manage.py migrate captcha
Usage
-----
Now you can create captchas for your forms in admin!
Include the following option on your settings.py in order to add a captcha
on the blog comments form.
COMMENT_FORM_CLASS = "mezzacaptcha.forms.CaptchaThreadedCommentForm"
For info on captcha configuration please see
https://django-simple-captcha.readthedocs.org/en/latest/index.html
License
-------
BSD. Whatever. Not gonna care too much.
from django import forms
from captcha.fields import CaptchaField
from mezzanine.generic.forms import ThreadedCommentForm
class CaptchaThreadedCommentForm(ThreadedCommentForm):
""" Adds a captcha field to the comment form in blog
"""
captcha = CaptchaField()
\ No newline at end of file
# vim: tabstop=4 expandtab autoindent shiftwidth=4 fileencoding=utf-8
from django.utils.translation import ugettext_lazy as _
from captcha import fields as captcha_fields
from mezzanine.forms import fields as mezzanine_fields
## Figure out what to register us as
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.CaptchaField
# EOF
from django import forms
from captcha.fields import CaptchaField
from mezzanine.generic.forms import ThreadedCommentForm
class CaptchaThreadedCommentForm(ThreadedCommentForm):
""" Adds a captcha field to the comment form in blog
"""
captcha = CaptchaField()
\ No newline at end of file
# vim: tabstop=4 expandtab autoindent shiftwidth=4 fileencoding=utf-8
from django.utils.translation import ugettext_lazy as _
from captcha import fields as captcha_fields
from mezzanine.forms import fields as mezzanine_fields
## Figure out what to register us as
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.CaptchaField
# EOF
Metadata-Version: 1.0
Name: mezzanine-captcha
Version: 0.0.5
Summary: Captcha field for Mezzanine. A hack which can break your fields if you're not careful.
Use with extreme care. Can screw up your field types if you have other apps like this.
Do not use unless you know what you're doing.
Home-page: https://github.com/mjtorn/mezzanine-captcha
Author: Markus Törnqvist
Author-email: mjt@fadconsulting.com
License: BSD
Description: UNKNOWN
Platform: UNKNOWN
README.rst
setup.py
mezzacaptcha/__init__.py
mezzacaptcha/forms.py
mezzacaptcha/models.py
mezzanine_captcha.egg-info/PKG-INFO
mezzanine_captcha.egg-info/SOURCES.txt
mezzanine_captcha.egg-info/dependency_links.txt
mezzanine_captcha.egg-info/not-zip-safe
mezzanine_captcha.egg-info/requires.txt
mezzanine_captcha.egg-info/top_level.txt
\ No newline at end of file
setuptools
django-simple-captcha>=0.3.4
mezzanine
# vim: tabstop=4 expandtab autoindent shiftwidth=4 fileencoding=utf-8
from setuptools import setup, find_packages
NAME = 'mezzanine-captcha'
VERSION = '0.0.5'
DESCR = """\
Captcha field for Mezzanine. A hack which can break your fields if you're not careful.
Use with extreme care. Can screw up your field types if you have other apps like this.
Do not use unless you know what you're doing.
"""
AUTHOR = 'Markus Törnqvist'
AUTHOR_EMAIL = 'mjt@fadconsulting.com'
URL = 'https://github.com/mjtorn/mezzanine-captcha'
setup(
name=NAME,
version=VERSION,
description=DESCR,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
url=URL,
license='BSD',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=['setuptools', 'django-simple-captcha>=0.3.4', 'mezzanine']
)
# EOF
......@@ -239,6 +239,8 @@ INSTALLED_APPS = (
"django.contrib.sites",
"django.contrib.sitemaps",
"django.contrib.staticfiles",
"captcha",
"mezzacaptcha",
"mezzanine.boot",
"mezzanine.conf",
"mezzanine.core",
......@@ -342,7 +344,7 @@ else:
RICHTEXT_FILTER_LEVEL = 3
BLOG_USE_FEATURED_IMAGE = True
COMMENT_FORM_CLASS = "mezzacaptcha.forms.CaptchaThreadedCommentForm"
SITE_TITLE = "Alice Climent-Pommeret"
SITE_TAGLINE = ""
......
......@@ -7,7 +7,6 @@ from django.views.i18n import set_language
from mezzanine.core.views import direct_to_template
from mezzanine.conf import settings
import mezzanine_pagedown.urls
#admin.autodiscover()
......@@ -19,6 +18,7 @@ urlpatterns = i18n_patterns(
# Change the admin prefix here to use an alternate URL for the
# admin interface, which would be marginally more secure.
url("^admin/", include(admin.site.urls)),
url("^captcha/", include('captcha.urls')),
url("^$", direct_to_template, {"template": "index.html"}, name="home"),
url("^pagedown/", include(mezzanine_pagedown.urls)),
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment