Commits

James Bennett committed 3f0e73a

Views should optionally accept a backend instance as an argument.

  • Participants
  • Parent commits d30002b

Comments (0)

Files changed (1)

File registration/views.py

 
 def activate(request,
              template_name='registration/activate.html',
-             extra_context=None,
+             extra_context=None, backend=get_backend(),
              **kwargs):
     """
     Activate a user's account.
 
     The actual activation of the account will be delegated to the
-    backend specified by the ``REGISTRATION_BACKEND`` setting; the
+    backend specified by the ``REGISTRATION_BACKEND`` setting
+    (although this can be overridden; see argument list below); the
     backend's ``activate()`` method will be called, passing any
     keyword arguments captured from the URL, and will be assumed to
     return a ``User`` if activation was successful, or a value which
     evaluates to ``False`` in boolean context if not.
 
     **Optional arguments**
-       
+
+    ``backend``
+        An instance of a registration backend. If specified, will be
+        used in place of the backend specified by the
+        ``REGISTRATION_BACKEND`` setting.
+
     ``extra_context``
         A dictionary of variables to add to the template context. Any
         callable object in this dictionary will be called to produce
     registration/activate.html or ``template_name`` keyword argument.
     
     """
-    backend = get_backend()
     account = backend.activate(request, **kwargs)
     if extra_context is None:
         extra_context = {}
 def register(request, success_url=None, form_class=None,
              disallowed_url='registration_disallowed',
              template_name='registration/registration_form.html',
-             extra_context=None):
+             extra_context=None, backend=get_backend()):
     """
     Allow a new user to register an account.
 
     The actual registration of the account will be delegated to the
-    backend specified by the ``REGISTRATION_BACKEND`` setting; it will
-    be used as follows:
+    backend specified by the ``REGISTRATION_BACKEND`` setting
+    (although this can be overridden; see argument list below); it
+    will be used as follows:
 
     1. The backend's ``registration_allowed()`` method will be called,
        passing the ``HttpRequest``, to determine whether registration
     
     **Optional arguments**
 
+    ``backend``
+        An instance of a registration backend. If specified, will be
+        used in place of the backend specified by the
+        ``REGISTRATION_BACKEND`` setting.
+
     ``disallowed_url``
         URL to redirect to if registration is not permitted for the
         current ``HttpRequest``. Must be a value which can legally be
     argument.
     
     """
-    backend = get_backend()
     if not backend.registration_allowed(request):
         return redirect(disallowed_url)
     if form_class is None: