# Path: media_tree/contrib/legacy_mptt_support/forms.py
# class MPTTAdminForm(forms.ModelForm):
#     """
#     A form which validates that the chosen parent for a node isn't one of
#     it's descendants.
#     """
#     def clean(self):
#         cleaned_data = super(MPTTAdminForm, self).clean()
#         opts = self._meta.model._mptt_meta
#         parent = cleaned_data.get(opts.parent_attr)
#         if self.instance and parent:
#             if parent.is_descendant_of(self.instance, include_self=True):
#                 if opts.parent_attr not in self._errors:
#                     self._errors[opts.parent_attr] = forms.util.ErrorList()
#                 self._errors[opts.parent_attr].append('Invalid parent')
#                 del self.cleaned_data[opts.parent_attr]
#         return cleaned_data
# 
# class TreeNodeChoiceField(forms.ModelChoiceField):
#     """A ModelChoiceField for tree nodes."""
#     def __init__(self, queryset, *args, **kwargs):
#         self.level_indicator = kwargs.pop('level_indicator', u'---')
#         if kwargs.get('required', True) and not 'empty_label' in kwargs:
#             kwargs['empty_label'] = None
# 
#         # if a queryset is supplied, enforce ordering
#         if hasattr(queryset, 'model'):
#             mptt_opts = queryset.model._mptt_meta
#             queryset = queryset.order_by(mptt_opts.tree_id_attr, mptt_opts.left_attr)
# 
#         super(TreeNodeChoiceField, self).__init__(queryset, *args, **kwargs)
# 
#     def label_from_instance(self, obj):
#         """
#         Creates labels which represent the tree level of each node when
#         generating option labels.
#         """
#         level = getattr(obj, obj._mptt_meta.level_attr)
#         level_indicator = mark_safe(conditional_escape(self.level_indicator) * level)
#         return mark_safe(u'%s %s' % (level_indicator, conditional_escape(smart_unicode(obj))))


import django
from django.conf import settings
from django.contrib.admin.views.main import ChangeList
from django.contrib.admin.options import ModelAdmin, IncorrectLookupParameters
from django import template
from django.contrib.admin import helpers
from django.core.exceptions import PermissionDenied
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.utils.encoding import force_unicode
from media_tree.contrib.legacy_mptt_support.forms import MPTTAdminForm, TreeNodeChoiceField
        from mptt.models import MPTTModel
            from django.contrib.admin.views.main import ERROR_FLAG
        from feincms.admin import editor
                'media': media,
                'has_add_permission': self.has_add_permission(request),
                'root_path': self.admin_site.root_path,
                'app_label': app_label,
                'action_form': action_form,
                'actions_on_top': self.actions_on_top,
                'actions_on_bottom': self.actions_on_bottom,
            }
            context.update(extra_context or {})
            context_instance = template.RequestContext(request, current_app=self.admin_site.name)
            return render_to_response(self.change_list_template or [
                'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
                'admin/%s/change_list.html' % app_label,
                'admin/change_list.html'
            ], context, context_instance=context_instance)


if getattr(settings, 'MPTT_USE_FEINCMS', True):
    try:
    except ImportError:
        pass
    else:
        __all__ = tuple(list(__all__) + ['FeinCMSModelAdmin'])
        
        class FeinCMSModelAdmin(editor.TreeEditor):
            """
            A ModelAdmin to add changelist tree view and editing capabilities.
            Requires FeinCMS to be installed.
            """
            

# Path: media_tree/contrib/legacy_mptt_support/forms.py
# class MPTTAdminForm(forms.ModelForm):
#     """
#     A form which validates that the chosen parent for a node isn't one of
#     it's descendants.
#     """
#     def clean(self):
#         cleaned_data = super(MPTTAdminForm, self).clean()
#         opts = self._meta.model._mptt_meta
#         parent = cleaned_data.get(opts.parent_attr)
#         if self.instance and parent:
#             if parent.is_descendant_of(self.instance, include_self=True):
#                 if opts.parent_attr not in self._errors:
#                     self._errors[opts.parent_attr] = forms.util.ErrorList()
#                 self._errors[opts.parent_attr].append('Invalid parent')
#                 del self.cleaned_data[opts.parent_attr]
#         return cleaned_data
# 
# class TreeNodeChoiceField(forms.ModelChoiceField):
#     """A ModelChoiceField for tree nodes."""
#     def __init__(self, queryset, *args, **kwargs):
#         self.level_indicator = kwargs.pop('level_indicator', u'---')
#         if kwargs.get('required', True) and not 'empty_label' in kwargs:
#             kwargs['empty_label'] = None
# 
#         # if a queryset is supplied, enforce ordering
#         if hasattr(queryset, 'model'):
#             mptt_opts = queryset.model._mptt_meta
#             queryset = queryset.order_by(mptt_opts.tree_id_attr, mptt_opts.left_attr)
# 
#         super(TreeNodeChoiceField, self).__init__(queryset, *args, **kwargs)
# 
#     def label_from_instance(self, obj):
#         """
#         Creates labels which represent the tree level of each node when
#         generating option labels.
#         """
#         level = getattr(obj, obj._mptt_meta.level_attr)
#         level_indicator = mark_safe(conditional_escape(self.level_indicator) * level)
#         return mark_safe(u'%s %s' % (level_indicator, conditional_escape(smart_unicode(obj))))


# Path: media_tree/contrib/legacy_mptt_support/admin.py
import django
from django.conf import settings
from django.contrib.admin.views.main import ChangeList
from django.contrib.admin.options import ModelAdmin, IncorrectLookupParameters
from django import template
from django.contrib.admin import helpers
from django.core.exceptions import PermissionDenied
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.utils.encoding import force_unicode
from media_tree.contrib.legacy_mptt_support.forms import MPTTAdminForm, TreeNodeChoiceField
        from mptt.models import MPTTModel
            from django.contrib.admin.views.main import ERROR_FLAG
        from feincms.admin import editor

                'media': media,
                'has_add_permission': self.has_add_permission(request),
                'root_path': self.admin_site.root_path,
                'app_label': app_label,
                'action_form': action_form,
                'actions_on_top': self.actions_on_top,
                'actions_on_bottom': self.actions_on_bottom,
            }
            context.update(extra_context or {})
            context_instance = template.RequestContext(request, current_app=self.admin_site.name)
            return render_to_response(self.change_list_template or [
                'admin/%s/%s/change_list.html' % (app_label, opts.object_name.lower()),
                'admin/%s/change_list.html' % app_label,
                'admin/change_list.html'
            ], context, context_instance=context_instance)


if getattr(settings, 'MPTT_USE_FEINCMS', True):
    try:
    except ImportError:
        pass
    else:
        __all__ = tuple(list(__all__) + ['FeinCMSModelAdmin'])
        
        class FeinCMSModelAdmin(editor.TreeEditor):
            """
            A ModelAdmin to add changelist tree view and editing capabilities.
            Requires FeinCMS to be installed.
            """
            

            form = MPTTAdminForm