1 from django.conf import settings
2 from django.contrib import admin
3 from django import forms
4 from philo.admin.base import COLLAPSE_CLASSES, TreeAdmin
5 from philo.admin.nodes import ViewAdmin
6 from philo.models.pages import Page, Template, Contentlet, ContentReference
7 from philo.admin.forms.containers import *
10 class ContentletInline(admin.StackedInline):
14 formset = ContentletInlineFormSet
17 classes = ('collapse-open', 'collapse','open')
18 if 'grappelli' in settings.INSTALLED_APPS:
19 template = 'admin/philo/edit_inline/grappelli_tabular_container.html'
21 template = 'admin/philo/edit_inline/tabular_container.html'
24 class ContentReferenceInline(admin.StackedInline):
25 model = ContentReference
28 formset = ContentReferenceInlineFormSet
29 form = ContentReferenceForm
31 classes = ('collapse-open', 'collapse','open')
32 if 'grappelli' in settings.INSTALLED_APPS:
33 template = 'admin/philo/edit_inline/grappelli_tabular_container.html'
35 template = 'admin/philo/edit_inline/tabular_container.html'
38 class PageAdmin(ViewAdmin):
39 add_form_template = 'admin/philo/page/add_form.html'
42 'fields': ('title', 'template')
45 list_display = ('title', 'template')
46 list_filter = ('template',)
47 search_fields = ['title', 'contentlets__content']
48 inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines
50 def response_add(self, request, obj, post_url_continue='../%s/'):
51 # Shamelessly cribbed from django/contrib/auth/admin.py:143
52 if '_addanother' not in request.POST and '_popup' not in request.POST:
53 request.POST['_continue'] = 1
54 return super(PageAdmin, self).response_add(request, obj, post_url_continue)
57 class TemplateAdmin(TreeAdmin):
58 prepopulated_fields = {'slug': ('name',)}
61 'fields': ('parent', 'name', 'slug')
64 'classes': COLLAPSE_CLASSES,
65 'fields': ('documentation',)
71 'classes': COLLAPSE_CLASSES,
72 'fields': ('mimetype',)
77 list_display = ('__unicode__', 'slug', 'get_path',)
80 admin.site.register(Page, PageAdmin)
81 admin.site.register(Template, TemplateAdmin)