Skip to content

Commit

Permalink
Adding django-registration backend integration point.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed May 31, 2011
1 parent 3cf3b68 commit a05e4f5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
11 changes: 11 additions & 0 deletions recaptcha_form/registration_backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from registration.backends.default import DefaultBackend
from .forms import RecaptchaRegistrationForm


class RecaptchaBackend(DefaultBackend):
def get_form_class(self, request):
"""
Return the recaptcha form class used for user registration.
"""
return RecaptchaRegistrationForm
6 changes: 6 additions & 0 deletions recaptcha_form/registration_backend/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from recaptcha_form.forms import RecaptchaForm
from registration.forms import RegistrationForm


class RecaptchaRegistrationForm(RecaptchaForm, RegistrationForm):
pass
54 changes: 54 additions & 0 deletions recaptcha_form/registration_backend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
URLconf for registration and activation, using django-registration's
default backend.
If the default behavior of these views is acceptable to you, simply
use a line like this in your root URLconf to set up the default URLs
for registration::
(r'^accounts/', include('registration.backends.default.urls')),
This will also automatically set up the views in
``django.contrib.auth`` at sensible default locations.
If you'd like to customize the behavior (e.g., by passing extra
arguments to the various views) or split up the URLs, feel free to set
up your own URL patterns for these views instead.
"""


from django.conf.urls.defaults import *
from django.views.generic.simple import direct_to_template

from registration.views import activate
from registration.views import register


urlpatterns = patterns('',
url(r'^activate/complete/$',
direct_to_template,
{'template': 'registration/activation_complete.html'},
name='registration_activation_complete'),
# Activation keys get matched by \w+ instead of the more specific
# [a-fA-F0-9]{40} because a bad activation key should still get to the view;
# that way it can return a sensible "invalid key" message instead of a
# confusing 404.
url(r'^activate/(?P<activation_key>\w+)/$',
activate,
{'backend': 'recaptcha_form.registration_backend.RecaptchaBackend'},
name='registration_activate'),
url(r'^register/$',
register,
{'backend': 'recaptcha_form.registration_backend.RecaptchaBackend'},
name='registration_register'),
url(r'^register/complete/$',
direct_to_template,
{'template': 'registration/registration_complete.html'},
name='registration_complete'),
url(r'^register/closed/$',
direct_to_template,
{'template': 'registration/registration_closed.html'},
name='registration_disallowed'),
(r'', include('registration.auth_urls')),
)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
description='Recaptcha for Django Forms',
author='SmileyChris',
url='http://bitbucket.org/ntucker/django-recaptcha',
packages=['recaptcha_form'],
packages=['recaptcha_form', 'recaptcha_form.registration_backend'],
)

0 comments on commit a05e4f5

Please sign in to comment.