Added basic docs for entities and attributes.
[philo.git] / admin / pages.py
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 *
8
9
10 class ContentletInline(admin.StackedInline):
11         model = Contentlet
12         extra = 0
13         max_num = 0
14         formset = ContentletInlineFormSet
15         form = ContentletForm
16         can_delete = False
17         classes = ('collapse-open', 'collapse','open')
18         if 'grappelli' in settings.INSTALLED_APPS:
19                 template = 'admin/philo/edit_inline/grappelli_tabular_container.html'
20         else:
21                 template = 'admin/philo/edit_inline/tabular_container.html'
22
23
24 class ContentReferenceInline(admin.StackedInline):
25         model = ContentReference
26         extra = 0
27         max_num = 0
28         formset = ContentReferenceInlineFormSet
29         form = ContentReferenceForm
30         can_delete = False
31         classes = ('collapse-open', 'collapse','open')
32         if 'grappelli' in settings.INSTALLED_APPS:
33                 template = 'admin/philo/edit_inline/grappelli_tabular_container.html'
34         else:
35                 template = 'admin/philo/edit_inline/tabular_container.html'
36
37
38 class PageAdmin(ViewAdmin):
39         add_form_template = 'admin/philo/page/add_form.html'
40         fieldsets = (
41                 (None, {
42                         'fields': ('title', 'template')
43                 }),
44         )
45         list_display = ('title', 'template')
46         list_filter = ('template',)
47         search_fields = ['title', 'contentlets__content']
48         inlines = [ContentletInline, ContentReferenceInline] + ViewAdmin.inlines
49
50
51 class TemplateAdmin(TreeAdmin):
52         prepopulated_fields = {'slug': ('name',)}
53         fieldsets = (
54                 (None, {
55                         'fields': ('parent', 'name', 'slug')
56                 }),
57                 ('Documentation', {
58                         'classes': COLLAPSE_CLASSES,
59                         'fields': ('documentation',)
60                 }),
61                 (None, {
62                         'fields': ('code',)
63                 }),
64                 ('Advanced', {
65                         'classes': COLLAPSE_CLASSES,
66                         'fields': ('mimetype',)
67                 }),
68         )
69         save_on_top = True
70         save_as = True
71         list_display = ('__unicode__', 'slug', 'get_path',)
72
73
74 admin.site.register(Page, PageAdmin)
75 admin.site.register(Template, TemplateAdmin)