from django.contrib import admin
from kombu.transport.django import models as kombu_models
from malwaredb.models import Malware, Upload, VirusTotalInfo, Hooklog, VirusTotal
from malwaredb.tasks import profiling


class HooklogInline(admin.StackedInline):
    model = Hooklog


class MalwareAdmin(admin.ModelAdmin):
    list_display = ('hash', 'submissiondate', 'create_hooklog_state')
    search_fields = ('hash', 'submissiondate', )
    actions = ['reprofiling']
    inlines = [HooklogInline, ]

    def reprofiling(self, request, queryset):
        for obj in queryset:
            profiling.delay(obj.hash)
    reprofiling.short_description = "Reprofiling"


class UploadAdmin(admin.ModelAdmin):
    list_display = ('name', 'hash', 'submissiondate', 'user_account')
    search_fields = ('hash', 'submissiondate', 'user_account__user__username')


class VirusTotalInfoAdmin(admin.ModelAdmin):
    list_display = ('vendor', 'md5')
    search_fields = ('md5',)


class VirusTotalAdmin(admin.ModelAdmin):
    list_display = ('malware', 'created')
    search_fields = ('malware',)


class HooklogAdmin(admin.ModelAdmin):
    list_display = ('malware', 'hooklog_file', 'created')
    search_fields = ('malware',)


admin.site.register(Malware, MalwareAdmin)
admin.site.register(Upload, UploadAdmin)
admin.site.register(VirusTotalInfo, VirusTotalInfoAdmin)
admin.site.register(VirusTotal, VirusTotalAdmin)
admin.site.register(Hooklog, HooklogAdmin)


# Celery
admin.site.register(kombu_models.Message)
