10

I'm using django 1.6.5 and django-allauth 0.18.0 and the social login works as expected once we create the social app in the django's admin panel.

So, my next step was trying to change the module's behavior by using adapters.

It looked simple in the docs but somehow, I can't seem to make django-allauth use my custom adapters.

So here's my attempt of trying to pdb into my adapter's methods.

here's my folders/files structure:

.
├── manage.py
├── requirements.freeze
├── foo
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── foo_app
    ├── adapters.py
    ├── views.py
    ├── etc...

here's my foo/settings.py file:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sites',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'south',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'foo_app'
)
ACCOUNT_ADAPTER="foo_app.adapters.FooAppAccountAdapter"
SOCIALACCOUNT_ADAPTER="foo_app.adapters.FooAppSocialAccountAdapter"

And here's my foo_app/adapters.py file:

# -*- coding: utf-8 -*-

import pdb

from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter


class FooAppAccountAdapter(DefaultAccountAdapter):
    def save_user(self, request, user, form, commit=true):
        print "FooAppAccountAdapter.save_user"
        pdb.set_trace()
        return super(FooAppAccountAdapter, self).save_user(
            request, user, form, commit
        )


class FooAppSocialAccountAdapter(DefaultSocialAccountAdapter):
    def pre_social_login(self, request, sociallogin):
        print "FooAppSocialAccountAdapter.pre_social_login"
        pdb.set_trace()
        return super(FooAppSocialAccountAdapter, self).pre_social_login(
            request, sociallogin
        )

    def save_user(self, request, sociallogin, form=None):
        print "FooAppSocialAccountAdapter.save_user"
        pdb.set_trace()
        return super(FooAppSocialAccountAdapter, self).save_user(
            request, sociallogin, form
        )

None of my set_trace are working and I think I might just have forgot something in the settings but can't figure it out.

So what I am missing or doing wrong guys ?

bchhun
  • 18,116
  • 8
  • 28
  • 31

1 Answers1

6

You have to add ACCOUNT_ADAPTER = 'project.users.adapter.MyAccountAdapter' to the setting.py

for more details on customising the adapter class, check this link https://django-allauth.readthedocs.io/en/latest/advanced.html#custom-redirects

Kireeti K
  • 1,370
  • 1
  • 19
  • 32
  • 1
    In case this helps others. I followed instructions above but named my custom adapter file `account_adapter.py` which is seems to be reserved name so it was giving `ModuleNotFoundError`. I had to rename it to something else eg `my_account_adapter.py` and then this worked. – curtisp Nov 02 '19 at 16:19