48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
# Middleware de diagnóstico: grava uma linha em NDJSON ao acessar /admin/
|
|
# Remover após confirmar correção do admin sem estilo.
|
|
import json
|
|
from pathlib import Path
|
|
from django.conf import settings
|
|
|
|
LOG_PATH = Path("/home/f3lipe/dev/.cursor/debug-288380.log")
|
|
SESSION_ID = "288380"
|
|
|
|
|
|
class DebugStaticLoggerMiddleware:
|
|
def __init__(self, get_response):
|
|
self.get_response = get_response
|
|
|
|
def __call__(self, request):
|
|
# #region agent log
|
|
if request.path.startswith("/admin/"):
|
|
static_root = getattr(settings, "STATIC_ROOT", None)
|
|
admin_css_exists = False
|
|
if static_root:
|
|
p = Path(static_root) / "admin" / "css"
|
|
admin_css_exists = p.exists() and any(p.iterdir())
|
|
try:
|
|
with open(LOG_PATH, "a") as f:
|
|
f.write(
|
|
json.dumps(
|
|
{
|
|
"sessionId": SESSION_ID,
|
|
"hypothesisId": "H1",
|
|
"location": "config/debug_static_logger.py",
|
|
"message": "admin request static config",
|
|
"data": {
|
|
"DEBUG": settings.DEBUG,
|
|
"STATIC_URL": getattr(settings, "STATIC_URL", None),
|
|
"STATIC_ROOT": str(static_root) if static_root else None,
|
|
"admin_css_exists": admin_css_exists,
|
|
},
|
|
"timestamp": __import__("time").time() * 1000,
|
|
},
|
|
ensure_ascii=False,
|
|
)
|
|
+ "\n"
|
|
)
|
|
except Exception:
|
|
pass
|
|
# #endregion
|
|
return self.get_response(request)
|