def admin_preview(self, node, icons_only=False):
        request = get_current_request()
        template = 'admin/media_tree/filenode/includes/preview.html'
        thumbnail_backend = get_media_backend(handles_media_types=(node.media_type,), supports_thumbnails=True)
        if not thumbnail_backend:
            icons_only = True
            template = 'media_tree/filenode/includes/icon.html'
            # TODO SPLIT preview.html in two: one that doesn't need media backend!

        context = {
            'node': node,
            'preview_file': node.get_icon_file() if icons_only else node.get_preview_file(),
            'class': 'collapsed' if node.is_folder() else '',
        }

        if not icons_only:
            thumb_size_key = get_request_attr(request, 'thumbnail_size') or 'default'
            context['thumbnail_size'] = app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES[thumb_size_key]
            thumb = thumbnail_backend.get_thumbnail(context['preview_file'], {'size': context['thumbnail_size']})
            context['thumb'] = thumb

        preview = render_to_string(template, context)

        if node.is_folder():
            preview += render_to_string(template, {
                'node': node,
                'preview_file': node.get_preview_file(default_name='_folder_expanded'),
                'class': 'expanded'
            })
        return preview
    def admin_preview(self, node, icons_only=False):
        request = get_current_request()
        template = 'admin/media_tree/filenode/includes/preview.html'
        if not get_media_backend():
            icons_only = True
            template = 'media_tree/filenode/includes/icon.html'
            # TODO SPLIT preview.html in two: one that doesn't need media backend!

        thumb_size_key = get_request_attr(request,
                                          'thumbnail_size') or 'default'

        preview = render_to_string(
            template, {
                'node':
                node,
                'preview_file':
                node.get_icon_file()
                if icons_only else node.get_preview_file(),
                'class':
                'collapsed' if node.is_folder() else '',
                'thumbnail_size':
                app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES[thumb_size_key]
            })
        if node.is_folder():
            preview += render_to_string(
                template, {
                    'node':
                    node,
                    'preview_file':
                    node.get_preview_file(default_name='_folder_expanded'),
                    'class':
                    'expanded'
                })
        return preview
 def browse_controls(self, node):
     state = ''
     if node.is_folder():
         request = get_current_request()
         state = 'expanded' if self.folder_is_open(request, node) else 'collapsed'
     return '<span id="%s" class="node browse-controls %s %s">%s%s</span>' %  \
         (self.anchor_name(node), 'folder' if node.is_folder() else 'file',
         state, self.expand_collapse(node), self.admin_link(node, True))
 def browse_controls(self, node):
     state = ''
     if node.is_folder():
         request = get_current_request()
         state = 'expanded' if self.folder_is_open(request,
                                                   node) else 'collapsed'
     return '<span id="%s" class="node browse-controls %s %s">%s%s</span>' %  \
         (self.anchor_name(node), 'folder' if node.is_folder() else 'file',
         state, self.expand_collapse(node), self.admin_link(node, True))
 def expand_collapse(self, node):
     request = get_current_request()
     if not is_search_request(request):
         rel = 'parent:%i' % node.parent_id if node.parent_id else ''
     else:
         rel = ''
     if hasattr(node, 'reduce_levels'):
         qs_params = {'reduce_levels': node.reduce_levels}
     else:
         qs_params = None
     if node.is_folder():
         empty = ' empty' if node.get_children().count() == 0 else ''
         return '<a href="%s" class="folder-toggle%s" rel="%s"><span>%s</span></a>' %  \
             (node.get_admin_url(qs_params), empty, rel, '+')
     else:
         return '<a class="folder-toggle dummy" rel="%s">&nbsp;</a>' % (rel,)
 def expand_collapse(self, node):
     request = get_current_request()
     if not is_search_request(request):
         rel = 'parent:%i' % node.parent_id if node.parent_id else ''
     else:
         rel = ''
     if hasattr(node, 'reduce_levels'):
         qs_params = {'reduce_levels': node.reduce_levels}
     else:
         qs_params = None
     if node.is_folder():
         empty = ' empty' if node.get_children().count() == 0 else ''
         return '<a href="%s" class="folder-toggle%s" rel="%s"><span>%s</span></a>' %  \
             (node.get_admin_url(qs_params), empty, rel, '+')
     else:
         return '<a class="folder-toggle dummy" rel="%s">&nbsp;</a>' % (
             rel, )
    def get_query_set(self, request=None):

        # request arg was added in django r16144 (after 1.3)
        if request is not None and django.VERSION >= (1, 4):
            qs = super(SimpleFileNodeChangeList, self).get_query_set(request)
        else:
            qs = super(SimpleFileNodeChangeList, self).get_query_set()
            request = get_current_request()

        # Pagination should be disabled by default, since it interferes
        # with expanded folders and might display them partially.
        # However, filtered results are presented as a flat list and 
        # should be paginated.
        pagination_enabled = self.is_filtered(request)
        if not pagination_enabled:
            self.show_all = True

        return qs.order_by('file')
