Skip to content

Commit

Permalink
Add some type hints to the SocialAccountAdapter class
Browse files Browse the repository at this point in the history
  • Loading branch information
browniebroke committed Jun 27, 2023
1 parent 8e19164 commit 476d877
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
from typing import Any
from __future__ import annotations

import typing

from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from django.conf import settings
from django.http import HttpRequest

if typing.TYPE_CHECKING:
from allauth.socialaccount.models import SocialLogin
from {{cookiecutter.project_slug}}.users.models import User


class AccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request: HttpRequest):
def is_open_for_signup(self, request: HttpRequest) -> bool:
return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)


class SocialAccountAdapter(DefaultSocialAccountAdapter):
def is_open_for_signup(self, request: HttpRequest, sociallogin: Any):
def is_open_for_signup(self, request: HttpRequest, sociallogin: SocialLogin) -> bool:
return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)

def populate_user(self, request, sociallogin, data):
def populate_user(self, request: HttpRequest, sociallogin: SocialLogin, data: dict[str, typing.Any]) -> User:
"""
Populates user information from social provider info
See: https://django-allauth.readthedocs.io/en/latest/advanced.html?highlight=populate_user#creating-and-populating-user-instances
Populates user information from social provider info.
See: https://django-allauth.readthedocs.io/en/latest/advanced.html?#creating-and-populating-user-instances
"""
user = sociallogin.user
if name := data.get("name"):
Expand Down

0 comments on commit 476d877

Please sign in to comment.