12

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?

Santosh Ghimire
  • 3,087
  • 8
  • 35
  • 63
  • What version of django-allauth are you using? In their github page they say they transitioned to class-based views in version 0.9.0 (for login and signup views). – Paulo Almeida Jan 04 '14 at 17:09
  • I am using django-allauth 0.15.0 which uses class-based views. – Santosh Ghimire Jan 04 '14 at 17:21
  • @PauloAlmeida I don't know how the class-based views work exactly...so having difficulty in passing my data to the view. – Santosh Ghimire Jan 04 '14 at 18:02
  • 1
    I have the opposite problem, I don't know how django-allauth's views are implemented. Generally, in class-based views, you can use the [get_context_data method](https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-simple/), from the ContextMixin, to pass arbitrary variables to the template. I don't know if that works directly with django-allauth's views though. – Paulo Almeida Jan 04 '14 at 18:49

1 Answers1

11

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.

Laur Ivan
  • 4,117
  • 3
  • 38
  • 62