Override signup view django-allauth

Santosh Ghimire picture Santosh Ghimire · Jan 4, 2014 · Viewed 9.8k times · Source

I am asking user to fill extra fields with custom form. And in one of the fields, I have to let user choose multiple hierarchical tags. For this, I need to pass the tags from a view to the template signup.html

from classes.Tags import Tags
from django.shortcuts import render_to_response
from allauth.socialaccount import views as signup_views

def signup_view(request):
    tags = Tags()
    parameters={}
    all_tags = tags.get_tags()
    parameters['all_tags'] = all_tags
    response = signup_views.signup(request)
    return response

And in urls.py, I added this line before the allauth urls include line.

url(r'^accounts/social/signup/', 'mainapp.signup_views.signup_view', name = 'account_signup'),
url(r'^accounts/', include('allauth.urls')),

What I need is that I need to add all_tags to the response so that I can access it from the template. How do I do that?

Answer

Laur Ivan picture Laur Ivan · Jan 6, 2014

This link has some details on using your own signup form. IMO, you can define your own form (eventually with a custom widget for the tags) and use it directly, without having to mess with the view.

Otherwise, @PauloAlmeida is correct. You could inherit a new class off SignupView with something like:

class MySignupView(SignupView):

    def get_context_data(self, **kwargs):
        ret = super(MySignupView, self).get_context_data(**kwargs)
        ret['all_tags'] = Tags.get_tags()

        return ret

I'd rather use the custom form approach as it won't mess up the urls.py.