Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override signup view django-allauth

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?

like image 392
Santosh Ghimire Avatar asked Jan 04 '14 16:01

Santosh Ghimire


People also ask

What is AllAuth in Django?

django-allauth is an integrated set of Django applications dealing with account authentication, registration, management, and third-party (social) account authentication. It is one of the most popular authentication modules due to its ability to handle both local and social logins.


1 Answers

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.

like image 128
Laur Ivan Avatar answered Oct 06 '22 16:10

Laur Ivan