feat: 移除Swagger/Redoc; 首页按区域分块显示设备清单
This commit is contained in:
@@ -7,8 +7,6 @@ from rest_framework import viewsets, status, parsers, renderers
|
||||
from rest_framework.decorators import action, api_view, parser_classes
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticatedOrReadOnly, IsAuthenticated
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi as swagger_openapi
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from openpyxl.styles import Font
|
||||
import pandas as pd
|
||||
@@ -16,7 +14,41 @@ from loguru import logger
|
||||
|
||||
|
||||
def home_page(request):
|
||||
return render(request, 'device_management/index.html')
|
||||
from collections import OrderedDict
|
||||
from django.db.models import Count, Q
|
||||
|
||||
all_devices = Device.objects.select_related(None).prefetch_related(
|
||||
'serials', 'ips', 'maintenance_records'
|
||||
).order_by('location', 'building', 'cabinet')
|
||||
|
||||
devices_by_location = OrderedDict()
|
||||
for device in all_devices:
|
||||
loc = device.location or '未分类'
|
||||
if loc not in devices_by_location:
|
||||
devices_by_location[loc] = []
|
||||
devices_by_location[loc].append(device)
|
||||
|
||||
status_counts = {
|
||||
'normal': all_devices.filter(status='normal').count(),
|
||||
'warning': all_devices.filter(status='warning').count(),
|
||||
'offline': all_devices.filter(status='offline').count(),
|
||||
'repair': all_devices.filter(status='repair').count(),
|
||||
'scrap': all_devices.filter(status='scrap').count(),
|
||||
}
|
||||
|
||||
warranty_expiring = all_devices.filter(
|
||||
warranty_expire__lte=date.today() + __import__('datetime').timedelta(days=30),
|
||||
warranty_expire__gte=date.today()
|
||||
).count()
|
||||
|
||||
context = {
|
||||
'devices_by_location': devices_by_location,
|
||||
'total_count': all_devices.count(),
|
||||
'status_counts': status_counts,
|
||||
'warranty_expiring': warranty_expiring,
|
||||
'location_count': len(devices_by_location),
|
||||
}
|
||||
return render(request, 'device_management/index.html', context)
|
||||
|
||||
from .models import (
|
||||
Device, DeviceSerial, DeviceIP, MaintenanceRecord, DeviceAttachment
|
||||
|
||||
Reference in New Issue
Block a user