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:
@@ -1,20 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
from openclaw.admin_new_views import (
|
||||
daily_report_list_view,
|
||||
daily_report_detail_view,
|
||||
)
|
||||
|
||||
urlpatterns = [
|
||||
# Custom daily report URLs (before admin.site to take precedence)
|
||||
path("admin/daily/", admin.site.admin_view(daily_report_list_view), name="openclaw_daily"),
|
||||
path("admin/daily-reports/", admin.site.admin_view(daily_report_list_view), name="openclaw_daily_reports"),
|
||||
path(
|
||||
"admin/daily-reports/<str:agent_name>/<int:year>-<int:month>-<int:day>/",
|
||||
admin.site.admin_view(daily_report_detail_view),
|
||||
name="openclaw_daily_report_detail",
|
||||
),
|
||||
path("admin/", admin.site.urls),
|
||||
path("api/", include("openclaw.urls")),
|
||||
]
|
||||
|
||||
@@ -1,72 +1 @@
|
||||
"""
|
||||
Custom AdminSite for OpenClaw — adds Daily Report to sidebar.
|
||||
"""
|
||||
|
||||
from django.contrib.admin import AdminSite
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from django.urls import path
|
||||
|
||||
from openclaw.admin_new_views import daily_report_list_view, daily_report_detail_view
|
||||
|
||||
|
||||
class OpenClawAdminSite(AdminSite):
|
||||
site_header = "OpenClaw Archive"
|
||||
site_title = "OpenClaw Admin"
|
||||
index_title = "Agent Sessions"
|
||||
|
||||
def get_urls(self):
|
||||
urls = super().get_urls()
|
||||
custom_urls = [
|
||||
path(
|
||||
"daily/",
|
||||
self.admin_view(daily_report_list_view),
|
||||
name="openclaw_daily",
|
||||
),
|
||||
path(
|
||||
"daily-reports/",
|
||||
self.admin_view(daily_report_list_view),
|
||||
name="openclaw_daily_reports",
|
||||
),
|
||||
path(
|
||||
"daily-reports/<str:agent_name>/<int:year>-<int:month>-<int:day>/",
|
||||
self.admin_view(daily_report_detail_view),
|
||||
name="openclaw_daily_report_detail",
|
||||
),
|
||||
]
|
||||
return custom_urls + urls
|
||||
|
||||
def get_app_list(self, request, app_label=None):
|
||||
"""
|
||||
Inject 'Daily Reports' as a sidebar app item, before the OpenClaw app.
|
||||
"""
|
||||
app_list = super().get_app_list(request, app_label)
|
||||
|
||||
# Our custom item to inject
|
||||
daily_reports_item = {
|
||||
"name": "Daily Reports",
|
||||
"app_label": "openclaw_daily",
|
||||
"app_url": "/admin/daily-reports/",
|
||||
"models": [
|
||||
{
|
||||
"name": "Daily Reports",
|
||||
"object_name": "DailyReports",
|
||||
"admin_url": "/admin/daily-reports/",
|
||||
"view_only": True,
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
# Insert at the top of the app list
|
||||
app_list.insert(0, daily_reports_item)
|
||||
return app_list
|
||||
|
||||
|
||||
openclaw_admin_site = OpenClawAdminSite(name="openclaw_admin")
|
||||
|
||||
# Re-register models with this custom site
|
||||
from openclaw.admin import SessionAdmin, MessageAdmin, ToolCallAdmin
|
||||
from openclaw.models import Session, Message, ToolCall
|
||||
|
||||
openclaw_admin_site.register(Session, SessionAdmin)
|
||||
openclaw_admin_site.register(Message, MessageAdmin)
|
||||
openclaw_admin_site.register(ToolCall, ToolCallAdmin)
|
||||
# Kept for potential future use — currently not used
|
||||
|
||||
@@ -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