diff --git a/bots/admin.py b/bots/admin.py index 1e8335f84..a73a57d86 100644 --- a/bots/admin.py +++ b/bots/admin.py @@ -12,7 +12,7 @@ from django.utils.timesince import timesince from app_users.models import AppUser -from bots.admin_links import list_related_html_url, change_obj_url +from bots.admin_links import list_related_html_url, change_obj_url, open_in_new_tab from bots.models import ( FeedbackComment, CHATML_ROLE_ASSISSTANT, @@ -29,11 +29,14 @@ BotIntegrationAnalysisRun, ) from bots.tasks import create_personal_channels_for_all_members +from daras_ai_v2.fastapi_tricks import get_route_url from gooeysite.custom_actions import export_to_excel, export_to_csv from gooeysite.custom_filters import ( related_json_field_summary, ) from gooeysite.custom_widgets import JSONEditorWidget +from recipes.VideoBots import VideoBotsPage +from routers.root import integrations_stats_route fb_fields = [ "fb_page_id", @@ -160,7 +163,7 @@ class BotIntegrationAdmin(admin.ModelAdmin): "view_messsages", "created_at", "updated_at", - "api_integration_id", + "api_integration_stats_url", ] fieldsets = [ @@ -173,7 +176,7 @@ class BotIntegrationAdmin(admin.ModelAdmin): "published_run", "billing_account_uid", "user_language", - "api_integration_id", + "api_integration_stats_url", ], }, ), @@ -248,6 +251,21 @@ def view_analysis_results(self, bi: BotIntegration): html = mark_safe(html) return html + @admin.display(description="Integration Stats") + def api_integration_stats_url(self, bi: BotIntegration): + + integration_id = bi.api_integration_id() + return open_in_new_tab( + url=get_route_url( + integrations_stats_route, + params=dict( + page_slug=VideoBotsPage.slug_versions[-1], + integration_id=integration_id, + ), + ), + label=integration_id, + ) + @admin.register(PublishedRun) class PublishedRunAdmin(admin.ModelAdmin): diff --git a/bots/models.py b/bots/models.py index ae8a828e8..c53f825b3 100644 --- a/bots/models.py +++ b/bots/models.py @@ -640,10 +640,10 @@ def get_active_saved_run(self) -> SavedRun | None: def get_display_name(self): return ( (self.wa_phone_number and self.wa_phone_number.as_international) - or self.ig_username - or self.fb_page_name or self.wa_phone_number_id + or self.fb_page_name or self.fb_page_id + or self.ig_username or " | #".join( filter(None, [self.slack_team_name, self.slack_channel_name]) ) @@ -656,7 +656,6 @@ def get_display_name(self): get_display_name.short_description = "Bot" - @admin.display(description="API integraton_id") def api_integration_id(self): from routers.bots_api import api_hashids @@ -987,6 +986,7 @@ def get_display_name(self): ) or self.fb_page_id or self.slack_user_id + or self.web_user_id ) get_display_name.short_description = "User" diff --git a/recipes/VideoBotsStats.py b/recipes/VideoBotsStats.py index c4a397753..f871deff4 100644 --- a/recipes/VideoBotsStats.py +++ b/recipes/VideoBotsStats.py @@ -437,12 +437,7 @@ def calculate_overall_stats(self, bi, run_title, run_url): rating=Feedback.Rating.RATING_THUMBS_DOWN, ).count() run_link = f'Powered By: {run_title}' - connection_detail = ( - bi.fb_page_name - or bi.wa_phone_number - or bi.ig_username - or (bi.slack_team_name + " - " + bi.slack_channel_name) - ) + connection_detail = bi.get_display_name() st.markdown( f""" - Platform: {Platform(bi.platform).name.capitalize()}