from django.contrib.admin import AdminSite
from django.contrib.admin.models import LogEntry
from django.contrib.sites.admin import SiteAdmin
from django.contrib.sites.models import Site

from accounts.admin import UserAdmin, GroupAdmin
from blog.admin import PostAdmin, CategoryAdmin
from blog.models import Post, Category
from comments.admin import CommentAdmin
from comments.models import Comment
from djangoblog.logentryadmin import LogEntryAdmin
from oauth.admin import OAuthAppAdmin, OAuthUserAdmin
from oauth.models import OAuthApp, OAuthUser
from owntracks.admin import DeviceAdmin, LocationAdmin
from owntracks.models import Device, Location
from servermanager.admin import ServerAdmin, TaskAdmin
from servermanager.models import Server, Task

class DjangoBlogAdminSite(AdminSite):
    """
    sh:
    自定义Admin站点类，继承自Django的AdminSite
    用于定制博客系统的管理后台特性
    """
    # 管理后台页面顶部的标题
    site_header = 'djangoblog administration'
    # 浏览器标签页显示的标题
    site_title = 'djangoblog site admin'

    def __init__(self, name='admin'):
        # 调用父类构造方法初始化
        super().__init__(name)

    def has_permission(self, request):
        """
        重写权限检查方法：仅允许超级用户访问管理后台
        """
        return request.user.is_superuser


admin_site = DjangoBlogAdminSite(name='admin')
"""注册博客核心模型及对应的Admin配置"""
admin_site.register(Article, ArticlelAdmin)
admin_site.register(Category, CategoryAdmin)
admin_site.register(Tag, TagAdmin)
admin_site.register(Links, LinksAdmin)
admin_site.register(SideBar, SideBarAdmin)
admin_site.register(BlogSettings, BlogSettingsAdmin)
"""注册服务器管理相关模型"""
admin_site.register(commands, CommandsAdmin)
admin_site.register(EmailSendLog, EmailSendLogAdmin)
"""注册用户相关模型"""
admin_site.register(BlogUser, BlogUserAdmin)
"""注册评论模型"""
admin_site.register(Comment, CommentAdmin)
"""注册OAuth相关模型"""
admin_site.register(OAuthUser, OAuthUserAdmin)
admin_site.register(OAuthConfig, OAuthConfigAdmin)
"""注册OwnTracks位置追踪模型"""
admin_site.register(OwnTrackLog, OwnTrackLogsAdmin)
"""注册站点和操作日志模型"""
admin_site.register(Site, SiteAdmin)
admin_site.register(LogEntry, LogEntryAdmin)
