Overrides TemplateField widget on admin container forms instead of on the ModelAdmin.
[philo.git] / philo / admin / pages.py
index fd8665b..4cdd37b 100644 (file)
@@ -2,18 +2,17 @@ from django import forms
 from django.conf import settings
 from django.contrib import admin
 
 from django.conf import settings
 from django.contrib import admin
 
-from philo.admin.base import COLLAPSE_CLASSES, TreeAdmin
+from philo.admin.base import COLLAPSE_CLASSES, TreeEntityAdmin
 from philo.admin.forms.containers import *
 from philo.admin.nodes import ViewAdmin
 from philo.admin.forms.containers import *
 from philo.admin.nodes import ViewAdmin
+from philo.admin.widgets import EmbedWidget
+from philo.models.fields import TemplateField
 from philo.models.pages import Page, Template, Contentlet, ContentReference
 
 
 from philo.models.pages import Page, Template, Contentlet, ContentReference
 
 
-class ContentletInline(admin.StackedInline):
-       model = Contentlet
+class ContainerInline(admin.StackedInline):
        extra = 0
        max_num = 0
        extra = 0
        max_num = 0
-       formset = ContentletInlineFormSet
-       form = ContentletForm
        can_delete = False
        classes = ('collapse-open', 'collapse','open')
        if 'grappelli' in settings.INSTALLED_APPS:
        can_delete = False
        classes = ('collapse-open', 'collapse','open')
        if 'grappelli' in settings.INSTALLED_APPS:
@@ -22,18 +21,16 @@ class ContentletInline(admin.StackedInline):
                template = 'admin/philo/edit_inline/tabular_container.html'
 
 
                template = 'admin/philo/edit_inline/tabular_container.html'
 
 
-class ContentReferenceInline(admin.StackedInline):
+class ContentletInline(ContainerInline):
+       model = Contentlet
+       formset = ContentletInlineFormSet
+       form = ContentletForm
+
+
+class ContentReferenceInline(ContainerInline):
        model = ContentReference
        model = ContentReference
-       extra = 0
-       max_num = 0
        formset = ContentReferenceInlineFormSet
        form = ContentReferenceForm
        formset = ContentReferenceInlineFormSet
        form = ContentReferenceForm
-       can_delete = False
-       classes = ('collapse-open', 'collapse','open')
-       if 'grappelli' in settings.INSTALLED_APPS:
-               template = 'admin/philo/edit_inline/grappelli_tabular_container.html'
-       else:
-               template = 'admin/philo/edit_inline/tabular_container.html'
 
 
 class PageAdmin(ViewAdmin):
 
 
 class PageAdmin(ViewAdmin):
@@ -55,7 +52,7 @@ class PageAdmin(ViewAdmin):
                return super(PageAdmin, self).response_add(request, obj, post_url_continue)
 
 
                return super(PageAdmin, self).response_add(request, obj, post_url_continue)
 
 
-class TemplateAdmin(TreeAdmin):
+class TemplateAdmin(TreeEntityAdmin):
        prepopulated_fields = {'slug': ('name',)}
        fieldsets = (
                (None, {
        prepopulated_fields = {'slug': ('name',)}
        fieldsets = (
                (None, {
@@ -73,6 +70,9 @@ class TemplateAdmin(TreeAdmin):
                        'fields': ('mimetype',)
                }),
        )
                        'fields': ('mimetype',)
                }),
        )
+       formfield_overrides = {
+               TemplateField: {'widget': EmbedWidget}
+       }
        save_on_top = True
        save_as = True
        list_display = ('__unicode__', 'slug', 'get_path',)
        save_on_top = True
        save_as = True
        list_display = ('__unicode__', 'slug', 'get_path',)