|
1 |
| -from typing import Any |
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import typing |
2 | 4 |
|
3 | 5 | from allauth.account.adapter import DefaultAccountAdapter
|
4 | 6 | from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
5 | 7 | from django.conf import settings
|
6 | 8 | from django.http import HttpRequest
|
7 | 9 |
|
| 10 | +if typing.TYPE_CHECKING: |
| 11 | + from allauth.socialaccount.models import SocialLogin |
| 12 | + from {{cookiecutter.project_slug}}.users.models import User |
| 13 | + |
8 | 14 |
|
9 | 15 | class AccountAdapter(DefaultAccountAdapter):
|
10 |
| - def is_open_for_signup(self, request: HttpRequest): |
| 16 | + def is_open_for_signup(self, request: HttpRequest) -> bool: |
11 | 17 | return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)
|
12 | 18 |
|
13 | 19 |
|
14 | 20 | class SocialAccountAdapter(DefaultSocialAccountAdapter):
|
15 |
| - def is_open_for_signup(self, request: HttpRequest, sociallogin: Any): |
| 21 | + def is_open_for_signup(self, request: HttpRequest, sociallogin: SocialLogin) -> bool: |
16 | 22 | return getattr(settings, "ACCOUNT_ALLOW_REGISTRATION", True)
|
17 | 23 |
|
18 |
| - def populate_user(self, request, sociallogin, data): |
| 24 | + def populate_user(self, request: HttpRequest, sociallogin: SocialLogin, data: dict[str, typing.Any]) -> User: |
19 | 25 | """
|
20 |
| - Populates user information from social provider info |
21 |
| - See: https://django-allauth.readthedocs.io/en/latest/advanced.html?highlight=populate_user#creating-and-populating-user-instances |
| 26 | + Populates user information from social provider info. |
| 27 | +
|
| 28 | + See: https://django-allauth.readthedocs.io/en/latest/advanced.html?#creating-and-populating-user-instances |
22 | 29 | """
|
23 | 30 | user = sociallogin.user
|
24 | 31 | if name := data.get("name"):
|
|
0 commit comments