from django.contrib import admin
from django.db.models import CASCADE, AutoField, OneToOneField
from django.views.generic import View
from django.utils.translation import gettext as _
from .models import *


@admin.action(description=_("Regenerate traits"))
def regenerate(modeladmin, request, queryset):
    for obj in queryset:
        obj.regenerate()


@admin.register(Keyword)
class KeywordAdmin(admin.ModelAdmin):
    """
    Admin Interface for Keyword
    """
    list_display = ["text_en", "text_de"]


@admin.register(StaticSite)
class StaticSiteAdmin(admin.ModelAdmin):
    """
    Admin Interface for StaticSite
    """
    list_display = ["title_en", "subtitle_en",
                    "title_de", "subtitle_de", "suburl"]
    ordering = ['title_de', 'title_en']
    actions = [regenerate]


@admin.register(Searchable)
class SearchableAdmin(admin.ModelAdmin):
    """
    Abstract Admin Interface for all Searchables
    """
    list_display = ["title_en", "subtitle_en",
                    "title_de", "subtitle_de", "suburl"]
    ordering = ['title_de', 'title_en']
    actions = [regenerate]


@admin.register(Link)
class LinkAdmin(admin.ModelAdmin):
    """
    Admin Interface for Links
    """
    list_display = ["title_en", "title_de", "url",
                    "suburl", "favicon", "status", "personal"]
    ordering = ['status', 'title_de', 'title_en']
    actions = [regenerate]
