feat: add Daily Report to admin sidebar via custom AdminSite
- Create OpenClawAdminSite (openclaw_admin) with Daily Reports menu in sidebar - Re-register Session/Message/ToolCall with custom site - Add daily/daily-reports URLs at AdminSite level - Override admin/index.html template for sidebar item - Use self.admin_view (not admin.site.admin_view) for site-aware view wrapping - Clean up admin.py: remove inline URLs from SessionAdmin (now at site level)
This commit is contained in:
52
src/openclaw/admin_custom_site.py
Normal file
52
src/openclaw/admin_custom_site.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
Custom AdminSite for OpenClaw — adds Daily Report to sidebar + URLs.
|
||||
Re-registers Session/Message/ToolCall from admin.py, and adds custom report URLs.
|
||||
"""
|
||||
|
||||
from django.contrib.admin import AdminSite
|
||||
|
||||
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):
|
||||
from django.urls import path
|
||||
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 index(self, request, extra_context=None):
|
||||
extra_context = extra_context or {}
|
||||
extra_context["show_daily_report"] = True
|
||||
return super().index(request, extra_context)
|
||||
|
||||
|
||||
openclaw_admin_site = OpenClawAdminSite(name="openclaw_admin")
|
||||
|
||||
# Re-register models with this custom site (imported from admin.py)
|
||||
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)
|
||||
Reference in New Issue
Block a user