示例#8
0
    def admin_preview(self, node, icons_only=False):
        request = get_current_request()
        template = 'admin/media_tree/filenode/includes/preview.html'
        thumbnail_backend = get_media_backend(
            handles_media_types=(node.media_type, ), supports_thumbnails=True)
        if not thumbnail_backend:
            icons_only = True
            template = 'media_tree/filenode/includes/icon.html'
            # TODO SPLIT preview.html in two: one that doesn't need media backend!

        context = {
            'node':
            node,
            'preview_file':
            node.get_icon_file() if icons_only else node.get_preview_file(),
            'class':
            'collapsed' if node.is_folder() else '',
        }

        if not icons_only:
            thumb_size_key = get_request_attr(request,
                                              'thumbnail_size') or 'default'
            context[
                'thumbnail_size'] = app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES[
                    thumb_size_key]
            thumb = thumbnail_backend.get_thumbnail(
                context['preview_file'], {'size': context['thumbnail_size']})
            context['thumb'] = thumb

        preview = render_to_string(template, context)

        if node.is_folder():
            preview += render_to_string(
                template, {
                    'node':
                    node,
                    'preview_file':
                    node.get_preview_file(default_name='_folder_expanded'),
                    'class':
                    'expanded'
                })
        return preview
    def get_query_set(self, request=None):

        # request arg was added in django r16144 (after 1.3)
        if request is not None and django.VERSION >= (1, 4):
            qs = super(MPTTChangeList, self).get_query_set(request)
        else:
            qs = super(MPTTChangeList, self).get_query_set()
            request = get_current_request()

        # Pagination should be disabled by default, since it interferes
        # with expanded folders and might display them partially.
        # However, filtered results are presented as a flat list and 
        # should be paginated.
        pagination_enabled = self.is_filtered(request)
        if not pagination_enabled:
            self.show_all = True

        # filter by currently expanded folders if list is not filtered
        # by extension or media_type
        self.parent_folder = self.model_admin.get_parent_folder(request)
        if self.parent_folder and not pagination_enabled:
            if self.parent_folder.is_top_node():
                expanded_folders_pk = \
                    self.model_admin.get_expanded_folders_pk(request)
                if expanded_folders_pk:
                    qs = qs.filter(
                        models.Q(parent=None) | 
                        models.Q(parent__pk__in=expanded_folders_pk))
                else:
                    qs = qs.filter(parent=None)
            else:
                qs = qs.filter(parent=self.parent_folder)

        if request is not None and self.is_filtered(request):
            return qs.order_by('name')
        else:
            # always order by (tree_id, left)
            tree_id = qs.model._mptt_meta.tree_id_attr
            left = qs.model._mptt_meta.left_attr
            return qs.order_by(tree_id, left)
示例#10
0
    def get_queryset(self, request=None):

        # request arg was added in django r16144 (after 1.3)
        if request is not None and django.VERSION >= (1, 4):
            qs = super(MPTTChangeList, self).get_queryset(request)
        else:
            qs = super(MPTTChangeList, self).get_queryset()
            request = get_current_request()

        # Pagination should be disabled by default, since it interferes
        # with expanded folders and might display them partially.
        # However, filtered results are presented as a flat list and
        # should be paginated.
        pagination_enabled = self.is_filtered(request)
        if not pagination_enabled:
            self.show_all = True

        # filter by currently expanded folders if list is not filtered by extension or media_type
        self.parent_folder = self.model_admin.get_parent_folder(request)
        if self.parent_folder and not pagination_enabled:
            if self.parent_folder.is_top_node():
                expanded_folders_pk = self.model_admin.get_expanded_folders_pk(
                    request)
                if expanded_folders_pk:
                    qs = qs.filter(
                        models.Q(parent=None)
                        | models.Q(parent__pk__in=expanded_folders_pk))
                else:
                    qs = qs.filter(parent=None)
            else:
                qs = qs.filter(parent=self.parent_folder)

        if request is not None and self.is_filtered(request):
            return qs.order_by('name')
        else:
            # always order by (tree_id, left)
            tree_id = qs.model._mptt_meta.tree_id_attr
            left = qs.model._mptt_meta.left_attr
            return qs.order_by(tree_id, left)
示例#11
0
    def admin_preview(self, node, icons_only=False):
        request = get_current_request()
        template = 'admin/media_tree/filenode/includes/preview.html'
        if not get_media_backend():
            icons_only = True
            template = 'media_tree/filenode/includes/icon.html'
            # TODO SPLIT preview.html in two: one that doesn't need media backend!
        
        thumb_size_key = get_request_attr(request, 'thumbnail_size') or 'default'

        preview = render_to_string(template, {
            'node': node,
            'preview_file': node.get_icon_file() if icons_only else node.get_preview_file(),
            'class': 'collapsed' if node.is_folder() else '',
            'thumbnail_size': app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES[thumb_size_key]
        })
        if node.is_folder():
            preview += render_to_string(template, {
                'node': node,
                'preview_file': node.get_preview_file(default_name='_folder_expanded'),
                'class': 'expanded'
            })
        return preview