Identation correction in for the webhook part on the admin
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Ekaropolus 2025-07-05 21:40:04 -06:00
parent 3abe84ca2b
commit 37eeeedebc

View File

@ -9,42 +9,41 @@ class TelegramBotAdmin(admin.ModelAdmin):
list_filter = ("is_active",) list_filter = ("is_active",)
actions = ["set_webhooks"] actions = ["set_webhooks"]
@admin.action(description="Set webhooks for selected bots") @admin.action(description="Set webhooks for selected bots")
def set_webhooks(self, request, queryset): def set_webhooks(self, request, queryset):
base_url = f"{request.scheme}://{request.get_host()}" base_url = f"{request.scheme}://{request.get_host()}"
for bot in queryset: for bot in queryset:
if bot.is_active: if bot.is_active:
try: try:
if not bot.assistant: if not bot.assistant:
self.message_user(
request,
f"Bot {bot.name} has no assistant configured.",
level="warning",
)
continue
result = bot.set_webhook(base_url)
self.message_user( self.message_user(
request, request,
f"Bot {bot.name} has no assistant configured.", f"Webhook set for {bot.name}: {result}",
level="warning", level="success",
) )
continue except Exception as e:
result = bot.set_webhook(base_url) self.message_user(
request,
f"Failed to set webhook for {bot.name}: {str(e)}",
level="error",
)
else:
self.message_user( self.message_user(
request, request,
f"Webhook set for {bot.name}: {result}", f"Skipped inactive bot: {bot.name}",
level="success", level="warning",
) )
except Exception as e:
self.message_user(
request,
f"Failed to set webhook for {bot.name}: {str(e)}",
level="error",
)
else:
self.message_user(
request,
f"Skipped inactive bot: {bot.name}",
level="warning",
)
def get_assistant_name(self, obj): def get_assistant_name(self, obj):
"""Show the name of the assistant linked to the bot.""" """Show the name of the assistant linked to the bot."""
return obj.assistant.name if obj.assistant else "None" return obj.assistant.name if obj.assistant else "None"
get_assistant_name.short_description = "Assistant Name" get_assistant_name.short_description = "Assistant Name"
def set_webhook_action(self, obj): def set_webhook_action(self, obj):
@ -53,5 +52,4 @@ def set_webhooks(self, request, queryset):
'<a class="button" href="{}">Set Webhook</a>', '<a class="button" href="{}">Set Webhook</a>',
f"/admin/pxy_bots/set_webhook/{obj.id}/" f"/admin/pxy_bots/set_webhook/{obj.id}/"
) )
set_webhook_action.short_description = "Webhook" set_webhook_action.short_description = "Webhook"