1 from django import forms
2 from django.conf import settings
3 from django.contrib import admin
5 from philo.admin.base import COLLAPSE_CLASSES, TreeEntityAdmin
6 from philo.admin.forms.containers import *
7 from philo.admin.nodes import ViewAdmin
8 from philo.models.pages import Page, Template, Contentlet, ContentReference
11 class ContentletInline(admin.StackedInline):
15 formset = ContentletInlineFormSet
18 classes = ('collapse-open', 'collapse','open')
19 if 'grappelli' in settings.INSTALLED_APPS:
20 template = 'admin/philo/edit_inline/grappelli_tabular_container.html'
22 template = 'admin/philo/edit_inline/tabular_container.html'
25 class ContentReferenceInline(admin.StackedInline):
26 model = ContentReference
29 formset = ContentReferenceInlineFormSet
30 form = ContentReferenceForm
32 classes = ('collapse-open', 'collapse','open')
33 if 'grappelli' in settings.INSTALLED_APPS:
34 template = 'admin/philo/edit_inline/grappelli_tabular_container.html'
36 template = 'admin/philo/edit_inline/tabular_container.html'
39 class PageAdmin(ViewAdmin):
40 add_form_template = 'admin/philo/page/add_form.html'
43 'fields': ('title', 'template')
46 list_display = ('title', 'template')
47 list_filter = ('template',)
48 search_fields = ['title', 'contentlets__content']
49 inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines
51 def response_add(self, request, obj, post_url_continue='../%s/'):
52 # Shamelessly cribbed from django/contrib/auth/admin.py:143
53 if '_addanother' not in request.POST and '_popup' not in request.POST:
54 request.POST['_continue'] = 1
55 return super(PageAdmin, self).response_add(request, obj, post_url_continue)
58 class TemplateAdmin(TreeEntityAdmin):
59 prepopulated_fields = {'slug': ('name',)}
62 'fields': ('parent', 'name', 'slug')
65 'classes': COLLAPSE_CLASSES,
66 'fields': ('documentation',)
72 'classes': COLLAPSE_CLASSES,
73 'fields': ('mimetype',)
78 list_display = ('__unicode__', 'slug', 'get_path',)
81 admin.site.register(Page, PageAdmin)
82 admin.site.register(Template, TemplateAdmin)