|
@@ -185,7 +185,6 @@ class AllocationInlineFormSet(BaseInlineFormSet):
|
|
|
class AllocationInline(admin.TabularInline):
|
|
|
formset = AllocationInlineFormSet
|
|
|
extra = 0
|
|
|
- verbose_name_plural = 'Allocations'
|
|
|
show_change_link = True
|
|
|
|
|
|
def get_formset(self, request, obj=None, **kwargs):
|
|
@@ -203,18 +202,48 @@ class AllocationInline(admin.TabularInline):
|
|
|
return False
|
|
|
|
|
|
|
|
|
-class ServiceAllocationInline(AllocationInline):
|
|
|
+class ActiveAllocationMixin:
|
|
|
+ verbose_name_plural = 'Allocations actives'
|
|
|
+
|
|
|
+ def get_queryset(self, request):
|
|
|
+ return super().get_queryset(request).filter(active=True)
|
|
|
+
|
|
|
+
|
|
|
+class InactiveAllocationMixin:
|
|
|
+ verbose_name_plural = 'Anciennes allocations'
|
|
|
+
|
|
|
+ def get_queryset(self, request):
|
|
|
+ return super().get_queryset(request).filter(active=False)
|
|
|
+
|
|
|
+
|
|
|
+class ServiceAllocationMixin:
|
|
|
model = ServiceAllocation
|
|
|
fields = ('id', 'service', 'resource', 'route', 'start', 'end')
|
|
|
raw_id_fields = ('service', 'resource',)
|
|
|
|
|
|
|
|
|
-class AntennaAllocationInline(AllocationInline):
|
|
|
+class AntennaAllocationMixin:
|
|
|
model = AntennaAllocation
|
|
|
fields = ('id', 'antenna', 'resource', 'start', 'end')
|
|
|
raw_id_fields = ('antenna', 'resource',)
|
|
|
|
|
|
|
|
|
+class ActiveServiceAllocationInline(ServiceAllocationMixin, ActiveAllocationMixin, AllocationInline):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+class InactiveServiceAllocationInline(ServiceAllocationMixin, InactiveAllocationMixin, AllocationInline):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+class ActiveAntennaAllocationInline(AntennaAllocationMixin, ActiveAllocationMixin, AllocationInline):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
+class InactiveAntennaAllocationInline(AntennaAllocationMixin, InactiveAllocationMixin, AllocationInline):
|
|
|
+ pass
|
|
|
+
|
|
|
+
|
|
|
### Actions
|
|
|
|
|
|
def ends_resource(resource, request, queryset):
|
|
@@ -233,7 +262,7 @@ class ServiceAdmin(admin.ModelAdmin):
|
|
|
ActiveServiceFilter,
|
|
|
('service_type', admin.RelatedOnlyFieldListFilter),
|
|
|
)
|
|
|
- inlines = (ServiceAllocationInline,)
|
|
|
+ inlines = (ActiveServiceAllocationInline, InactiveServiceAllocationInline,)
|
|
|
search_fields = ('=id', 'service_type__name', 'label', 'notes',)
|
|
|
fields = ('adhesion', 'service_type', 'label', 'notes', 'get_contribution_link', 'is_active',)
|
|
|
readonly_fields = ('get_contribution_link', 'is_active',)
|
|
@@ -314,9 +343,9 @@ class IPResourceAdmin(admin.ModelAdmin):
|
|
|
def get_inline_instances(self, request, obj=None):
|
|
|
if obj:
|
|
|
if obj.category == 0:
|
|
|
- inlines = (ServiceAllocationInline,)
|
|
|
+ inlines = (ActiveServiceAllocationInline, InactiveServiceAllocationInline,)
|
|
|
elif obj.category == 1:
|
|
|
- inlines = (AntennaAllocationInline,)
|
|
|
+ inlines = (ActiveAntennaAllocationInline, InactiveAntennaAllocationInline,)
|
|
|
else:
|
|
|
inlines = ()
|
|
|
return [inline(self.model, self.admin_site) for inline in inlines]
|
|
@@ -494,7 +523,7 @@ class ServiceTypeAdmin(admin.ModelAdmin):
|
|
|
|
|
|
|
|
|
class AntennaAdmin(admin.ModelAdmin):
|
|
|
- inlines = (AntennaAllocationInline,)
|
|
|
+ inlines = (ActiveAntennaAllocationInline, InactiveAntennaAllocationInline,)
|
|
|
list_filter = (
|
|
|
AntennaPrefixFilter,
|
|
|
AntennaPositionFilter,
|