Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My custom adapter isn't used by django-allauth

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 ?

like image 711
bchhun Avatar asked Nov 16 '14 20:11

bchhun


1 Answers

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

like image 152
Kireeti K Avatar answered Sep 20 '22 17:09

Kireeti K