gnocchi-cms / gnocchi / cms / admin.py

from django.contrib import admin
from gnocchi.cms import settings, models
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'),
                os.path.join(settings.CODEMIRROR, 'theme/default.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',)
    list_filter = ('parent', 'is_published',)
    list_editable = ('is_published',)

    class Media:
        js = (
            'ckeditor/ckeditor.js',
            'gnocchi/ckeditor_page.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, 'mode/css/css.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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.