Files
lottery_ycms/lottery/bot/admin.py

38 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.contrib import admin
from django.urls import path
from django.shortcuts import redirect
from django.contrib import messages
from .models import BotConfig
from .models import BotConfig, WelcomeMessage
from .tasks import restart_bot_container
@admin.register(BotConfig)
class BotConfigAdmin(admin.ModelAdmin):
change_form_template = "admin/botconfig_change_form.html"
def get_urls(self):
urls = super().get_urls()
custom_urls = [
path(
"<int:botconfig_id>/restart/",
self.admin_site.admin_view(self.restart_bot),
name="botconfig-restart"
),
]
return custom_urls + urls
def restart_bot(self, request, botconfig_id):
try:
BotConfig.objects.get(id=botconfig_id)
except BotConfig.DoesNotExist:
self.message_user(request, "Настройка бота с таким ID не найдена.", level=messages.ERROR)
return redirect("..")
restart_bot_container.delay()
self.message_user(request, "Бот будет перезапущен в фоновом режиме.", messages.SUCCESS)
return redirect("..")
@admin.register(WelcomeMessage)
class WWelcomeMessageAdmin(admin.ModelAdmin):
list_display = ("bot", "welcome_message", "welcome_image", "admin_contact", "channel_link", "group_link", "custom_link1_name", "custom_link1_url")