|
|
from conntrackt.models import *
|
|
|
from django.contrib import admin
|
|
|
from django.core.urlresolvers import resolve
|
|
|
|
|
|
class InterfaceInline(admin.StackedInline):
|
|
|
model = Interface
|
|
|
extra = 1
|
|
|
|
|
|
def add_under_project(modeladmin, request, queryset):
|
|
|
print "Hello"
|
|
|
add_under_project.short_description = "Do things."
|
|
|
|
|
|
class CommunicationAdmin(admin.ModelAdmin):
|
|
|
list_display = ('source', 'destination', 'protocol', 'port', 'edit_link')
|
|
|
list_editable = ('source', 'destination', 'protocol', 'port')
|
|
|
list_display_links = ('edit_link',)
|
|
|
list_filter = ['source__entity__project', 'source__entity__location']
|
|
|
actions = [add_under_project]
|
|
|
|
|
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
|
|
view_name = resolve(request.path).view_name
|
|
|
if db_field.name == "source" or db_field.name == "destination":
|
|
|
interface_filter = {}
|
|
|
if 'source__entity__project__id__exact' in request.GET:
|
|
|
interface_filter['entity__project'] = request.GET['source__entity__project__id__exact']
|
|
|
if 'source__entity__location__id__exact' in request.GET:
|
|
|
interface_filter['entity__location'] = request.GET['source__entity__location__id__exact']
|
|
|
if interface_filter:
|
|
|
kwargs["queryset"] = Interface.objects.filter(**interface_filter)
|
|
|
return super(CommunicationAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
|
|
|
|
|
|
class EntityAdmin(admin.ModelAdmin):
|
|
|
inlines = [InterfaceInline]
|
|
|
list_display = ('name', 'project', 'location')
|
|
|
list_editable = ('project', 'location')
|
|
|
list_filter = ['project', 'location']
|
|
|
|
|
|
class InterfaceAdmin(admin.ModelAdmin):
|
|
|
list_display = ('entity', 'address', 'netmask')
|
|
|
list_editable = ('address', 'netmask')
|
|
|
|
|
|
|
|
|
admin.site.register(Project)
|
|
|
admin.site.register(Location)
|
|
|
admin.site.register(Entity)
|
|
|
admin.site.register(Interface)
|
|
|
admin.site.register(Communication)
|
|
|
admin.site.register(Entity, EntityAdmin)
|
|
|
admin.site.register(Interface, InterfaceAdmin)
|
|
|
admin.site.register(Communication, CommunicationAdmin)
|
|
|
|