Exemplo n.º 1
0
    def init_parent_folder(self, request):
        folder_id = request.GET.get('folder_id', None) or  \
            request.GET.get('parent') or request.POST.get('parent', None)
        reduce_levels = request.GET.get('reduce_levels', None) or request.POST.get('reduce_levels', None)
        if folder_id or reduce_levels:
            request.GET = request.GET.copy()
            try:
                del request.GET['folder_id']
            except KeyError:
                pass
            try:
                del request.GET['reduce_levels']
            except KeyError:
                pass

        if folder_id:
            parent_folder = get_object_or_404(FileNode, pk=folder_id, node_type=FileNode.FOLDER)
        else:
            parent_folder = FileNode.get_top_node()

        if reduce_levels:
            try:
                reduce_levels = int(reduce_levels)
            except ValueError:
                reduce_levels = None

        if not reduce_levels and not request.is_ajax() and parent_folder.level >= 0:
            self.reset_expanded_folders_pk(request)
            reduce_levels = parent_folder.level + 1

        set_request_attr(request, 'parent_folder', parent_folder)
        set_request_attr(request, 'reduce_levels', reduce_levels)
Exemplo n.º 2
0
 def change_view(self, request, object_id, extra_context=None):
     try:
         object_id = str(object_id)
         node = get_object_or_404(FileNode, pk=unquote(object_id))
     except ValueError:
         raise Http404
     set_request_attr(request, 'save_node', node)
     if not extra_context:
         extra_context = {}
     extra_context.update({'node': node,})
     return super(BaseFileNodeAdmin, self).change_view(\
         request, object_id, extra_context=extra_context)
Exemplo n.º 3
0
 def init_changelist_view_options(self, request):
     if 'thumbnail_size' in request.GET:
         request.GET = request.GET.copy()
         thumb_size_key = request.GET.get('thumbnail_size')
         del request.GET['thumbnail_size']
         if not thumb_size_key in app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES:
              thumb_size_key = None
         request.session['thumbnail_size'] = thumb_size_key
     thumb_size_key = request.session.get('thumbnail_size', 'default')
     set_request_attr(request, 'thumbnail_size', thumb_size_key)
     return {
         'thumbnail_sizes': app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES,
         'thumbnail_size_key': thumb_size_key
     }
Exemplo n.º 4
0
 def init_changelist_view_options(self, request):
     if 'thumbnail_size' in request.GET:
         request.GET = request.GET.copy()
         thumb_size_key = request.GET.get('thumbnail_size')
         del request.GET['thumbnail_size']
         if not thumb_size_key in app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES:
             thumb_size_key = None
         request.session['thumbnail_size'] = thumb_size_key
     thumb_size_key = request.session.get('thumbnail_size', 'default')
     set_request_attr(request, 'thumbnail_size', thumb_size_key)
     return {
         'thumbnail_sizes': app_settings.MEDIA_TREE_ADMIN_THUMBNAIL_SIZES,
         'thumbnail_size_key': thumb_size_key
     }
Exemplo n.º 5
0
 def _add_node_view(self, request, form_url='', extra_context=None, node_type=FileNode.FILE):
     self.init_parent_folder(request)
     parent_folder = self.get_parent_folder(request)
     if not extra_context:
         extra_context = {}
     extra_context.update({
         'node': parent_folder,
         'breadcrumbs_title': _('Add')
     })
     set_request_attr(request, 'save_node_type', node_type)
     response = super(FileNodeAdmin, self).add_view(request, form_url, extra_context)
     if isinstance(response, HttpResponseRedirect) and not parent_folder.is_top_node():
         return HttpResponseRedirect(reverse('admin:media_tree_filenode_folder_expand', 
             args=(parent_folder.pk,)))
     return response
Exemplo n.º 6
0
    def change_view(self, request, object_id, extra_context=None):
        node = get_object_or_404(FileNode, pk=unquote(object_id))
        set_request_attr(request, 'save_node', node)
        set_request_attr(request, 'save_node_type', node.node_type)
        if not extra_context:
            extra_context = {}
        extra_context.update({
            'node': node,
        })
        if node.is_folder():
            extra_context.update({
                'breadcrumbs_title': _('Change')
            })

        return super(FileNodeAdmin, self).change_view(request, object_id, extra_context=extra_context)
Exemplo n.º 7
0
    def change_view(self, request, object_id, extra_context=None):
        try:
            object_id = str(object_id)
            node = get_object_or_404(FileNode, pk=unquote(object_id))
        except ValueError:
            raise Http404
        set_request_attr(request, 'save_node', node)
        set_request_attr(request, 'save_node_type', node.node_type)
        if not extra_context:
            extra_context = {}
        extra_context.update({
            'node': node,
        })
        if node.is_folder():
            extra_context.update({
                'breadcrumbs_title': capfirst(_('change'))
            })

        return super(FileNodeAdmin, self).change_view(request, object_id, extra_context=extra_context)
Exemplo n.º 8
0
    def change_view(self, request, object_id, extra_context=None):
        try:
            object_id = str(object_id)
            node = get_object_or_404(FileNode, pk=unquote(object_id))
        except ValueError:
            raise Http404
        set_request_attr(request, 'save_node', node)
        set_request_attr(request, 'save_node_type', node.node_type)
        if not extra_context:
            extra_context = {}
        extra_context.update({
            'node': node,
        })
        if node.is_folder():
            extra_context.update({'breadcrumbs_title': capfirst(_('change'))})

        return super(FileNodeAdmin,
                     self).change_view(request,
                                       object_id,
                                       extra_context=extra_context)
Exemplo n.º 9
0
 def _add_node_view(self,
                    request,
                    form_url='',
                    extra_context=None,
                    node_type=FileNode.FILE):
     self.init_parent_folder(request)
     parent_folder = self.get_parent_folder(request)
     if not extra_context:
         extra_context = {}
     extra_context.update({
         'node': parent_folder,
         'breadcrumbs_title': _('Add')
     })
     set_request_attr(request, 'save_node_type', node_type)
     response = super(FileNodeAdmin, self).add_view(request, form_url,
                                                    extra_context)
     if isinstance(response, HttpResponseRedirect
                   ) and parent_folder and not parent_folder.is_top_node():
         return HttpResponseRedirect(
             reverse('admin:media_tree_filenode_folder_expand',
                     args=(parent_folder.pk, )))
     return response
Exemplo n.º 10
0
    def init_parent_folder(self, request):
        folder_id = request.GET.get('folder_id', None) or  \
            request.GET.get('parent') or request.POST.get('parent', None)
        reduce_levels = request.GET.get(
            'reduce_levels', None) or request.POST.get('reduce_levels', None)
        if folder_id or reduce_levels:
            request.GET = request.GET.copy()
            try:
                del request.GET['folder_id']
            except KeyError:
                pass
            try:
                del request.GET['reduce_levels']
            except KeyError:
                pass

        if folder_id:
            parent_folder = get_object_or_404(FileNode,
                                              pk=folder_id,
                                              node_type=FileNode.FOLDER)
        else:
            parent_folder = FileNode.get_top_node()

        if reduce_levels:
            try:
                reduce_levels = int(reduce_levels)
            except ValueError:
                reduce_levels = None

        if not reduce_levels and not request.is_ajax(
        ) and parent_folder.level >= 0:
            self.reset_expanded_folders_pk(request)
            reduce_levels = parent_folder.level + 1

        set_request_attr(request, 'parent_folder', parent_folder)
        set_request_attr(request, 'reduce_levels', reduce_levels)