Implement data integration tasks with Celery, including periodic fetching and manual refresh of chat data; add utility functions for data processing and transcript handling; create views and URLs for manual data refresh; establish Redis and Celery configuration; enhance error handling and logging; introduce scripts for data cleanup and fixing dashboard data; update documentation for Redis and Celery setup and troubleshooting.

This commit is contained in:
2025-05-18 13:33:11 +00:00
parent e8f2d2adc2
commit 8bbbb109bd
63 changed files with 4601 additions and 164 deletions

View File

@ -5,18 +5,55 @@ from django.contrib import admin
from .models import ChatSession, Dashboard, DataSource
@admin.register(DataSource)
class DataSourceAdmin(admin.ModelAdmin):
list_display = ("name", "company", "uploaded_at", "get_session_count")
list_display = (
"name",
"company",
"uploaded_at",
"get_external_source",
"get_session_count",
)
list_filter = ("company", "uploaded_at")
search_fields = ("name", "description", "company__name")
ordering = ("-uploaded_at",)
readonly_fields = ("get_external_data_status",)
fieldsets = (
(None, {"fields": ("name", "description", "company")}),
(
"Data Source",
{
"fields": ("file", "external_source"),
"description": "Either upload a file OR select an external data source. Not both.",
},
),
(
"Stats",
{
"fields": ("get_external_data_status",),
},
),
)
@admin.display(description="Sessions")
def get_session_count(self, obj):
return obj.chat_sessions.count()
get_session_count.short_description = "Sessions"
@admin.display(description="External Source")
def get_external_source(self, obj):
if obj.external_source:
return obj.external_source.name
return "None"
@admin.display(description="External Data Status")
def get_external_data_status(self, obj):
if obj.external_source:
return f"Last synced: {obj.external_source.last_synced or 'Never'} | Status: {obj.external_source.get_status()}"
return "No external data source linked"
@admin.register(ChatSession)
class ChatSessionAdmin(admin.ModelAdmin):
list_display = (
"session_id",
@ -45,21 +82,18 @@ class ChatSessionAdmin(admin.ModelAdmin):
)
ordering = ("-start_time",)
@admin.display(
description="Company",
ordering="data_source__company__name",
)
def get_company(self, obj):
return obj.data_source.company.name
get_company.short_description = "Company"
get_company.admin_order_field = "data_source__company__name"
@admin.register(Dashboard)
class DashboardAdmin(admin.ModelAdmin):
list_display = ("name", "company", "created_at", "updated_at")
list_filter = ("company", "created_at")
search_fields = ("name", "description", "company__name")
filter_horizontal = ("data_sources",)
ordering = ("-updated_at",)
admin.site.register(DataSource, DataSourceAdmin)
admin.site.register(ChatSession, ChatSessionAdmin)
admin.site.register(Dashboard, DashboardAdmin)