Question

With django-allauth, I am forcing a new user to fill out additional profile information on signup using a custom ACCOUNT_SIGNUP_FORM.

settings.py

ACCOUNT_SIGNUP_FORM_CLASS = 'profiles.signup.ProfileSignupForm'
SOCIALACCOUNT_AUTO_SIGNUP = False

This ProfileSignupForm is then rendered in a modified allauth/templates/socialaccount/signup.html template. This modified template renders the logo of the new user's company that is defined in the new user's session (I used an invitation link that first goes to a RedirectView, writes into the session, and then forwards to the new signup).

signup.html

<html>
  <body>
    <img src="{{ logo }}" />
    {% crispy form %}
  </body>
</html>

How can I pull the company logo from my session and pass it to my template without forking the repository and modifying the SignUp View?

That approach would look like this:

class SignupView(RedirectAuthenticatedUserMixin, CloseableSignupMixin, FormView):

    def dispatch(self, request, *args, **kwargs):
        ...
        self.company = request.session.get('company')
        ...

    def get_context_data(self, **kwargs):
        ...
        context['logo'] = company.logo
        ...
Was it helpful?

Solution

Either you can follow the above mentioned way to Inherit the View and Define custom url for Signup to use your view.

Or

you car directly access company logo in your template as:

{{ request.session.company.logo }}

This can be done because request is available as a context variable in Templates if rendered with RequestContext instance.

OTHER TIPS

you can inherit SignupView directly in your code instead of forking and modifying the original SignupView.

class MySignupView(SignupView):

    def dispatch(self, request, *args, **kwargs):
        ...
        self.company = request.session.get('company')
        ...
        return super(MySignupView, self).dispatch(request, *args, *kwargs)

    def get_context_data(self, **kwargs):
        context = super(MySignupView, self).get_context_data(**kwargs)
        context['logo'] = self.company.logo
        return context

Then using MysignupView.as_view() in the urls.py.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top