diff --git a/config/urls.py b/config/urls.py index e18d5f1..68cdca3 100644 --- a/config/urls.py +++ b/config/urls.py @@ -11,10 +11,11 @@ from rest_framework_simplejwt.views import ( TokenRefreshView, ) -from device_management.views import home_page +from device_management.views import home_page, device_detail urlpatterns = [ path('', home_page, name='home'), + path('device//', device_detail, name='device_detail'), path('admin/', admin.site.urls), path('api/', include('device_management.urls')), path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'), diff --git a/device_management/templates/device_management/detail.html b/device_management/templates/device_management/detail.html new file mode 100644 index 0000000..111ee57 --- /dev/null +++ b/device_management/templates/device_management/detail.html @@ -0,0 +1,268 @@ + + + + + + {{ device.device_name }} - 设备详情 + + + + +
+
+
+
+ + + + + +
+

{{ device.device_name }}

+

{{ device.location|default:"-" }}

+
+
+ +
+
+
+ +
+ +
+

+ + 基本信息 +

+
+
+

状态

+

+ + {{ device.get_status_display }} + +

+
+
+

品牌

+

{{ device.brand|default:"-" }}

+
+
+

型号

+

{{ device.model|default:"-" }}

+
+
+

地点

+

{{ device.location|default:"-" }}

+
+
+

楼栋/机柜

+

+ {{ device.building|default:"-" }} + {% if device.floor %} {{ device.floor }}{% endif %} + {% if device.cabinet %} / {{ device.cabinet }}{% endif %} +

+
+
+

MAC地址

+

{{ device.mac_address|default:"-" }}

+
+
+

运维人员

+

{{ device.responsible_person|default:"-" }}

+
+
+

启用日期

+

{{ device.enable_date|default:"-" }}

+
+
+

服役时长

+

{{ device.service_duration_days }} 天

+
+
+

保修到期

+

{{ device.warranty_expire|default:"-" }}

+
+
+

最后巡检

+

{{ device.last_inspection_date|default:"-" }}

+
+
+
+ + +
+

+ + IP地址 + {{ device_ips|length }} +

+ {% if device_ips %} +
+ + + + + + + + + + + + + {% for ip in device_ips %} + + + + + + + + + {% endfor %} + +
IP地址类型主IP子网掩码网关VLAN
{{ ip.ip_address }}{{ ip.ip_type|default:"-" }} + {% if ip.is_primary %} + + {% else %} + + {% endif %} + {{ ip.subnet_mask|default:"-" }}{{ ip.gateway|default:"-" }}{{ ip.vlan_id|default:"-" }}
+
+ {% else %} +

暂无IP地址

+ {% endif %} +
+ + +
+

+ + 序列号 + {{ device_serials|length }} +

+ {% if device_serials %} +
+ + + + + + + + + + + {% for serial in device_serials %} + + + + + + + {% endfor %} + +
序列号类型主序列号备注
{{ serial.serial_number }}{{ serial.serial_type|default:"-" }} + {% if serial.is_primary %} + + {% else %} + + {% endif %} + {{ serial.remark|default:"-" }}
+
+ {% else %} +

暂无序列号

+ {% endif %} +
+ + +
+

+ + 维修记录 + {{ maintenance_records|length }} +

+ {% if maintenance_records %} +
+ {% for record in maintenance_records %} +
+
+ {{ record.maintenance_date }} + + {% if record.cost %}费用: ¥{{ record.cost }}{% endif %} + {% if record.maintenance_by %} · {{ record.maintenance_by }}{% endif %} + +
+ {% if record.fault_description %} +
+

故障描述

+

{{ record.fault_description }}

+
+ {% endif %} + {% if record.repair_content %} +
+

维修内容

+

{{ record.repair_content }}

+
+ {% endif %} + {% if record.replaced_parts %} +
+

更换配件

+

{{ record.replaced_parts }}

+
+ {% endif %} +
+ {% endfor %} +
+ {% else %} +

暂无维修记录

+ {% endif %} +
+ + +
+

+ + 附件 + {{ attachments|length }} +

+ {% if attachments %} + + {% else %} +

暂无附件

+ {% endif %} +
+
+ + + + diff --git a/device_management/templates/device_management/index.html b/device_management/templates/device_management/index.html index 540c76c..31a8d06 100644 --- a/device_management/templates/device_management/index.html +++ b/device_management/templates/device_management/index.html @@ -92,8 +92,6 @@ 设备名称 型号 - 主IP - 主序列号 状态 运维人员 服役天数 @@ -104,34 +102,12 @@ {% for device in devices %} -
{{ device.device_name }}
+
+ {{ device.device_name }} +
{{ device.brand|default:"" }}
{{ device.model|default:"-" }} - - {% with primary_ip=device.ips.all|first %} - {% if primary_ip and primary_ip.is_primary %} - {{ primary_ip.ip_address }} - {% else %} - {% for ip in device.ips.all %} - {% if ip.is_primary %} - {{ ip.ip_address }} - {% endif %} - {% empty %} - - - {% endfor %} - {% endif %} - {% endwith %} - - - {% for serial in device.serials.all %} - {% if serial.is_primary %} - {{ serial.serial_number }} - {% endif %} - {% empty %} - - - {% endfor %} - {{ device.get_status_display }} diff --git a/device_management/views.py b/device_management/views.py index 0fdcc2c..7a6cf71 100644 --- a/device_management/views.py +++ b/device_management/views.py @@ -50,6 +50,26 @@ def home_page(request): } return render(request, 'device_management/index.html', context) + +def device_detail(request, device_id): + from django.shortcuts import get_object_or_404 + + device = get_object_or_404(Device, id=device_id) + device_serials = device.serials.all() + device_ips = device.ips.all() + maintenance_records = device.maintenance_records.order_by('-maintenance_date') + attachments = device.attachments.order_by('-uploaded_at') + + context = { + 'device': device, + 'device_serials': device_serials, + 'device_ips': device_ips, + 'maintenance_records': maintenance_records, + 'attachments': attachments, + } + return render(request, 'device_management/detail.html', context) + + from .models import ( Device, DeviceSerial, DeviceIP, MaintenanceRecord, DeviceAttachment )