"""Django admin interface for the content app.

you will not need the admin interface that often, many tasks can be resoved via
 the user frontend.
"""

from django.contrib import admin

from . import models


class PageTabularInline(admin.TabularInline):
    """ Displays the sub-pages of an page element. """
    fields = ('title_de', 'menu_name_de', "position",)
    model = models.Page
    sortable_field_name = "position"


class ArticleAdmin(admin.ModelAdmin):
    """ Admin interface for the news-articles. """
    prepopulated_fields = {"slug": ("headline_de",)}
    list_display = ('headline', 'category', 'date_created', 'author',)
    list_editable = ('category', 'author')


class CategoryAdmin(admin.ModelAdmin):
    """ Admin interface for categories of the news-aricles. """
    list_display = ['name', 'slug', 'description']
    list_display_links = ('name', 'slug',)
    prepopulated_fields = {'slug': ('name_de',)}


class PageAdmin(admin.ModelAdmin):
    """
    Admin interface for static pages that can contain HTML or PDF Content.
    """
    prepopulated_fields = {"slug": ('menu_name_de',)}
    inlines = [PageTabularInline, ]
    list_display = ('position', 'menu_name', 'title', 'parent', 'path',)
    list_display_links = ('menu_name', 'title',)
    list_editable = ('position',)
    list_filter = ('parent',)
    search_fields = ('menu_name_de', 'title_de',)
    fieldsets = (
        ('Deutsch', {
            'fields': ('menu_name_de', 'title_de', 'description_de', 'pdf_de',
                       'content_de',),
            'classes': ('grp-collapse grp-open',),
        }),
        ('English', {
            'fields': ('menu_name_en', 'title_en', 'description_en', 'pdf_en',
                       'content_en'),
            'classes': ('grp-collapse grp-closed',),
        }),
        ('Meta Data', {
            'fields': (
                'content_type', 'slug', ('parent', 'position'),
                'status', 'template',
            )
        }),
    )


admin.site.register(models.Article, ArticleAdmin)
admin.site.register(models.Page, PageAdmin)
admin.site.register(models.Category, CategoryAdmin)
