|
@@ -9,7 +9,7 @@ from django.utils.html import format_html
|
|
|
from django.core.mail import mail_managers
|
|
|
|
|
|
from adhesions.models import Adhesion
|
|
|
-from .models import Service, ServiceType, IPResource, Route, ServiceAllocation, Antenna, AntennaAllocation, Allocation
|
|
|
+from .models import Service, ServiceType, IPPrefix, IPResource, Route, ServiceAllocation, Antenna, AntennaAllocation, Allocation
|
|
|
from .utils import notify_allocation
|
|
|
|
|
|
|
|
@@ -32,6 +32,25 @@ class ResourceInUseFilter(admin.SimpleListFilter):
|
|
|
if self.value() == '1': # disponible
|
|
|
return queryset.filter(available_filter)
|
|
|
|
|
|
+class AntennaPrefixFilter(admin.SimpleListFilter):
|
|
|
+ title = 'préfix'
|
|
|
+ parameter_name = 'prefix'
|
|
|
+
|
|
|
+ def lookups(self, request, model_admin):
|
|
|
+ resources = AntennaAllocation.actives.filter(active=True).values_list('resource')
|
|
|
+ prefixes = IPPrefix.objects.filter(ipresource=resources).values_list('pk', 'prefix')
|
|
|
+ return prefixes
|
|
|
+
|
|
|
+ def queryset(self, request, queryset):
|
|
|
+ try:
|
|
|
+ prefix = int(self.value())
|
|
|
+ except TypeError:
|
|
|
+ pass
|
|
|
+ else:
|
|
|
+ allocations = AntennaAllocation.actives.filter(active=True, resource__prefixes__pk=prefix)
|
|
|
+ queryset = queryset.filter(allocation=allocations)
|
|
|
+ return queryset
|
|
|
+
|
|
|
|
|
|
### Inlines
|
|
|
|
|
@@ -211,6 +230,9 @@ class ServiceTypeAdmin(admin.ModelAdmin):
|
|
|
|
|
|
class AntennaAdmin(geo_admin.OSMGeoAdmin):
|
|
|
inlines = (AntennaAllocationInline,)
|
|
|
+ list_filter = (
|
|
|
+ AntennaPrefixFilter,
|
|
|
+ )
|
|
|
|
|
|
|
|
|
admin.site.register(ServiceType, ServiceTypeAdmin)
|