Integrated set of Django applications addressing authentication, registration, account management as well as 3rd party (social) account authentication.
—
Core configuration management, utility functions, and foundational functionality for django-allauth. Provides settings management, username generation, URL building, form utilities, and version information.
Package version information and metadata.
VERSION: tuple = (65, 11, 1, "final", 0)
__version__: str = "65.11.1"
__title__: str = "django-allauth"
__author__: str = "Raymond Penners"
__license__: str = "MIT"Configuration management through Django settings with app-specific prefixes and dynamic property access.
class AppSettings:
"""Main configuration class for django-allauth settings."""
def __init__(self, prefix: str): ...
def _setting(self, name: str, dflt: Any) -> Any: ...
@property
def SITES_ENABLED(self) -> bool:
"""Check if Django sites framework is enabled."""
@property
def SOCIALACCOUNT_ENABLED(self) -> bool:
"""Check if social account functionality is enabled."""
@property
def SOCIALACCOUNT_ONLY(self) -> bool:
"""Check if only social authentication is enabled."""
@property
def MFA_ENABLED(self) -> bool:
"""Check if multi-factor authentication is enabled."""
@property
def USERSESSIONS_ENABLED(self) -> bool:
"""Check if user sessions management is enabled."""
@property
def HEADLESS_ENABLED(self) -> bool:
"""Check if headless API mode is enabled."""
@property
def HEADLESS_ONLY(self) -> bool:
"""Check if headless only mode is enabled."""
@property
def DEFAULT_AUTO_FIELD(self) -> Optional[str]:
"""Get default auto field setting."""
def get_setting(name: str, dflt: Any) -> Any:
"""
Get Django setting with support for custom getter functions.
Parameters:
- name: Setting name to retrieve
- dflt: Default value if setting not found
Returns:
Setting value or default
"""Utilities for generating unique usernames from various text sources with collision avoidance.
def generate_unique_username(txts: List[str], regex: Optional[str] = None) -> str:
"""
Generate a unique username from a list of text sources.
Parameters:
- txts: List of text sources to generate username from
- regex: Optional regex pattern for character filtering
Returns:
Unique username string
Raises:
NotImplementedError: If unable to find unique username
"""
def generate_username_candidates(basename: str) -> List[str]:
"""
Generate list of username candidates from a base name.
Parameters:
- basename: Base username to generate variations from
Returns:
List of username candidate strings
"""
def get_username_max_length() -> int:
"""
Get maximum username length from user model configuration.
Returns:
Maximum allowed username length
"""Utilities for building absolute URIs and extracting request parameters.
def build_absolute_uri(request: Optional[HttpRequest], location: str, protocol: Optional[str] = None) -> str:
"""
Build absolute URI with proper protocol handling.
Parameters:
- request: HTTP request object (can be None if sites enabled)
- location: URL location to make absolute
- protocol: Optional protocol override
Returns:
Absolute URI string
Raises:
ImproperlyConfigured: If request is None and sites not enabled
"""
def get_request_param(request: Optional[HttpRequest], param: str, default: Any = None) -> Any:
"""
Get parameter from request POST or GET data.
Parameters:
- request: HTTP request object
- param: Parameter name to retrieve
- default: Default value if parameter not found
Returns:
Parameter value or default
"""Form field ordering and form class resolution utilities.
def set_form_field_order(form: Form, field_order: Optional[List[str]]) -> None:
"""
Set the order of fields in a Django form.
Parameters:
- form: Django form instance
- field_order: List of field names in desired order
"""
def get_form_class(forms: Dict[str, Any], form_id: str, default_form: type) -> type:
"""
Get form class from forms dictionary with string import support.
Parameters:
- forms: Dictionary mapping form IDs to form classes or import paths
- form_id: Form identifier to look up
- default_form: Default form class if not found
Returns:
Form class
"""Dynamic importing of Python attributes and callables from string paths.
def import_attribute(path: str) -> Any:
"""
Import Python attribute from string path.
Parameters:
- path: Dotted path to attribute (e.g., 'module.submodule.ClassName')
Returns:
Imported attribute
"""
def import_callable(path_or_callable: Union[str, Callable]) -> Callable:
"""
Import callable from path or return if already callable.
Parameters:
- path_or_callable: String path to callable or callable object
Returns:
Callable object
"""from allauth import app_settings
# Check enabled features
if app_settings.SOCIALACCOUNT_ENABLED:
print("Social authentication is enabled")
if app_settings.MFA_ENABLED:
print("Multi-factor authentication is enabled")
# Custom setting getter
from allauth.utils import get_setting
custom_value = get_setting('ALLAUTH_CUSTOM_SETTING', 'default_value')from allauth.utils import generate_unique_username
# Generate username from multiple sources
sources = ['john.doe@example.com', 'John Doe', 'johndoe']
username = generate_unique_username(sources)
print(username) # e.g., 'johndoe' or 'johndoe123'
# With custom regex
username = generate_unique_username(sources, regex=r'[^a-z0-9]')from allauth.utils import build_absolute_uri
# Build absolute URI
uri = build_absolute_uri(request, '/accounts/login/')
print(uri) # e.g., 'https://example.com/accounts/login/'
# With protocol override
uri = build_absolute_uri(request, '/accounts/login/', protocol='https')Install with Tessl CLI
npx tessl i tessl/pypi-django-allauth