Removed backwards-compatibility for database template loader. Added VERSION information.
[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         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)
55
56
57 class TemplateAdmin(TreeAdmin):
58         prepopulated_fields = {'slug': ('name',)}
59         fieldsets = (
60                 (None, {
61                         'fields': ('parent', 'name', 'slug')
62                 }),
63                 ('Documentation', {
64                         'classes': COLLAPSE_CLASSES,
65                         'fields': ('documentation',)
66                 }),
67                 (None, {
68                         'fields': ('code',)
69                 }),
70                 ('Advanced', {
71                         'classes': COLLAPSE_CLASSES,
72                         'fields': ('mimetype',)
73                 }),
74         )
75         save_on_top = True
76         save_as = True
77         list_display = ('__unicode__', 'slug', 'get_path',)
78
79
80 admin.site.register(Page, PageAdmin)
81 admin.site.register(Template, TemplateAdmin)