fix: add Daily Reports to sidebar via get_app_list override
- Create openclaw_daily app (no models, just app config) - Override get_app_list() in OpenClawAdminSite to inject Daily Reports item - Use get_app_list approach (not nav-sidebar template override) - Inject at top of app list for visibility
This commit is contained in:
@@ -14,6 +14,7 @@ INSTALLED_APPS = [
|
||||
"django.contrib.humanize",
|
||||
"rest_framework",
|
||||
"openclaw",
|
||||
"openclaw_daily",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
"""
|
||||
Custom AdminSite for OpenClaw — adds Daily Report to sidebar + URLs.
|
||||
Re-registers Session/Message/ToolCall from admin.py, and adds custom report URLs.
|
||||
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
|
||||
|
||||
@@ -14,7 +15,6 @@ class OpenClawAdminSite(AdminSite):
|
||||
index_title = "Agent Sessions"
|
||||
|
||||
def get_urls(self):
|
||||
from django.urls import path
|
||||
urls = super().get_urls()
|
||||
custom_urls = [
|
||||
path(
|
||||
@@ -35,15 +35,35 @@ class OpenClawAdminSite(AdminSite):
|
||||
]
|
||||
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)
|
||||
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 (imported from admin.py)
|
||||
# Re-register models with this custom site
|
||||
from openclaw.admin import SessionAdmin, MessageAdmin, ToolCallAdmin
|
||||
from openclaw.models import Session, Message, ToolCall
|
||||
|
||||
|
||||
1
src/openclaw_daily/__init__.py
Normal file
1
src/openclaw_daily/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
default_app_config = "openclaw_daily.apps.OpenClawDailyConfig"
|
||||
6
src/openclaw_daily/apps.py
Normal file
6
src/openclaw_daily/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
class OpenClawDailyConfig(AppConfig):
|
||||
name = "openclaw_daily"
|
||||
label = "openclaw_daily"
|
||||
verbose_name = "Daily Reports"
|
||||
@@ -1,24 +0,0 @@
|
||||
{% extends "admin/index.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block branding %}
|
||||
<h1 id="site-name">
|
||||
<a href="{% url 'openclaw_admin:index' %}">{{ site_header|default:"Django Admin" }}</a>
|
||||
</h1>
|
||||
{% endblock %}
|
||||
|
||||
{% block nav-sidebar %}
|
||||
{{ block.super }}
|
||||
|
||||
{# Daily Report custom sidebar item #}
|
||||
<div class="app-openclaw module">
|
||||
<table>
|
||||
<caption>
|
||||
<a href="{% url 'openclaw_admin:openclaw_daily_reports' %}" class="section">
|
||||
📊 Daily Reports
|
||||
</a>
|
||||
</caption>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user