fix: add Daily Reports to admin sidebar via ready() monkey-patch
- openclaw_daily/apps.py ready(): monkey-patch admin.site.get_urls() to add daily/ and daily-reports/ URLs under admin namespace (admin: prefix) - admin_custom_site.py: simplified (no custom site needed) - Revert urls.py to use default admin.site - URL now correctly resolves as admin:openclaw_daily_report_detail
This commit is contained in:
@@ -8,11 +8,44 @@ class OpenClawDailyConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from openclaw.admin_new_views import (
|
||||
daily_report_list_view,
|
||||
daily_report_detail_view,
|
||||
)
|
||||
|
||||
_orig = admin.site.get_app_list
|
||||
# ── Monkey-patch admin.site.get_urls ───────────────────────────────
|
||||
_orig_get_urls = admin.site.get_urls
|
||||
|
||||
def _patched(request, app_label=None):
|
||||
app_list = _orig(request, app_label)
|
||||
def _new_get_urls():
|
||||
urls = _orig_get_urls()
|
||||
# Prepend our custom URLs so they take precedence
|
||||
custom = [
|
||||
path(
|
||||
"daily/",
|
||||
admin.site.admin_view(daily_report_list_view),
|
||||
name="openclaw_daily",
|
||||
),
|
||||
path(
|
||||
"daily-reports/",
|
||||
admin.site.admin_view(daily_report_list_view),
|
||||
name="openclaw_daily_reports",
|
||||
),
|
||||
path(
|
||||
"daily-reports/<str:agent_name>/<int:year>-<int:month>-<int:day>/",
|
||||
admin.site.admin_view(daily_report_detail_view),
|
||||
name="openclaw_daily_report_detail",
|
||||
),
|
||||
]
|
||||
return custom + urls
|
||||
|
||||
admin.site.get_urls = _new_get_urls
|
||||
|
||||
# ── Monkey-patch admin.site.get_app_list ──────────────────────────
|
||||
_orig_get_app_list = admin.site.get_app_list
|
||||
|
||||
def _new_get_app_list(request, app_label=None):
|
||||
app_list = _orig_get_app_list(request, app_label)
|
||||
app_list.insert(0, {
|
||||
"name": "Daily Reports",
|
||||
"app_label": "openclaw_daily",
|
||||
@@ -26,4 +59,4 @@ class OpenClawDailyConfig(AppConfig):
|
||||
})
|
||||
return app_list
|
||||
|
||||
admin.site.get_app_list = _patched
|
||||
admin.site.get_app_list = _new_get_app_list
|
||||
|
||||
Reference in New Issue
Block a user