or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

account-management.mdcore-config.mdheadless-api.mdindex.mdmfa.mdsocial-authentication.mdtemplate-system.mduser-sessions.md

core-config.mddocs/

0

# Core Configuration and Utilities

1

2

Core configuration management, utility functions, and foundational functionality for django-allauth. Provides settings management, username generation, URL building, form utilities, and version information.

3

4

## Capabilities

5

6

### Version Information

7

8

Package version information and metadata.

9

10

```python { .api }

11

VERSION: tuple = (65, 11, 1, "final", 0)

12

__version__: str = "65.11.1"

13

__title__: str = "django-allauth"

14

__author__: str = "Raymond Penners"

15

__license__: str = "MIT"

16

```

17

18

### Settings Management

19

20

Configuration management through Django settings with app-specific prefixes and dynamic property access.

21

22

```python { .api }

23

class AppSettings:

24

"""Main configuration class for django-allauth settings."""

25

26

def __init__(self, prefix: str): ...

27

def _setting(self, name: str, dflt: Any) -> Any: ...

28

29

@property

30

def SITES_ENABLED(self) -> bool:

31

"""Check if Django sites framework is enabled."""

32

33

@property

34

def SOCIALACCOUNT_ENABLED(self) -> bool:

35

"""Check if social account functionality is enabled."""

36

37

@property

38

def SOCIALACCOUNT_ONLY(self) -> bool:

39

"""Check if only social authentication is enabled."""

40

41

@property

42

def MFA_ENABLED(self) -> bool:

43

"""Check if multi-factor authentication is enabled."""

44

45

@property

46

def USERSESSIONS_ENABLED(self) -> bool:

47

"""Check if user sessions management is enabled."""

48

49

@property

50

def HEADLESS_ENABLED(self) -> bool:

51

"""Check if headless API mode is enabled."""

52

53

@property

54

def HEADLESS_ONLY(self) -> bool:

55

"""Check if headless only mode is enabled."""

56

57

@property

58

def DEFAULT_AUTO_FIELD(self) -> Optional[str]:

59

"""Get default auto field setting."""

60

61

def get_setting(name: str, dflt: Any) -> Any:

62

"""

63

Get Django setting with support for custom getter functions.

64

65

Parameters:

66

- name: Setting name to retrieve

67

- dflt: Default value if setting not found

68

69

Returns:

70

Setting value or default

71

"""

72

```

73

74

### Username Generation

75

76

Utilities for generating unique usernames from various text sources with collision avoidance.

77

78

```python { .api }

79

def generate_unique_username(txts: List[str], regex: Optional[str] = None) -> str:

80

"""

81

Generate a unique username from a list of text sources.

82

83

Parameters:

84

- txts: List of text sources to generate username from

85

- regex: Optional regex pattern for character filtering

86

87

Returns:

88

Unique username string

89

90

Raises:

91

NotImplementedError: If unable to find unique username

92

"""

93

94

def generate_username_candidates(basename: str) -> List[str]:

95

"""

96

Generate list of username candidates from a base name.

97

98

Parameters:

99

- basename: Base username to generate variations from

100

101

Returns:

102

List of username candidate strings

103

"""

104

105

def get_username_max_length() -> int:

106

"""

107

Get maximum username length from user model configuration.

108

109

Returns:

110

Maximum allowed username length

111

"""

112

```

113

114

### URL and Request Utilities

115

116

Utilities for building absolute URIs and extracting request parameters.

117

118

```python { .api }

119

def build_absolute_uri(request: Optional[HttpRequest], location: str, protocol: Optional[str] = None) -> str:

120

"""

121

Build absolute URI with proper protocol handling.

122

123

Parameters:

124

- request: HTTP request object (can be None if sites enabled)

125

- location: URL location to make absolute

126

- protocol: Optional protocol override

127

128

Returns:

129

Absolute URI string

130

131

Raises:

132

ImproperlyConfigured: If request is None and sites not enabled

133

"""

134

135

def get_request_param(request: Optional[HttpRequest], param: str, default: Any = None) -> Any:

136

"""

137

Get parameter from request POST or GET data.

138

139

Parameters:

140

- request: HTTP request object

141

- param: Parameter name to retrieve

142

- default: Default value if parameter not found

143

144

Returns:

145

Parameter value or default

146

"""

147

```

148

149

### Form Utilities

150

151

Form field ordering and form class resolution utilities.

152

153

```python { .api }

154

def set_form_field_order(form: Form, field_order: Optional[List[str]]) -> None:

155

"""

156

Set the order of fields in a Django form.

157

158

Parameters:

159

- form: Django form instance

160

- field_order: List of field names in desired order

161

"""

162

163

def get_form_class(forms: Dict[str, Any], form_id: str, default_form: type) -> type:

164

"""

165

Get form class from forms dictionary with string import support.

166

167

Parameters:

168

- forms: Dictionary mapping form IDs to form classes or import paths

169

- form_id: Form identifier to look up

170

- default_form: Default form class if not found

171

172

Returns:

173

Form class

174

"""

175

```

176

177

### Import Utilities

178

179

Dynamic importing of Python attributes and callables from string paths.

180

181

```python { .api }

182

def import_attribute(path: str) -> Any:

183

"""

184

Import Python attribute from string path.

185

186

Parameters:

187

- path: Dotted path to attribute (e.g., 'module.submodule.ClassName')

188

189

Returns:

190

Imported attribute

191

"""

192

193

def import_callable(path_or_callable: Union[str, Callable]) -> Callable:

194

"""

195

Import callable from path or return if already callable.

196

197

Parameters:

198

- path_or_callable: String path to callable or callable object

199

200

Returns:

201

Callable object

202

"""

203

```

204

205

## Usage Examples

206

207

### Basic Settings Configuration

208

209

```python

210

from allauth import app_settings

211

212

# Check enabled features

213

if app_settings.SOCIALACCOUNT_ENABLED:

214

print("Social authentication is enabled")

215

216

if app_settings.MFA_ENABLED:

217

print("Multi-factor authentication is enabled")

218

219

# Custom setting getter

220

from allauth.utils import get_setting

221

222

custom_value = get_setting('ALLAUTH_CUSTOM_SETTING', 'default_value')

223

```

224

225

### Username Generation

226

227

```python

228

from allauth.utils import generate_unique_username

229

230

# Generate username from multiple sources

231

sources = ['john.doe@example.com', 'John Doe', 'johndoe']

232

username = generate_unique_username(sources)

233

print(username) # e.g., 'johndoe' or 'johndoe123'

234

235

# With custom regex

236

username = generate_unique_username(sources, regex=r'[^a-z0-9]')

237

```

238

239

### URL Building

240

241

```python

242

from allauth.utils import build_absolute_uri

243

244

# Build absolute URI

245

uri = build_absolute_uri(request, '/accounts/login/')

246

print(uri) # e.g., 'https://example.com/accounts/login/'

247

248

# With protocol override

249

uri = build_absolute_uri(request, '/accounts/login/', protocol='https')

250

```