# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from cms.extensions import PageExtensionAdmin, TitleExtensionAdmin
from django.conf import settings
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from .forms import TitleMetaAdminForm
from .models import GenericMetaAttribute, PageMeta, TitleMeta


class GenericAttributePageInline(admin.TabularInline):
    model = GenericMetaAttribute
    fields = ('page', 'attribute', 'name', 'value')


class GenericAttributeTitleInline(admin.TabularInline):
    model = GenericMetaAttribute
    fields = ('title', 'attribute', 'name', 'value')


class PageMetaAdmin(PageExtensionAdmin):
    raw_id_fields = ('og_author',)
    inlines = (GenericAttributePageInline,)
    fieldsets = (
        (None, {'fields': ('image',)}),
        (_('OpenGraph'), {
            'fields': (
                'og_type', ('og_author', 'og_author_url', 'og_author_fbid'),
                ('og_publisher', 'og_app_id', 'fb_pages')
            ),
            'classes': ('collapse',)
        }),
        (_('Twitter Cards'), {
            'fields': ('twitter_type', 'twitter_author'),
            'classes': ('collapse',)
        }),
        (_('Google+ Snippets'), {
            'fields': ('gplus_type', 'gplus_author'),
            'classes': ('collapse',)
        }),
    )

    class Media:
        css = {
            'all': ('%sdjangocms_page_meta/css/%s' % (
                settings.STATIC_URL, 'djangocms_page_meta_admin.css'),)
        }

    def get_model_perms(self, request):
        """
        Return empty perms dict thus hiding the model from admin index.
        """
        return {}

admin.site.register(PageMeta, PageMetaAdmin)


class TitleMetaAdmin(TitleExtensionAdmin):
    form = TitleMetaAdminForm
    inlines = (GenericAttributeTitleInline,)

    class Media:
        css = {
            'all': ('%sdjangocms_page_meta/css/%s' % (
                settings.STATIC_URL, 'djangocms_page_meta_admin.css'),)
        }

    def get_model_perms(self, request):
        """
        Return empty perms dict thus hiding the model from admin index.
        """
        return {}

admin.site.register(TitleMeta, TitleMetaAdmin)

@@ -91,16 +91,48 @@
 terals%0A%0A
+from cms.admin import pageadmin%0A
 from cms
@@ -414,16 +414,55 @@
 leMeta%0A%0A
+admin.site.unregister(pageadmin.Page)%0A%0A
 %0Aclass G
@@ -2303,20 +2303,468 @@
 ta, TitleMetaAdmin)%0A
+%0A%0Aclass PageAdmin(pageadmin.PageAdmin):%0A    %22%22%22%0A    Remove the meta description field from the page admin (we have this in django-cms-meta)%0A    %22%22%22%0A    def get_form(self, request, obj=None, **kwargs):%0A        form = super(PageAdmin, self).get_form(request, obj, **kwargs)%0A        try:%0A            del form.base_fields%5B'meta_description'%5D%0A        except KeyError:%0A            pass%0A%0A        return form%0Aadmin.site.register(pageadmin.Page, PageAdmin)%0A

Remove description field from page admin