Shelter PMS fully functional
This commit is contained in:
@@ -1,14 +1,59 @@
|
||||
from django.contrib import admin
|
||||
from .models import PMSConfiguration, PMSIntegrationLog
|
||||
# Register your models here.
|
||||
from .manager import PluginLoader
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.urls import path
|
||||
from django.utils.html import format_html
|
||||
from django.shortcuts import render
|
||||
from django import forms
|
||||
from pms_integration.models import PMSConfiguration, PMSIntegrationLog
|
||||
|
||||
class PMSConfigurationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = PMSConfiguration
|
||||
fields = "__all__"
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
plugins = PluginLoader.load_plugins()
|
||||
self.fields['plugin_name'].choices = [(plugin, plugin) for plugin in plugins.keys()]
|
||||
|
||||
@admin.register(PMSConfiguration)
|
||||
class PMSConfigurationAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'parser_settings', 'description', 'created_at')
|
||||
form = PMSConfigurationForm
|
||||
list_display = ('name', 'plugin_name', 'created_at', 'check_plugins_button')
|
||||
search_fields = ('name', 'description')
|
||||
list_filter = ('created_at',)
|
||||
ordering = ('-created_at',)
|
||||
|
||||
def get_urls(self):
|
||||
"""Добавляем URL для проверки плагинов."""
|
||||
urls = super().get_urls()
|
||||
custom_urls = [
|
||||
path("check-plugins/", self.check_plugins, name="check-plugins"),
|
||||
]
|
||||
return custom_urls + urls
|
||||
|
||||
def check_plugins(self, request):
|
||||
"""Проверка и отображение плагинов."""
|
||||
plugins = PluginLoader.load_plugins()
|
||||
plugin_details = [
|
||||
{"name": plugin_name, "doc": plugins[plugin_name].__doc__ or "Нет документации"}
|
||||
for plugin_name in plugins
|
||||
]
|
||||
context = {
|
||||
"title": "Проверка плагинов",
|
||||
"plugin_details": plugin_details,
|
||||
}
|
||||
return render(request, "admin/check_plugins.html", context)
|
||||
|
||||
def check_plugins_button(self, obj):
|
||||
"""Добавляем кнопку для проверки плагинов."""
|
||||
return format_html(
|
||||
'<a class="button" href="{}">Проверить плагины</a>',
|
||||
"/admin/pms_integration/pmsconfiguration/check-plugins/",
|
||||
)
|
||||
check_plugins_button.short_description = "Проверить плагины"
|
||||
|
||||
@admin.register(PMSIntegrationLog)
|
||||
class PMSIntegrationLogAdmin(admin.ModelAdmin):
|
||||
|
||||
Reference in New Issue
Block a user