from sets.admin import *
from .models import *
from django.contrib import admin
from django.utils.translation import gettext as _

class Admin_StaticPage(Admin_Trans_BaseModelViewPage):

    fieldsets = [
        (None, {
            'classes': ['wide'],
            'fields': ('name',
                       'url',
                       'title', 'description', 'text',
                       'picture',
                       'order',
                       )
        }),
        (_('Настройки'), {
            'classes': ['wide', 'collapse'],
            'fields': (
                'FAQ_title',
            )
        }),
        ('SEO', {
            'classes': ['wide', 'collapse'],
            'fields': (
                'seo_title', 'seo_description', 'seo_keywords', 'seo_text',
           )
        }),
    ]


    list_display = [
        'id',
        'name', 'url', 'title',
        'order', 'modifiedDT', 'createDT'
    ]

    list_display_links = ['id']
    list_editable = ['order']

    list_filter = ['modifiedDT', 'createDT']
    search_fields = ['name', 'title']
    # filter_horizontal = ['options']

    def has_delete_permission(self, request, obj=None):
        if request.user.is_superuser:
           return True

        if obj.url in ('main', 'spec_technics', 'works'):
            return False

admin.site.register(StaticPage,Admin_StaticPage)

# class Admin_Block(Admin_Trans_BaseModel):
#     pass
#
#     # def get_fieldsets(self, request, obj=None):
#     #     fieldsets = super(type(self), self).get_fieldsets(request, obj)
#     #     if not request.user.is_superuser and obj.name and obj.name in ('About US', 'machines', 'works'):
#     #         fieldsets[0][1]['fields'].pop(0)
#     #     fieldsets.insert(
#     #         1, (_('Контент'), {
#     #             'classes': ['wide'],
#     #             'fields': (
#     #                 'title', 'description', 'text',
#     #                 'picture',
#     #             )
#     #
#     #         })
#     #     )
#     #     return fieldsets
#     #
#     # def has_delete_permission(self, request, obj=None):
#     #     if request.user.is_superuser:
#     #        return True
#     #
#     #     if obj.name in ('About US', 'machines', 'works'):
#     #         return False
#
# admin.site.register(Block,Admin_Block)

class Admin_Option(Admin_Trans_BaseModel):

    # def get_fieldsets(self, request, obj=None):
    #     fieldsets = super(type(self), self).get_fieldsets(request, obj)
    #     fieldsets.insert(
    #         1, ('Контент', {
    #             'classes': ['wide'],
    #             'fields': (
    #                 'opt_type', 'prefix', 'value', 'picture'
    #             )
    #
    #         })
    #     )
    #     return fieldsets


    fieldsets = [
        (_('Контент'), {
            'classes': ['wide'],
            'fields': (
               'name', 'opt_type', 'prefix', 'value', 'picture'
            )
        }),
    ]

    list_display = ['image_thumb', 'opt_type', 'name', 'value', 'prefix']
    list_editable = ['value', 'prefix']
    list_filter = ['opt_type']

admin.site.register(Option,Admin_Option)
