from django.contrib import admin

from django.contrib.auth.models import User
from django.contrib.postgres import fields
from django_json_widget.widgets import JSONEditorWidget

from console import models
from networkmap import models as netmap_models


class IncidentAdmin(admin.ModelAdmin):
    date_hierarchy = 'timestamp'
    list_display = ('incident_id', 'timestamp', 'title', 'category', 'importance', 'status', 'assigned_to')
    list_filter = ('category', 'status', 'assigned_to')
    list_display_links = ['incident_id']

    formfield_overrides = {
        fields.JSONField: {'widget': JSONEditorWidget},
    }


class ConnectionAdmin(admin.ModelAdmin):
    list_display = ['pk', 'src_asset', 'dst_asset', 'src_port', 'dst_port', 'updated']
    list_filter = ['src_asset', 'dst_asset']
    list_display_links = ['pk']


# Re-register UserAdmin
admin.site.register(models.VulnerabilityEffect)
admin.site.register(models.VulnerabilityRecommendations)
admin.site.register(models.Vulnerability)
admin.site.register(models.ConnectionType)
admin.site.register(models.Connection, ConnectionAdmin)
admin.site.register(netmap_models.NetworkMap)
