- 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
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
from django.apps import AppConfig
|
|
|
|
|
|
class OpenClawDailyConfig(AppConfig):
|
|
name = "openclaw_daily"
|
|
label = "openclaw_daily"
|
|
verbose_name = "Daily Reports"
|
|
|
|
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,
|
|
)
|
|
|
|
# ── Monkey-patch admin.site.get_urls ───────────────────────────────
|
|
_orig_get_urls = admin.site.get_urls
|
|
|
|
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",
|
|
"app_url": "/admin/daily-reports/",
|
|
"models": [{
|
|
"name": "Daily Reports",
|
|
"object_name": "DailyReports",
|
|
"admin_url": "/admin/daily-reports/",
|
|
"view_only": True,
|
|
}],
|
|
})
|
|
return app_list
|
|
|
|
admin.site.get_app_list = _new_get_app_list
|