Commits

Nathaniel Tucker  committed 7cb0b26

Adding django-registration backend integration point.

  • Participants
  • Parent commits f54454c

Comments (0)

Files changed (4)

File recaptcha_form/registration_backend/__init__.py

+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

File recaptcha_form/registration_backend/forms.py

+from recaptcha_form.forms import RecaptchaForm
+from registration.forms import RegistrationForm
+
+
+class RecaptchaRegistrationForm(RecaptchaForm, RegistrationForm):
+    pass

File recaptcha_form/registration_backend/urls.py

+"""
+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')),
+                       )
       description='Recaptcha for Django Forms',
       author='SmileyChris',
       url='http://bitbucket.org/ntucker/django-recaptcha',
-      packages=['recaptcha_form'],
+      packages=['recaptcha_form', 'recaptcha_form.registration_backend'],
      )