# -*- coding: utf-8 -*-
from django.contrib import admin
from django.contrib.auth.models import User
from parler.admin import TranslatableAdmin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin

from portal.models import Profile, Announcement, DownloadSection, DownloadFile, Information, InformationSection


class ProfileInline(admin.StackedInline):
    model = Profile
    can_delete = False


class UserAdmin(BaseUserAdmin):
    inlines = [ProfileInline]
    fieldsets = (
        (None, {'fields': ('username', 'email', 'password')}),
        ('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups')}),
    )


admin.site.unregister(User)
admin.site.register(User, UserAdmin)


@admin.register(Announcement)
class AnnouncementAdmin(TranslatableAdmin):
    list_display = ('title', 'published')
    list_filter = ('groups',)
    filter_horizontal = ('groups',)
    readonly_fields = ('informed_users',)
    fieldsets = (
        (None, {'fields': ('title', 'published', 'image', 'cropping')}),
        ('Permissions', {'fields': ('groups',)}),
        ('Information', {'fields': ('informed_users',)}),
    )


@admin.register(Information)
class InformationAdmin(TranslatableAdmin):
    list_display = ('title', 'published')
    list_filter = ('groups',)
    filter_horizontal = ('groups',)


@admin.register(InformationSection)
class InformationSectionAdmin(TranslatableAdmin):
    pass


@admin.register(DownloadSection)
class DownloadSectionAdmin(TranslatableAdmin):
    list_display = ('title', 'ordering')
    list_editable = ['ordering']


@admin.register(DownloadFile)
class DownloadFileAdmin(TranslatableAdmin):
    list_display = ('label', 'ordering')
    list_editable = ['ordering']
    list_filter = ('section', 'groups')
    filter_horizontal = ('groups',)
