Added contentlet unicode and fixed container context bug.
[philo.git] / admin.py
index af97bde..5737041 100644 (file)
--- a/admin.py
+++ b/admin.py
@@ -7,7 +7,7 @@ from django.utils.translation import ugettext as _
 from django.utils.safestring import mark_safe
 from django.utils.html import escape
 from django.utils.text import truncate_words
-from models import *
+from philo.models import *
 from django.core.exceptions import ValidationError, ObjectDoesNotExist
 from validators import TreeParentValidator, TreePositionValidator
 
@@ -41,10 +41,12 @@ class CollectionMemberInline(admin.TabularInline):
        extra = 1
        classes = ('collapse-closed',)
        allow_add = True
+       fields = ('member_content_type', 'member_object_id', 'index',)
 
 
 class CollectionAdmin(admin.ModelAdmin):
        inlines = [CollectionMemberInline]
+       list_display = ('name', 'description', 'get_count')
 
 
 class TreeForm(forms.ModelForm):
@@ -52,10 +54,13 @@ class TreeForm(forms.ModelForm):
                super(TreeForm, self).__init__(*args, **kwargs)
                instance = self.instance
                instance_class=self.get_instance_class()
-               try:
-                       self.fields['parent'].queryset = instance_class.objects.exclude(id=instance.id)
-               except ObjectDoesNotExist:
-                       pass
+               
+               if instance_class is not None:
+                       try:
+                               self.fields['parent'].queryset = instance_class.objects.exclude(id=instance.id)
+                       except ObjectDoesNotExist:
+                               pass
+                       
                self.fields['parent'].validators = [TreeParentValidator(*self.get_validator_args())]
        
        def get_instance_class(self):
@@ -132,7 +137,7 @@ class ModelLookupWidget(forms.TextInput):
 
 class NodeForm(TreeForm):
        def get_instance_class(self):
-               return self.instance.node_ptr.__class__
+               return Node
                
        def get_validator_args(self):
                return [self.instance, 'instance']
@@ -227,6 +232,8 @@ class PageAdmin(EntityAdmin):
                for container_name, container_content_type in contentreference_containers:
                        if ('contentreference_container_%s' % container_name) in form.cleaned_data:
                                content = form.cleaned_data[('contentreference_container_%s' % container_name)]
+                               if content == None:
+                                       continue
                                contentreference, created = page.contentreferences.get_or_create(name=container_name, defaults={'content': content})
                                if not created:
                                        contentreference.content = content