Commits

Anonymous committed da42b2e

Experimental support for extra_context in registration/activation views

Comments (0)

Files changed (1)

registration/views.py

 from registration.models import RegistrationProfile
 
 
-def activate(request, activation_key, template_name='registration/activate.html'):
+def activate(request, activation_key,
+             template_name='registration/activate.html',
+             extra_context=None):
     """
     Activate a ``User``'s account, if their key is valid and hasn't
     expired.
         The number of days for which activation keys stay valid after
         registration.
     
+    Any values passed in the keyword argument ``extra_context`` (which
+    must be a dictionary) will be added to the context as well; any
+    values in ``extra_context`` which are callable will be called
+    prior to being added to the context.
+
     **Template:**
     
     registration/activate.html or ``template_name`` keyword argument.
     """
     activation_key = activation_key.lower() # Normalize before trying anything with it.
     account = RegistrationProfile.objects.activate_user(activation_key)
+    if extra_context is None:
+        extra_context = {}
+    context = RequestContext(request)
+    for key, value in extra_context.items():
+        context[key] = callable(value) and value() or value
     return render_to_response(template_name,
                               { 'account': account,
                                 'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS },
-                              context_instance=RequestContext(request))
+                              context_instance=context)
 
 
 def register(request, success_url='/accounts/register/complete/',
              form_class=RegistrationForm, profile_callback=None,
-             template_name='registration/registration_form.html'):
+             template_name='registration/registration_form.html',
+             extra_context=None):
     """
     Allow a new user to register an account.
     
     form
         The registration form.
     
+    Any values passed in the keyword argument ``extra_context`` (which
+    must be a dictionary) will be added to the context as well; any
+    values in ``extra_context`` which are callable will be called
+    prior to being added to the context.
+
     **Template:**
     
     registration/registration_form.html or ``template_name`` keyword
             return HttpResponseRedirect(success_url)
     else:
         form = form_class()
+    
+    if extra_context is None:
+        extra_context = {}
+    context = RequestContext(request)
+    for key, value in extra_context.items():
+        context[key] = callable(value) and value() or value
     return render_to_response(template_name,
                               { 'form': form },
-                              context_instance=RequestContext(request))
+                              context_instance=context)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.