Source

gnocchi-cms / gnocchi / cms / admin.py

Full commit
from django.contrib import admin
from gnocchi.cms import settings, models, forms
from gnocchi.tools.admin import InlineAttributeAdmin

import os.path

class TemplateAdmin(admin.ModelAdmin):
    list_display = ('path', 'description',)
    class Media:
        css = {
            'all': (
                os.path.join(settings.CODEMIRROR, 'lib/codemirror.css'),
            )
        }
        js = (
            os.path.join(settings.CODEMIRROR, 'lib/codemirror.js'),
            os.path.join(settings.CODEMIRROR, 'mode/xml/xml.js'),
            os.path.join(settings.CODEMIRROR, 'mode/javascript/javascript.js'),
            os.path.join(settings.CODEMIRROR, 'mode/css/css.js'),
            os.path.join(settings.CODEMIRROR, 'mode/htmlmixed/htmlmixed.js'),
            'gnocchi/codemirror.js',
            'gnocchi/codemirror_template.js',
        )

admin.site.register(models.Template, TemplateAdmin)

class FragmentInline(admin.TabularInline):
    model = models.Fragment
    extra = 0

class PageAccessInline(admin.TabularInline):
    model = models.PageAccess
    extra = 0

class PageAdmin(admin.ModelAdmin):
    list_display = ('get_absolute_url', 'title', 'is_published', 'template', 'position',)
    list_filter = ('parent', 'is_published',)
    list_editable = ('is_published', 'order',)

    #form = forms.PageAdminForm

    class Media:
        js = (
            'ckeditor/ckeditor.js',
            'gnocchi/ckeditor_page.js',
            'gnocchi/admin_list_reorder.js',
        )
    fieldsets = (
        (None, {
            'fields': ('parent', 'path', 'is_published',),
        }),
        ('Content', {
            'fields': ('title', 'template', 'content',),
        }),
    )

    inlines = [
        FragmentInline,
        InlineAttributeAdmin,
        PageAccessInline,
    ]

admin.site.register(models.Page, PageAdmin)

class StyleSheetAdmin(admin.ModelAdmin):
    list_display = ('name', 'description',)
    class Media:
        css = {
            'all': (
                os.path.join(settings.CODEMIRROR, 'lib/codemirror.css'),
                os.path.join(settings.CODEMIRROR, 'theme/default.css'),
            )
        }
        js = (
            os.path.join(settings.CODEMIRROR, 'lib/codemirror.js'),
            os.path.join(settings.CODEMIRROR, 'mode/css/css.js'),
            'gnocchi/codemirror.js',
            'gnocchi/codemirror_stylesheet.js',
        )

admin.site.register(models.StyleSheet, StyleSheetAdmin)

class ContextVariableAdmin(admin.ModelAdmin):
    list_display = ('full_name', 'type', 'description', 'value',)
    list_filter = ('group', 'type',)

    fieldsets = (
        (None, {
            'fields': (
                ('group', 'name',),
                ('type', 'value',),
                'description',
            ),
        }),
    )
admin.site.register(models.ContextVariable, ContextVariableAdmin)