|
@@ -14,6 +14,8 @@ from django.contrib.postgres.aggregates import StringAgg
|
|
|
from django.db import connection
|
|
|
from django.core.cache import cache
|
|
|
from django.contrib.humanize.templatetags.humanize import naturaltime
|
|
|
+from django.contrib.contenttypes.models import ContentType
|
|
|
+from django.http import HttpResponseRedirect
|
|
|
|
|
|
from djgeojson.views import GeoJSONLayerView
|
|
|
from urllib.parse import urlencode
|
|
@@ -382,6 +384,7 @@ class IPResourceAdmin(admin.ModelAdmin):
|
|
|
RouteFilter,
|
|
|
)
|
|
|
search_fields = ('=ip', 'notes',)
|
|
|
+ actions = ['contact_ip_owners']
|
|
|
|
|
|
def get_fields(self, request, obj=None):
|
|
|
return self.get_readonly_fields(request, obj)
|
|
@@ -461,6 +464,18 @@ class IPResourceAdmin(admin.ModelAdmin):
|
|
|
return format_html('<a href="{}">{}</a>', obj.checkmk_url, 'voir')
|
|
|
checkmk.short_description = 'CheckMK'
|
|
|
|
|
|
+ def contact_ip_owners(self, request, queryset):
|
|
|
+ selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
|
|
|
+ services = ServiceAllocation.objects.filter(resource__ip__in=selected) \
|
|
|
+ .filter(get_active_filter()) \
|
|
|
+ .values_list('service__adhesion', flat=True)
|
|
|
+ antennas = AntennaAllocation.objects.filter(resource__ip__in=selected) \
|
|
|
+ .filter(get_active_filter()) \
|
|
|
+ .values_list('antenna__contact', flat=True)
|
|
|
+ pk = ",".join(map(str, set(services) | set(antennas)))
|
|
|
+ return HttpResponseRedirect(reverse('admin:contact-adherents') + "?pk=%s" % pk)
|
|
|
+ contact_ip_owners.short_description = 'Contacter les adhérents'
|
|
|
+
|
|
|
def get_actions(self, request):
|
|
|
actions = super().get_actions(request)
|
|
|
if 'delete_selected' in actions:
|