Browse Source

affichage route des IP

Élie Bouttier 6 years ago
parent
commit
2e88ea11e4
1 changed files with 18 additions and 1 deletions
  1. 18 1
      services/admin.py

+ 18 - 1
services/admin.py

@@ -374,7 +374,7 @@ class IPPrefixAdmin(admin.ModelAdmin):
 
 
 class IPResourceAdmin(admin.ModelAdmin):
-    list_display = ('__str__', 'available_display', 'last_use', 'ping',)
+    list_display = ('__str__', 'available_display', 'route', 'last_use', 'ping',)
     list_filter = (
         'category',
         ResourceInUseFilter,
@@ -431,6 +431,18 @@ class IPResourceAdmin(admin.ModelAdmin):
                     output_field=models.NullBooleanField(),
                 ))
         qs = qs.annotate(downtime=models.F('last_check') - models.F('last_time_up'))
+        qs = qs.annotate(
+                route=models.Case(
+                    models.When(
+                        in_use_by_service=True,
+                        then=models.Subquery(
+                            ServiceAllocation.objects.filter(
+                                Q(resource=models.OuterRef('pk')) & get_active_filter()
+                            ).values('route__name')[:1]
+                        ),
+                    ),
+                    output_field=models.CharField(),
+                ))
         return qs
 
     def available_display(self, obj):
@@ -460,6 +472,11 @@ class IPResourceAdmin(admin.ModelAdmin):
     ping.short_description = 'ping'
     ping.admin_order_field = 'downtime'
 
+    def route(self, obj):
+        return obj.route
+    route.short_description = 'route'
+    route.admin_order_field = 'route'
+
     def checkmk(self, obj):
         return format_html('<a href="{}">{}</a>', obj.checkmk_url, 'voir')
     checkmk.short_description = 'CheckMK'