Added AttributeInlineFormSet to force new Attribute instances to be run through the...
[philo.git] / admin / pages.py
1 from django.contrib import admin
2 from django import forms
3 from philo.admin.base import COLLAPSE_CLASSES
4 from philo.admin.nodes import ViewAdmin
5 from philo.models.pages import Page, Template, Contentlet, ContentReference
6 from philo.forms import ContentletInlineFormSet, ContentReferenceInlineFormSet, ContentletForm, ContentReferenceForm
7
8
9 class ContentletInline(admin.StackedInline):
10         model = Contentlet
11         extra = 0
12         max_num = 0
13         formset = ContentletInlineFormSet
14         form = ContentletForm
15         can_delete = False
16         template = 'admin/philo/edit_inline/tabular_container.html'
17
18
19 class ContentReferenceInline(admin.StackedInline):
20         model = ContentReference
21         extra = 0
22         max_num = 0
23         formset = ContentReferenceInlineFormSet
24         form = ContentReferenceForm
25         can_delete = False
26         template = 'admin/philo/edit_inline/tabular_container.html'
27
28
29 class PageAdmin(ViewAdmin):
30         add_form_template = 'admin/philo/page/add_form.html'
31         fieldsets = (
32                 (None, {
33                         'fields': ('title', 'template')
34                 }),
35         )
36         list_display = ('title', 'template')
37         list_filter = ('template',)
38         search_fields = ['title', 'contentlets__content']
39         inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines
40
41
42 class TemplateAdmin(admin.ModelAdmin):
43         prepopulated_fields = {'slug': ('name',)}
44         fieldsets = (
45                 (None, {
46                         'fields': ('parent', 'name', 'slug')
47                 }),
48                 ('Documentation', {
49                         'classes': COLLAPSE_CLASSES,
50                         'fields': ('documentation',)
51                 }),
52                 (None, {
53                         'fields': ('code',)
54                 }),
55                 ('Advanced', {
56                         'classes': COLLAPSE_CLASSES,
57                         'fields': ('mimetype',)
58                 }),
59         )
60         save_on_top = True
61         save_as = True
62         list_display = ('__unicode__', 'slug', 'get_path',)
63
64
65 admin.site.register(Page, PageAdmin)
66 admin.site.register(Template, TemplateAdmin)