django-cfg 1.1.73__py3-none-any.whl → 1.1.75__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_cfg/__init__.py +1 -1
- django_cfg/apps/accounts/managers/user_manager.py +2 -2
- django_cfg/core/config.py +1 -0
- django_cfg/management/commands/migrate_all.py +117 -0
- django_cfg/middleware/README.md +158 -0
- django_cfg/middleware/__init__.py +2 -0
- django_cfg/middleware/public_endpoints.py +182 -0
- {django_cfg-1.1.73.dist-info → django_cfg-1.1.75.dist-info}/METADATA +44 -7
- {django_cfg-1.1.73.dist-info → django_cfg-1.1.75.dist-info}/RECORD +12 -10
- {django_cfg-1.1.73.dist-info → django_cfg-1.1.75.dist-info}/WHEEL +0 -0
- {django_cfg-1.1.73.dist-info → django_cfg-1.1.75.dist-info}/entry_points.txt +0 -0
- {django_cfg-1.1.73.dist-info → django_cfg-1.1.75.dist-info}/licenses/LICENSE +0 -0
django_cfg/__init__.py
CHANGED
@@ -38,7 +38,7 @@ default_app_config = "django_cfg.apps.DjangoCfgConfig"
|
|
38
38
|
from typing import TYPE_CHECKING
|
39
39
|
|
40
40
|
# Version information
|
41
|
-
__version__ = "1.1.
|
41
|
+
__version__ = "1.1.75"
|
42
42
|
__author__ = "Unrealos Team"
|
43
43
|
__email__ = "info@unrealos.com"
|
44
44
|
__license__ = "MIT"
|
@@ -83,8 +83,8 @@ class UserManager(UserManager):
|
|
83
83
|
f"Attempting to get_or_create user with email: {email}, username: {username}"
|
84
84
|
)
|
85
85
|
|
86
|
-
# Create or get user using self
|
87
|
-
user, created = self.
|
86
|
+
# Create or get user using self (the manager)
|
87
|
+
user, created = self.get_or_create(
|
88
88
|
email=email, defaults=defaults
|
89
89
|
)
|
90
90
|
|
django_cfg/core/config.py
CHANGED
@@ -633,6 +633,7 @@ class DjangoConfig(BaseModel):
|
|
633
633
|
"django.contrib.sessions.middleware.SessionMiddleware",
|
634
634
|
"django.middleware.common.CommonMiddleware",
|
635
635
|
"django.middleware.csrf.CsrfViewMiddleware",
|
636
|
+
"django_cfg.middleware.PublicEndpointsMiddleware", # Handle invalid JWT tokens on public endpoints
|
636
637
|
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
637
638
|
"django.contrib.messages.middleware.MessageMiddleware",
|
638
639
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
@@ -0,0 +1,117 @@
|
|
1
|
+
"""
|
2
|
+
Simple Migration Command for Django Config Toolkit
|
3
|
+
Migrate all databases based on django-cfg configuration.
|
4
|
+
"""
|
5
|
+
|
6
|
+
from django.core.management.base import BaseCommand
|
7
|
+
from django.core.management import call_command
|
8
|
+
from django.apps import apps
|
9
|
+
|
10
|
+
from django_cfg.core.config import get_current_config
|
11
|
+
|
12
|
+
|
13
|
+
class Command(BaseCommand):
|
14
|
+
help = "Migrate all databases based on django-cfg configuration"
|
15
|
+
|
16
|
+
def add_arguments(self, parser):
|
17
|
+
parser.add_argument(
|
18
|
+
"--dry-run",
|
19
|
+
action="store_true",
|
20
|
+
help="Show what would be migrated without executing"
|
21
|
+
)
|
22
|
+
parser.add_argument(
|
23
|
+
"--skip-makemigrations",
|
24
|
+
action="store_true",
|
25
|
+
help="Skip makemigrations step"
|
26
|
+
)
|
27
|
+
|
28
|
+
def handle(self, *args, **options):
|
29
|
+
"""Run migrations for all configured databases."""
|
30
|
+
dry_run = options.get("dry_run", False)
|
31
|
+
skip_makemigrations = options.get("skip_makemigrations", False)
|
32
|
+
|
33
|
+
if dry_run:
|
34
|
+
self.stdout.write(self.style.WARNING("🔍 DRY RUN - No changes will be made"))
|
35
|
+
|
36
|
+
self.stdout.write(self.style.SUCCESS("🚀 Migrating all databases..."))
|
37
|
+
|
38
|
+
# Step 1: Create migrations if needed
|
39
|
+
if not skip_makemigrations:
|
40
|
+
self.stdout.write("📝 Creating migrations...")
|
41
|
+
if not dry_run:
|
42
|
+
call_command("makemigrations", verbosity=1)
|
43
|
+
else:
|
44
|
+
self.stdout.write(" Would run: makemigrations")
|
45
|
+
|
46
|
+
# Step 2: Get database configuration
|
47
|
+
try:
|
48
|
+
config = get_current_config()
|
49
|
+
if not config or not hasattr(config, 'databases'):
|
50
|
+
self.stdout.write(self.style.ERROR("❌ No django-cfg configuration found"))
|
51
|
+
return
|
52
|
+
except Exception as e:
|
53
|
+
self.stdout.write(self.style.ERROR(f"❌ Error loading configuration: {e}"))
|
54
|
+
return
|
55
|
+
|
56
|
+
# Step 3: Migrate each database
|
57
|
+
for db_name, db_config in config.databases.items():
|
58
|
+
self.stdout.write(f"\n🔄 Migrating database: {db_name}")
|
59
|
+
|
60
|
+
if hasattr(db_config, 'apps') and db_config.apps:
|
61
|
+
# Migrate specific apps for this database
|
62
|
+
for app_path in db_config.apps:
|
63
|
+
app_label = self._get_app_label(app_path)
|
64
|
+
if app_label:
|
65
|
+
self.stdout.write(f" 📦 Migrating {app_label}...")
|
66
|
+
if not dry_run:
|
67
|
+
try:
|
68
|
+
call_command("migrate", app_label, database=db_name, verbosity=1)
|
69
|
+
except Exception as e:
|
70
|
+
self.stdout.write(self.style.WARNING(f" ⚠️ Warning: {e}"))
|
71
|
+
else:
|
72
|
+
self.stdout.write(f" Would run: migrate {app_label} --database={db_name}")
|
73
|
+
else:
|
74
|
+
# Migrate all apps for this database (usually default)
|
75
|
+
self.stdout.write(f" 📦 Migrating all apps...")
|
76
|
+
if not dry_run:
|
77
|
+
try:
|
78
|
+
call_command("migrate", database=db_name, verbosity=1)
|
79
|
+
except Exception as e:
|
80
|
+
self.stdout.write(self.style.WARNING(f" ⚠️ Warning: {e}"))
|
81
|
+
else:
|
82
|
+
self.stdout.write(f" Would run: migrate --database={db_name}")
|
83
|
+
|
84
|
+
# Step 4: Migrate constance if needed
|
85
|
+
self.stdout.write(f"\n🔧 Migrating constance...")
|
86
|
+
if not dry_run:
|
87
|
+
try:
|
88
|
+
call_command("migrate", "constance", database="default", verbosity=1)
|
89
|
+
except Exception as e:
|
90
|
+
self.stdout.write(self.style.WARNING(f"⚠️ Constance warning: {e}"))
|
91
|
+
else:
|
92
|
+
self.stdout.write(" Would run: migrate constance --database=default")
|
93
|
+
|
94
|
+
self.stdout.write(self.style.SUCCESS("\n✅ All migrations completed!"))
|
95
|
+
|
96
|
+
def _get_app_label(self, app_path: str) -> str:
|
97
|
+
"""Convert full module path to Django app_label."""
|
98
|
+
try:
|
99
|
+
# Try to get app config by full path first
|
100
|
+
try:
|
101
|
+
app_config = apps.get_app_config(app_path)
|
102
|
+
return app_config.label
|
103
|
+
except LookupError:
|
104
|
+
pass
|
105
|
+
|
106
|
+
# Fallback: extract last part of the path as potential app_label
|
107
|
+
potential_label = app_path.split('.')[-1]
|
108
|
+
try:
|
109
|
+
app_config = apps.get_app_config(potential_label)
|
110
|
+
return app_config.label
|
111
|
+
except LookupError:
|
112
|
+
pass
|
113
|
+
|
114
|
+
return app_path
|
115
|
+
|
116
|
+
except Exception:
|
117
|
+
return app_path
|
django_cfg/middleware/README.md
CHANGED
@@ -5,6 +5,7 @@ Custom Django middleware components for Django CFG applications.
|
|
5
5
|
## 📋 Contents
|
6
6
|
|
7
7
|
- [UserActivityMiddleware](#useractivitymiddleware) - User activity tracking
|
8
|
+
- [PublicEndpointsMiddleware](#publicendpointsmiddleware) - Ignore invalid JWT tokens on public endpoints
|
8
9
|
|
9
10
|
## UserActivityMiddleware
|
10
11
|
|
@@ -158,3 +159,160 @@ class MyProjectConfig(DjangoConfig):
|
|
158
159
|
# GET /api/users/?format=json
|
159
160
|
# PUT /cfg/newsletter/subscribe/
|
160
161
|
```
|
162
|
+
|
163
|
+
## PublicEndpointsMiddleware
|
164
|
+
|
165
|
+
Middleware that temporarily removes invalid JWT tokens from public endpoints to prevent authentication errors.
|
166
|
+
|
167
|
+
### ✨ Features
|
168
|
+
|
169
|
+
- ✅ **Automatic activation** - No configuration needed, works out of the box
|
170
|
+
- ✅ **Smart endpoint detection** - Configurable regex patterns for public endpoints
|
171
|
+
- ✅ **JWT token detection** - Only processes requests with Bearer tokens
|
172
|
+
- ✅ **Temporary removal** - Auth headers are restored after request processing
|
173
|
+
- ✅ **Performance optimized** - Compiled regex patterns for fast matching
|
174
|
+
- ✅ **Detailed logging** - Debug information for troubleshooting
|
175
|
+
- ✅ **Statistics tracking** - Monitor middleware usage and effectiveness
|
176
|
+
|
177
|
+
### 🎯 Problem Solved
|
178
|
+
|
179
|
+
When a frontend sends an invalid/expired JWT token to a public endpoint (like OTP request), Django's authentication middleware tries to authenticate the user and fails with "User not found" errors, even though the endpoint has `AllowAny` permissions.
|
180
|
+
|
181
|
+
This middleware temporarily removes the `Authorization` header for public endpoints, allowing them to work without authentication errors.
|
182
|
+
|
183
|
+
### 🚀 Automatic Integration
|
184
|
+
|
185
|
+
The middleware is **automatically included** in all Django CFG projects:
|
186
|
+
|
187
|
+
```python
|
188
|
+
class MyConfig(DjangoConfig):
|
189
|
+
# No configuration needed - PublicEndpointsMiddleware is always active
|
190
|
+
pass
|
191
|
+
```
|
192
|
+
|
193
|
+
### 🎯 Default Public Endpoints
|
194
|
+
|
195
|
+
The middleware protects these endpoints by default:
|
196
|
+
|
197
|
+
```python
|
198
|
+
DEFAULT_PUBLIC_PATTERNS = [
|
199
|
+
r'^/api/accounts/otp/', # OTP endpoints (request, verify)
|
200
|
+
r'^/cfg/accounts/otp/', # CFG OTP endpoints
|
201
|
+
r'^/api/accounts/token/refresh/', # Token refresh
|
202
|
+
r'^/cfg/accounts/token/refresh/', # CFG Token refresh
|
203
|
+
r'^/api/health/', # Health check endpoints
|
204
|
+
r'^/cfg/api/health/', # CFG Health check endpoints
|
205
|
+
r'^/admin/login/', # Django admin login
|
206
|
+
r'^/api/schema/', # API schema endpoints
|
207
|
+
r'^/api/docs/', # API documentation
|
208
|
+
]
|
209
|
+
```
|
210
|
+
|
211
|
+
### ⚙️ Custom Configuration
|
212
|
+
|
213
|
+
You can customize public endpoint patterns in your Django settings:
|
214
|
+
|
215
|
+
```python
|
216
|
+
# settings.py (optional)
|
217
|
+
PUBLIC_ENDPOINT_PATTERNS = [
|
218
|
+
r'^/api/accounts/otp/',
|
219
|
+
r'^/api/public/',
|
220
|
+
r'^/api/webhooks/',
|
221
|
+
# Add your custom patterns here
|
222
|
+
]
|
223
|
+
```
|
224
|
+
|
225
|
+
### 🔍 How It Works
|
226
|
+
|
227
|
+
1. **Request Processing**: Middleware checks if the request path matches public endpoint patterns
|
228
|
+
2. **Token Detection**: If a Bearer token is present, it's temporarily removed
|
229
|
+
3. **Request Handling**: Django processes the request without authentication
|
230
|
+
4. **Token Restoration**: The original Authorization header is restored after processing
|
231
|
+
|
232
|
+
### 📊 Statistics
|
233
|
+
|
234
|
+
Get middleware statistics for monitoring:
|
235
|
+
|
236
|
+
```python
|
237
|
+
from django_cfg.middleware import PublicEndpointsMiddleware
|
238
|
+
|
239
|
+
# In your view or management command
|
240
|
+
middleware = PublicEndpointsMiddleware()
|
241
|
+
stats = middleware.get_stats()
|
242
|
+
|
243
|
+
print(stats)
|
244
|
+
# {
|
245
|
+
# 'requests_processed': 1250,
|
246
|
+
# 'tokens_ignored': 45,
|
247
|
+
# 'public_endpoints_hit': 120,
|
248
|
+
# 'public_patterns_count': 9,
|
249
|
+
# 'middleware_active': True
|
250
|
+
# }
|
251
|
+
```
|
252
|
+
|
253
|
+
### 🔍 Logging
|
254
|
+
|
255
|
+
The middleware logs activity at DEBUG level:
|
256
|
+
|
257
|
+
```python
|
258
|
+
# settings.py
|
259
|
+
LOGGING = {
|
260
|
+
'loggers': {
|
261
|
+
'django_cfg.middleware.public_endpoints': {
|
262
|
+
'level': 'DEBUG',
|
263
|
+
'handlers': ['console'],
|
264
|
+
},
|
265
|
+
},
|
266
|
+
}
|
267
|
+
```
|
268
|
+
|
269
|
+
### 🎛️ Manual Integration
|
270
|
+
|
271
|
+
If you need to include the middleware manually (not recommended):
|
272
|
+
|
273
|
+
```python
|
274
|
+
# settings.py
|
275
|
+
MIDDLEWARE = [
|
276
|
+
'django.middleware.security.SecurityMiddleware',
|
277
|
+
'corsheaders.middleware.CorsMiddleware',
|
278
|
+
'django_cfg.middleware.PublicEndpointsMiddleware', # Add early in stack
|
279
|
+
# ... other middleware
|
280
|
+
]
|
281
|
+
```
|
282
|
+
|
283
|
+
### 🚨 Important Notes
|
284
|
+
|
285
|
+
1. **Always Active**: Middleware is included by default in all Django CFG projects
|
286
|
+
2. **Performance**: Uses compiled regex patterns for fast endpoint matching
|
287
|
+
3. **Safety**: Only removes Authorization headers temporarily, restores them after processing
|
288
|
+
4. **Logging**: All actions are logged for debugging and monitoring
|
289
|
+
|
290
|
+
### 💡 Usage Examples
|
291
|
+
|
292
|
+
The middleware works automatically with no configuration needed:
|
293
|
+
|
294
|
+
```python
|
295
|
+
# Your DjangoConfig
|
296
|
+
class MyProjectConfig(DjangoConfig):
|
297
|
+
# PublicEndpointsMiddleware is automatically active
|
298
|
+
pass
|
299
|
+
|
300
|
+
# These requests will work even with invalid tokens:
|
301
|
+
# POST /api/accounts/otp/request/ (with expired Bearer token)
|
302
|
+
# POST /cfg/accounts/otp/verify/ (with invalid Bearer token)
|
303
|
+
# GET /api/health/ (with any Bearer token)
|
304
|
+
```
|
305
|
+
|
306
|
+
### 🔧 Frontend Integration
|
307
|
+
|
308
|
+
Perfect companion to frontend error handling:
|
309
|
+
|
310
|
+
```typescript
|
311
|
+
// Frontend automatically clears invalid tokens on 401/403
|
312
|
+
// Middleware ensures public endpoints work during token cleanup
|
313
|
+
const response = await api.requestOTP({
|
314
|
+
identifier: "user@example.com",
|
315
|
+
channel: "email"
|
316
|
+
});
|
317
|
+
// ✅ Works even if localStorage has invalid token
|
318
|
+
```
|
@@ -0,0 +1,182 @@
|
|
1
|
+
"""
|
2
|
+
Public Endpoints Middleware
|
3
|
+
|
4
|
+
Middleware that ignores invalid JWT tokens on public endpoints to prevent
|
5
|
+
authentication errors on endpoints with AllowAny permissions.
|
6
|
+
"""
|
7
|
+
|
8
|
+
import logging
|
9
|
+
import re
|
10
|
+
from typing import List, Optional, Set
|
11
|
+
from django.http import HttpRequest, HttpResponse
|
12
|
+
from django.utils.deprecation import MiddlewareMixin
|
13
|
+
|
14
|
+
logger = logging.getLogger(__name__)
|
15
|
+
|
16
|
+
|
17
|
+
class PublicEndpointsMiddleware(MiddlewareMixin):
|
18
|
+
"""
|
19
|
+
Middleware that temporarily removes Authorization headers for public endpoints.
|
20
|
+
|
21
|
+
This prevents Django from trying to authenticate invalid JWT tokens on endpoints
|
22
|
+
that have AllowAny permissions, which can cause "User not found" errors.
|
23
|
+
|
24
|
+
Features:
|
25
|
+
- ✅ Configurable public endpoint patterns
|
26
|
+
- ✅ Smart JWT token detection
|
27
|
+
- ✅ Automatic restoration of headers after processing
|
28
|
+
- ✅ Detailed logging for debugging
|
29
|
+
- ✅ Performance optimized with compiled regex patterns
|
30
|
+
"""
|
31
|
+
|
32
|
+
# Default public endpoint patterns
|
33
|
+
DEFAULT_PUBLIC_PATTERNS = [
|
34
|
+
r'^/api/accounts/otp/', # OTP endpoints (request, verify)
|
35
|
+
r'^/cfg/accounts/otp/', # CFG OTP endpoints
|
36
|
+
r'^/api/accounts/token/refresh/', # Token refresh
|
37
|
+
r'^/cfg/accounts/token/refresh/', # CFG Token refresh
|
38
|
+
r'^/api/health/', # Health check endpoints
|
39
|
+
r'^/cfg/api/health/', # CFG Health check endpoints
|
40
|
+
r'^/admin/login/', # Django admin login
|
41
|
+
r'^/api/schema/', # API schema endpoints
|
42
|
+
r'^/api/docs/', # API documentation
|
43
|
+
]
|
44
|
+
|
45
|
+
def __init__(self, get_response=None):
|
46
|
+
super().__init__(get_response)
|
47
|
+
self.public_patterns: List[re.Pattern] = []
|
48
|
+
self.stats = {
|
49
|
+
'requests_processed': 0,
|
50
|
+
'tokens_ignored': 0,
|
51
|
+
'public_endpoints_hit': 0,
|
52
|
+
}
|
53
|
+
self._compile_patterns()
|
54
|
+
|
55
|
+
def _compile_patterns(self):
|
56
|
+
"""Compile regex patterns for better performance."""
|
57
|
+
patterns = self._get_public_patterns()
|
58
|
+
self.public_patterns = [re.compile(pattern) for pattern in patterns]
|
59
|
+
logger.debug(f"Compiled {len(self.public_patterns)} public endpoint patterns")
|
60
|
+
|
61
|
+
def _get_public_patterns(self) -> List[str]:
|
62
|
+
"""Get public endpoint patterns from Django settings or use defaults."""
|
63
|
+
from django.conf import settings
|
64
|
+
|
65
|
+
# Try to get patterns from settings
|
66
|
+
custom_patterns = getattr(settings, 'PUBLIC_ENDPOINT_PATTERNS', None)
|
67
|
+
if custom_patterns:
|
68
|
+
logger.debug(f"Using custom public patterns: {len(custom_patterns)} patterns")
|
69
|
+
return custom_patterns
|
70
|
+
|
71
|
+
# Use defaults
|
72
|
+
logger.debug(f"Using default public patterns: {len(self.DEFAULT_PUBLIC_PATTERNS)} patterns")
|
73
|
+
return self.DEFAULT_PUBLIC_PATTERNS
|
74
|
+
|
75
|
+
def _is_public_endpoint(self, path: str) -> bool:
|
76
|
+
"""Check if the request path matches any public endpoint pattern."""
|
77
|
+
for pattern in self.public_patterns:
|
78
|
+
if pattern.match(path):
|
79
|
+
return True
|
80
|
+
return False
|
81
|
+
|
82
|
+
def _has_jwt_token(self, request: HttpRequest) -> bool:
|
83
|
+
"""Check if request has a JWT Authorization header."""
|
84
|
+
auth_header = request.META.get('HTTP_AUTHORIZATION', '')
|
85
|
+
return auth_header.startswith('Bearer ')
|
86
|
+
|
87
|
+
def _extract_auth_header(self, request: HttpRequest) -> Optional[str]:
|
88
|
+
"""Extract and remove Authorization header from request."""
|
89
|
+
return request.META.pop('HTTP_AUTHORIZATION', None)
|
90
|
+
|
91
|
+
def _restore_auth_header(self, request: HttpRequest, auth_header: str):
|
92
|
+
"""Restore Authorization header to request."""
|
93
|
+
if auth_header:
|
94
|
+
request.META['HTTP_AUTHORIZATION'] = auth_header
|
95
|
+
|
96
|
+
def process_request(self, request: HttpRequest) -> Optional[HttpResponse]:
|
97
|
+
"""
|
98
|
+
Process incoming request and temporarily remove auth header for public endpoints.
|
99
|
+
"""
|
100
|
+
self.stats['requests_processed'] += 1
|
101
|
+
|
102
|
+
# Check if this is a public endpoint
|
103
|
+
if not self._is_public_endpoint(request.path):
|
104
|
+
return None
|
105
|
+
|
106
|
+
self.stats['public_endpoints_hit'] += 1
|
107
|
+
|
108
|
+
# Check if request has JWT token
|
109
|
+
if not self._has_jwt_token(request):
|
110
|
+
return None
|
111
|
+
|
112
|
+
# Store the auth header and remove it temporarily
|
113
|
+
auth_header = self._extract_auth_header(request)
|
114
|
+
if auth_header:
|
115
|
+
self.stats['tokens_ignored'] += 1
|
116
|
+
# Store in request for restoration later
|
117
|
+
request._original_auth_header = auth_header
|
118
|
+
|
119
|
+
logger.debug(
|
120
|
+
f"Temporarily removed auth header for public endpoint: {request.path}",
|
121
|
+
extra={
|
122
|
+
'path': request.path,
|
123
|
+
'method': request.method,
|
124
|
+
'has_token': bool(auth_header),
|
125
|
+
}
|
126
|
+
)
|
127
|
+
|
128
|
+
return None
|
129
|
+
|
130
|
+
def process_response(self, request: HttpRequest, response: HttpResponse) -> HttpResponse:
|
131
|
+
"""
|
132
|
+
Restore Authorization header after request processing.
|
133
|
+
"""
|
134
|
+
# Restore auth header if it was temporarily removed
|
135
|
+
if hasattr(request, '_original_auth_header'):
|
136
|
+
self._restore_auth_header(request, request._original_auth_header)
|
137
|
+
delattr(request, '_original_auth_header')
|
138
|
+
|
139
|
+
logger.debug(
|
140
|
+
f"Restored auth header for public endpoint: {request.path}",
|
141
|
+
extra={
|
142
|
+
'path': request.path,
|
143
|
+
'status_code': response.status_code,
|
144
|
+
}
|
145
|
+
)
|
146
|
+
|
147
|
+
return response
|
148
|
+
|
149
|
+
def get_stats(self) -> dict:
|
150
|
+
"""Get middleware statistics."""
|
151
|
+
return {
|
152
|
+
**self.stats,
|
153
|
+
'public_patterns_count': len(self.public_patterns),
|
154
|
+
'middleware_active': True,
|
155
|
+
}
|
156
|
+
|
157
|
+
def reset_stats(self):
|
158
|
+
"""Reset middleware statistics."""
|
159
|
+
self.stats = {
|
160
|
+
'requests_processed': 0,
|
161
|
+
'tokens_ignored': 0,
|
162
|
+
'public_endpoints_hit': 0,
|
163
|
+
}
|
164
|
+
logger.info("PublicEndpointsMiddleware stats reset")
|
165
|
+
|
166
|
+
|
167
|
+
# Convenience function for getting middleware stats
|
168
|
+
def get_public_endpoints_stats() -> dict:
|
169
|
+
"""Get statistics from PublicEndpointsMiddleware if available."""
|
170
|
+
try:
|
171
|
+
# This would need to be implemented if we want global stats access
|
172
|
+
# For now, return basic info
|
173
|
+
return {
|
174
|
+
'middleware_available': True,
|
175
|
+
'note': 'Use middleware.get_stats() method for detailed statistics'
|
176
|
+
}
|
177
|
+
except Exception as e:
|
178
|
+
logger.error(f"Error getting public endpoints stats: {e}")
|
179
|
+
return {
|
180
|
+
'middleware_available': False,
|
181
|
+
'error': str(e)
|
182
|
+
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: django-cfg
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.75
|
4
4
|
Summary: 🚀 Production-ready Django configuration framework with type-safe settings, smart automation, and modern developer experience
|
5
5
|
Project-URL: Homepage, https://github.com/markolofsen/django-cfg
|
6
6
|
Project-URL: Documentation, https://django-cfg.readthedocs.io
|
@@ -552,31 +552,68 @@ def queue_document_processing(sender, instance, created, **kwargs):
|
|
552
552
|
|
553
553
|
Django-CFG includes powerful management commands for development and operations:
|
554
554
|
|
555
|
+
### 🗄️ Database & Migration Commands
|
556
|
+
| Command | Description | Example |
|
557
|
+
|---------|-------------|---------|
|
558
|
+
| **`migrator`** | Interactive database migration tool with multi-DB support | `python manage.py migrator --auto` |
|
559
|
+
| **`migrate_all`** | Simple migration command for all databases (production-ready) | `python manage.py migrate_all --dry-run` |
|
560
|
+
|
561
|
+
**Migration Command Details:**
|
562
|
+
- **`migrator`** - Full-featured migration tool with interactive menu, database status, and diagnostics
|
563
|
+
- `python manage.py migrator` - Interactive menu with all options
|
564
|
+
- `python manage.py migrator --auto` - Automatic migration of all databases
|
565
|
+
- `python manage.py migrator --database vehicles` - Migrate specific database only
|
566
|
+
- `python manage.py migrator --app vehicles_data` - Migrate specific app across all databases
|
567
|
+
- **`migrate_all`** - Simplified migration tool optimized for production and CI/CD
|
568
|
+
- `python manage.py migrate_all` - Migrate all databases automatically
|
569
|
+
- `python manage.py migrate_all --dry-run` - Show what would be migrated without executing
|
570
|
+
- `python manage.py migrate_all --skip-makemigrations` - Skip makemigrations step
|
571
|
+
|
572
|
+
### 🔧 Configuration & Validation Commands
|
555
573
|
| Command | Description | Example |
|
556
574
|
|---------|-------------|---------|
|
557
575
|
| **`check_settings`** | Validate configuration and settings | `python manage.py check_settings` |
|
576
|
+
| **`show_config`** | Display current configuration | `python manage.py show_config --format yaml` |
|
577
|
+
| **`validate_config`** | Deep validation of all settings | `python manage.py validate_config --strict` |
|
578
|
+
| **`tree`** | Display Django project structure | `python manage.py tree --depth 3 --include-docs` |
|
579
|
+
|
580
|
+
### 🚀 API & Development Commands
|
581
|
+
| Command | Description | Example |
|
582
|
+
|---------|-------------|---------|
|
558
583
|
| **`create_token`** | Generate API tokens and keys | `python manage.py create_token --user admin` |
|
559
584
|
| **`generate`** | Generate API clients and documentation | `python manage.py generate --zone client` |
|
560
|
-
| **`migrator`** | Smart database migrations with routing | `python manage.py migrator --apps blog,shop` |
|
561
|
-
| **`script`** | Run custom scripts with Django context | `python manage.py script my_script.py` |
|
562
|
-
| **`show_config`** | Display current configuration | `python manage.py show_config --format yaml` |
|
563
585
|
| **`show_urls`** | Display all URL patterns | `python manage.py show_urls --zone client` |
|
586
|
+
| **`script`** | Run custom scripts with Django context | `python manage.py script my_script.py` |
|
587
|
+
| **`runserver_ngrok`** | Run development server with ngrok tunnel | `python manage.py runserver_ngrok --domain custom` |
|
588
|
+
|
589
|
+
### 👤 User & Authentication Commands
|
590
|
+
| Command | Description | Example |
|
591
|
+
|---------|-------------|---------|
|
564
592
|
| **`superuser`** | Create superuser with smart defaults | `python manage.py superuser --email admin@example.com` |
|
593
|
+
|
594
|
+
### 📧 Communication & Integration Commands
|
595
|
+
| Command | Description | Example |
|
596
|
+
|---------|-------------|---------|
|
565
597
|
| **`test_email`** | Test email configuration | `python manage.py test_email --to test@example.com` |
|
566
598
|
| **`test_telegram`** | Test Telegram bot integration | `python manage.py test_telegram --chat_id 123` |
|
567
599
|
| **`test_twilio`** | Test Twilio SMS and WhatsApp integration | `python manage.py test_twilio` |
|
568
600
|
| **`translate_content`** | Translate JSON with LLM and smart caching | `python manage.py translate_content --target-lang es` |
|
601
|
+
|
602
|
+
### 🎫 Built-in Module Commands
|
603
|
+
| Command | Description | Example |
|
604
|
+
|---------|-------------|---------|
|
569
605
|
| **`support_stats`** | Display support ticket statistics | `python manage.py support_stats --format json` |
|
570
606
|
| **`test_newsletter`** | Test newsletter sending functionality | `python manage.py test_newsletter --email test@example.com` |
|
571
607
|
| **`newsletter_stats`** | Display newsletter campaign statistics | `python manage.py newsletter_stats --format json` |
|
572
608
|
| **`leads_stats`** | Display lead conversion statistics | `python manage.py leads_stats --format json` |
|
573
|
-
|
609
|
+
|
610
|
+
### 🔄 Background Task Commands
|
611
|
+
| Command | Description | Example |
|
612
|
+
|---------|-------------|---------|
|
574
613
|
| **`rundramatiq`** | Run Dramatiq background task workers | `python manage.py rundramatiq --processes 4` |
|
575
614
|
| **`task_status`** | Show Dramatiq task status and queues | `python manage.py task_status --queue high` |
|
576
615
|
| **`task_clear`** | Clear Dramatiq queues | `python manage.py task_clear --queue default` |
|
577
616
|
| **`test_tasks`** | Test Dramatiq task processing pipeline | `python manage.py test_tasks --document-id 123` |
|
578
|
-
| **`tree`** | Display Django project structure | `python manage.py tree --depth 3 --include-docs` |
|
579
|
-
| **`validate_config`** | Deep validation of all settings | `python manage.py validate_config --strict` |
|
580
617
|
|
581
618
|
---
|
582
619
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
django_cfg/README.md,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
django_cfg/__init__.py,sha256=
|
2
|
+
django_cfg/__init__.py,sha256=JG8dtwEHyEayruiAQVqWa4ko-ktJ-kl88E2Y3jZIczA,14288
|
3
3
|
django_cfg/apps.py,sha256=k84brkeXJI7EgKZLEpTkM9YFZofKI4PzhFOn1cl9Msc,1656
|
4
4
|
django_cfg/exceptions.py,sha256=RTQEoU3PfR8lqqNNv5ayd_HY2yJLs3eioqUy8VM6AG4,10378
|
5
5
|
django_cfg/integration.py,sha256=jUO-uZXLmBXy9iugqgsl_xnYA_xoH3LZg5RxZbobVrc,4988
|
@@ -26,7 +26,7 @@ django_cfg/apps/accounts/admin/twilio_response.py,sha256=0K424Yn1Gle41i7xCuFs821
|
|
26
26
|
django_cfg/apps/accounts/admin/user.py,sha256=h9c0wCZ4--_DLZ8rKNMPOtKECxHO8N_228TDnKLFdVA,10571
|
27
27
|
django_cfg/apps/accounts/management/commands/test_otp.py,sha256=NPlANZtGgq9kqOHWneaTyWUIsyvpIbrP6wM0jASSfhA,6980
|
28
28
|
django_cfg/apps/accounts/managers/__init__.py,sha256=NtY-cQl-6TUVum9HEVud4RKbR72xEiYzK14mbd9Y2Y0,50
|
29
|
-
django_cfg/apps/accounts/managers/user_manager.py,sha256=
|
29
|
+
django_cfg/apps/accounts/managers/user_manager.py,sha256=B71kdLfrcBQzFJJyX_bsKldcZKsrUauVLDodTnArJJM,14814
|
30
30
|
django_cfg/apps/accounts/migrations/0001_initial.py,sha256=j139MrNVgq7g7bpV5B14RUhTqoYCMOa5mcaNsuHeJSY,7447
|
31
31
|
django_cfg/apps/accounts/migrations/0002_add_phone_otp_clean.py,sha256=z7FYr6BF_CCyZSjfJqlvcUH1Jfla4JN5uqmlkNyxO4A,1490
|
32
32
|
django_cfg/apps/accounts/migrations/0003_twilioresponse.py,sha256=KBeWBm8UJwqV5UG6KTl9Ugz3Mqe3yJ0ufzwdf8YE4Vo,3172
|
@@ -154,7 +154,7 @@ django_cfg/cli/commands/__init__.py,sha256=EKLXDAx-QttnGmdjsmVANAfhxWplxl2V_2I0S
|
|
154
154
|
django_cfg/cli/commands/create_project.py,sha256=bxgf_YCVAhaGx-mvpuJvcx8fjMJe-EPiuw7pbD4iNxA,21053
|
155
155
|
django_cfg/cli/commands/info.py,sha256=tLZmiZX2nEpwrcN9cUwrGKb95X7dasuoeePrqTmK2do,4932
|
156
156
|
django_cfg/core/__init__.py,sha256=eVK57qFOok9kTeHoNEMQ1BplkUOaQ7NB9kP9eQK1vg0,358
|
157
|
-
django_cfg/core/config.py,sha256=
|
157
|
+
django_cfg/core/config.py,sha256=_ZCZ03FeAiqBgEvgQ1YaBLBgnubnXdtuNuF1N7s2xDM,28119
|
158
158
|
django_cfg/core/environment.py,sha256=AXNKVxcV_3_3gtlafDx3wFTnTPPMGQ9gl40vYm2w-Hg,9101
|
159
159
|
django_cfg/core/generation.py,sha256=i3c0RI4vUk3X2JZiULfoH5_H8ZjO7rOZTY83eJDfDYA,24715
|
160
160
|
django_cfg/core/validation.py,sha256=j0q57oJEJjI6ylb3AzvsgupmvBKsUcrxpmkfKF3ZRF4,6585
|
@@ -165,6 +165,7 @@ django_cfg/management/commands/clear_constance.py,sha256=bSUhxEIKFLmXVilQGn3s9FZ
|
|
165
165
|
django_cfg/management/commands/create_token.py,sha256=beHtUTuyFZhG97F9vSkaX-u7tieAZW-C6pntujGw1C8,11796
|
166
166
|
django_cfg/management/commands/generate.py,sha256=w0BF7IMftxNjxTxFuY8cw5pNKGW-LmTScJ8kZpxHu_8,4248
|
167
167
|
django_cfg/management/commands/list_urls.py,sha256=D8ikInA3uE1LbQGLWmfdLnEqPg7wqrI3caQA6iTe_-0,11009
|
168
|
+
django_cfg/management/commands/migrate_all.py,sha256=zL-wf6SGIeCQ1UNyx-Kt2G1WniLvdxEMsCyYosiYaUk,4749
|
168
169
|
django_cfg/management/commands/migrator.py,sha256=KPWbn46sGWj3y1PBq4vXjE2cY_N_UMmnNdeJaTXIJ18,19799
|
169
170
|
django_cfg/management/commands/rundramatiq.py,sha256=62l7PvtVabtfRtrdktj_5uBbXDXi8oEde0W4IsmoHXw,8980
|
170
171
|
django_cfg/management/commands/runserver_ngrok.py,sha256=mcTioDIzHgha6sGo5eazlJhdKr8y5-uEQIc3qG3AvCI,5237
|
@@ -179,8 +180,9 @@ django_cfg/management/commands/test_telegram.py,sha256=hH6hmKQIosuekc6anrKkf9DAD
|
|
179
180
|
django_cfg/management/commands/test_twilio.py,sha256=DOmcRiaUFYAkNgrbUAlmBsgfgUYFL_jiLgkvlKfLixA,4080
|
180
181
|
django_cfg/management/commands/tree.py,sha256=rBeDOouqntFZjZGI5uYLOCpInJgSzb9Fz7z7ZiCo53E,13240
|
181
182
|
django_cfg/management/commands/validate_config.py,sha256=2V8M6ZCOfrXA-tZ8WoXRxgnb6gDE0xXymAbBzUJ4gic,6940
|
182
|
-
django_cfg/middleware/README.md,sha256=
|
183
|
-
django_cfg/middleware/__init__.py,sha256=
|
183
|
+
django_cfg/middleware/README.md,sha256=LCYTtRy-NvxtmMDCh7anUkhW_HYbjn5SffHQ4TyYllc,8884
|
184
|
+
django_cfg/middleware/__init__.py,sha256=yldqDJ7tJ-2IrmziyzntW90GHI_UKesRSBHjMTP7g6w,284
|
185
|
+
django_cfg/middleware/public_endpoints.py,sha256=EHJKzlYwakeU3hSPBJ53FZn8Ub-jwENCVSfFDJt3kAk,6915
|
184
186
|
django_cfg/middleware/user_activity.py,sha256=P2V_RwiT6F7-F06B-2_V04gf7qFonxM03xVxMFsOk5o,6144
|
185
187
|
django_cfg/models/__init__.py,sha256=du24ZdqKdvc3VNXjgufEz_6B6gxdHtlqVHG4PJWaOQM,419
|
186
188
|
django_cfg/models/cache.py,sha256=Oq6VwVgWAscMM3B91sEvbCX4rXNrP4diSt68_R4XCQk,12131
|
@@ -262,8 +264,8 @@ django_cfg/templates/emails/base_email.html,sha256=TWcvYa2IHShlF_E8jf1bWZStRO0v8
|
|
262
264
|
django_cfg/utils/__init__.py,sha256=64wwXJuXytvwt8Ze_erSR2HmV07nGWJ6DV5wloRBvYE,435
|
263
265
|
django_cfg/utils/path_resolution.py,sha256=eML-6-RIGTs5TePktIQN8nxfDUEFJ3JA0AzWBcihAbs,13894
|
264
266
|
django_cfg/utils/smart_defaults.py,sha256=-qaoiOQ1HKDOzwK2uxoNlmrOX6l8zgGlVPgqtdj3y4g,22319
|
265
|
-
django_cfg-1.1.
|
266
|
-
django_cfg-1.1.
|
267
|
-
django_cfg-1.1.
|
268
|
-
django_cfg-1.1.
|
269
|
-
django_cfg-1.1.
|
267
|
+
django_cfg-1.1.75.dist-info/METADATA,sha256=IaPmM9_kAbLRqYDznkJtgRcYB4Aqx20D4cmTBUZr9xQ,45783
|
268
|
+
django_cfg-1.1.75.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
269
|
+
django_cfg-1.1.75.dist-info/entry_points.txt,sha256=Ucmde4Z2wEzgb4AggxxZ0zaYDb9HpyE5blM3uJ0_VNg,56
|
270
|
+
django_cfg-1.1.75.dist-info/licenses/LICENSE,sha256=xHuytiUkSZCRG3N11nk1X6q1_EGQtv6aL5O9cqNRhKE,1071
|
271
|
+
django_cfg-1.1.75.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|