Commits

bseverson  committed d4cc293

Update registration views to add new org_register view.

  • Participants
  • Parent commits 184b6f9

Comments (0)

Files changed (1)

File registration/views.py

     return render_to_response(template_name,
                               {'form': form},
                               context_instance=context)
+
+def org_register(request, backend, success_url=None, form_class=None,
+             disallowed_url='registration_disallowed',
+             template_name='registration/registration_form.html',
+             extra_context=None, *args, **kwargs):
+    """
+    Allow a new user to register an account, through being linked
+    by their company or organization.
+
+    Follows similar logic to previous register process, adds args
+    and kwargs to pass in the organization. Then pulls the organization
+    in to pass to context and ultimately to registration.
+    """
+    # get organization for landing page registration
+    org_slug = kwargs.get('org_slug', None)
+    from organizations.models import Organization
+    org = Organization.objects.get(slug=org_slug)
+
+    backend = get_backend(backend)
+    if not backend.registration_allowed(request):
+        return redirect(disallowed_url)
+    if form_class is None:
+        form_class = backend.get_form_class(request)
+
+    if request.method == 'POST':
+        form = form_class(data=request.POST, files=request.FILES)
+        if form.is_valid():
+            # ads org to new user registration backend
+            new_user = backend.register(request, org, **form.cleaned_data)
+            return redirect(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
+
+    # push org into context
+    context['org'] = org
+
+    return render_to_response(template_name,
+                              {'form': form},
+                              context_instance=context)