from sets.admin import *
from .models import *
from django.contrib import admin

class Admin_StaticPage(Admin_Trans_BaseModelViewPage):

    fieldsets = [
        (None, {
            'classes': ['wide'],
            'fields': ('name',
                       'url',
                       'title', 'description', 'text',
                       'picture',
                       'order',
                       )
        }),
        ('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_BaseBlock):

    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_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

admin.site.register(Option,Admin_Option)
