"""
Created on 19.09.2011

@author: christian
"""
# import stuff we need from django
from django.contrib import admin

from . import models


class PageTabularInline(admin.TabularInline):
    fields = ('title_de', 'menu_name_de', "position",)
    model = models.Page
    sortable_field_name = "position"


class ArticleAdmin(admin.ModelAdmin):
    prepopulated_fields = {"slug": ("headline_de",)}
    list_display = ('headline', 'category', 'date_created', 'author',)
    list_editable = ('category', 'author')


class CategoryAdmin(admin.ModelAdmin):
    list_display = ['name', 'slug', 'description']
    list_display_links = ('name', 'slug',)
    prepopulated_fields = {'slug': ('name_de',)}


class PageAdmin(admin.ModelAdmin):
    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', 'pdf_de', 'content_de',),
            'classes': ('grp-collapse grp-open',),
        }),
        ('English', {
            'fields': ('menu_name_en', 'title_en', 'pdf_en', 'content_en'),
            'classes': ('grp-collapse grp-closed',),
        }),
        ('Meta Data', {
            'fields': (
                'content_type', 'slug', ('parent', 'position'),
                'status', 'template',
            )
        }),
    )

    class Media(object):
        js = [
            '/static/grappelli/tinymce/jscripts/tiny_mce/tiny_mce.js',
            '/static/js/tinymce_setup.js',
        ]


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