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