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.admin.widgets import EmbedWidget
9 from philo.models.fields import TemplateField
10 from philo.models.pages import Page, Template, Contentlet, ContentReference
13 class ContainerInline(admin.StackedInline):
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 ContentletInline(ContainerInline):
26 formset = ContentletInlineFormSet
30 class ContentReferenceInline(ContainerInline):
31 model = ContentReference
32 formset = ContentReferenceInlineFormSet
33 form = ContentReferenceForm
36 class PageAdmin(ViewAdmin):
37 add_form_template = 'admin/philo/page/add_form.html'
40 'fields': ('title', 'template')
43 list_display = ('title', 'template')
44 list_filter = ('template',)
45 search_fields = ['title', 'contentlets__content']
46 inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines
48 def response_add(self, request, obj, post_url_continue='../%s/'):
49 # Shamelessly cribbed from django/contrib/auth/admin.py:143
50 if '_addanother' not in request.POST and '_popup' not in request.POST:
51 request.POST['_continue'] = 1
52 return super(PageAdmin, self).response_add(request, obj, post_url_continue)
55 class TemplateAdmin(TreeEntityAdmin):
56 prepopulated_fields = {'slug': ('name',)}
59 'fields': ('parent', 'name', 'slug')
62 'classes': COLLAPSE_CLASSES,
63 'fields': ('documentation',)
69 'classes': COLLAPSE_CLASSES,
70 'fields': ('mimetype',)
73 formfield_overrides = {
74 TemplateField: {'widget': EmbedWidget}
78 list_display = ('__unicode__', 'slug', 'get_path',)
81 admin.site.register(Page, PageAdmin)
82 admin.site.register(Template, TemplateAdmin)