当前位置: 首页>>代码示例>>Python>>正文


Python FileNode.get_top_node方法代码示例

本文整理汇总了Python中media_tree.models.FileNode.get_top_node方法的典型用法代码示例。如果您正苦于以下问题:Python FileNode.get_top_node方法的具体用法?Python FileNode.get_top_node怎么用?Python FileNode.get_top_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在media_tree.models.FileNode的用法示例。


在下文中一共展示了FileNode.get_top_node方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_actions_context

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
def get_actions_context(modeladmin):
    return {
        'node': FileNode.get_top_node(), # TODO get current folder
        "opts": modeladmin.model._meta,
        "app_label": modeladmin.model._meta.app_label,
        'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
    }
开发者ID:cassydius,项目名称:django-media-tree,代码行数:9,代码来源:utils.py

示例2: init_parent_folder

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
    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)
开发者ID:quinode,项目名称:django-media-tree,代码行数:34,代码来源:filenode_admin.py

示例3: get_current_node

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
def get_current_node(form):
    selected_nodes = form.get_selected_nodes()
    if len(selected_nodes) > 0:
        current_node = selected_nodes[0].parent
    if not current_node:
        return FileNode.get_top_node()
    else:
        return current_node
开发者ID:sentido,项目名称:django-media-tree,代码行数:10,代码来源:core_actions.py

示例4: clear_cache

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
def clear_cache(modeladmin, request, queryset=None):
    """
    """
    from unicodedata import normalize
    
    execute = request.POST.get('execute')
    
    files_in_storage = []
    storage = get_media_storage()

    cache_files_choices = []

    for cache_dir in get_media_backend().get_cache_paths():
        if storage.exists(cache_dir):
            files_in_dir = [storage.path(os.path.join(cache_dir, filename))  \
                for filename in storage.listdir(cache_dir)[1]]
            for file_path in files_in_dir:
                # need to normalize unicode path due to https://code.djangoproject.com/ticket/16315
                file_path = normalize('NFC', file_path)
                storage_name = os.path.join(cache_dir, os.path.basename(file_path))
                link = mark_safe('<a href="%s">%s</a>' % (
                    storage.url(storage_name), storage_name))
                cache_files_choices.append((storage_name, link))

    if not len(cache_files_choices):
        #request.user.message_set.create(message=_('There are no cache files.'))
        return HttpResponseRedirect('')

    if execute:
        form = DeleteCacheFilesForm(queryset, cache_files_choices, request.POST)
        if form.is_valid():
            form.save()
            node = FileNode.get_top_node()
            message = ungettext('Deleted %i cache file.', 'Deleted %i cache files.', len(form.success_files)) % len(form.success_files)
            if len(form.success_files) == len(cache_files_choices):
                message = '%s %s' % (_('The cache was cleared.'), message)
            #request.user.message_set.create(message=message)
            if form.error_files:
		pass                
		#request.user.message_set.create(message=_('The following files could not be deleted:')+' '+repr(form.error_files))
            return HttpResponseRedirect(node.get_admin_url())

    if not execute:
        if len(cache_files_choices) > 0:
            form = DeleteCacheFilesForm(queryset, cache_files_choices)
        else:
            form = None

    c = get_actions_context(modeladmin)
    c.update({
        'title': _('Clear cache'),
        'submit_label': _('Delete selected files'),
        'form': form,
        'select_all': 'selected_files',
    })
    return render_to_response('admin/media_tree/filenode/actions_form.html', c, context_instance=RequestContext(request))

    return HttpResponseRedirect('')
开发者ID:cyber778,项目名称:django-media-tree,代码行数:60,代码来源:maintenance_actions.py

示例5: clear_cache

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
def clear_cache(modeladmin, request, queryset=None):
    """ Clears media cache files such as thumbnails. """
    
    execute = request.POST.get('execute')
    
    files_in_storage = []
    storage = get_media_storage()
    cache_files_choices = []
    for storage_name in get_cache_files():
        link = mark_safe('<a href="%s">%s</a>' % (
            storage.url(storage_name), storage_name))
        cache_files_choices.append((storage_name, link))

    if not len(cache_files_choices):
        messages.warning(request, message=_('There are no cache files.'))
        return HttpResponseRedirect('')

    if execute:
        form = DeleteCacheFilesForm(
            queryset, cache_files_choices, request.POST)
        if form.is_valid():
            form.save()
            node = FileNode.get_top_node()
            message = ungettext(
                'Deleted %i cache file.',
                'Deleted %i cache files.',
                len(form.success_files)) % len(form.success_files)
            if len(form.success_files) == len(cache_files_choices):
                message = '%s %s' % (_('The cache was cleared.'), message)
            messages.success(request, message=message)
            if form.error_files:
                messages.error(
                    request,
                    message=_('The following files could not be deleted:')
                    + ' ' + repr(form.error_files))
            return HttpResponseRedirect(node.get_admin_url())

    if not execute:
        if len(cache_files_choices) > 0:
            form = DeleteCacheFilesForm(queryset, cache_files_choices)
        else:
            form = None

    c = get_actions_context(modeladmin)
    c.update({
        'title': _('Clear cache'),
        'submit_label': _('Delete selected files'),
        'form': form,
        'select_all': 'selected_files',
    })
    return render_to_response('admin/media_tree/filenode/actions_form.html',
                              c, context_instance=RequestContext(request))

    return HttpResponseRedirect('')
开发者ID:loungelogic,项目名称:django-media-tree,代码行数:56,代码来源:maintenance_actions.py

示例6: delete_orphaned_files

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
def delete_orphaned_files(modeladmin, request, queryset=None):
    """
    Deletes orphaned files, i.e. media files existing in storage that are not in the database.
    """
    
    execute = request.POST.get('execute')
    
    storage = get_media_storage()
    broken_node_links = []
    orphaned_files_choices = []

    broken_nodes, orphaned_files = get_broken_media()

    for node in broken_nodes:
        link = mark_safe('<a href="%s">%s</a>' % (node.get_admin_url(), node.__unicode__()))
        broken_node_links.append(link)

    for storage_name in orphaned_files:
        file_path = storage.path(storage_name)
        link = mark_safe('<a href="%s">%s</a>' % (
            storage.url(storage_name), file_path))
        orphaned_files_choices.append((storage_name, link))

    if not len(orphaned_files_choices) and not len(broken_node_links):
        messages.success(request, message=_('There are no orphaned files.'))
        return HttpResponseRedirect('')

    if execute:
        form = DeleteOrphanedFilesForm(queryset, orphaned_files_choices, request.POST)
        if form.is_valid():
            form.save()
            node = FileNode.get_top_node()
            messages.success(request, message=ungettext('Deleted %i file from storage.', 'Deleted %i files from storage.', len(form.success_files)) % len(form.success_files))
            if form.error_files:
                messages.error(request, message=_('The following files could not be deleted from storage:')+' '+repr(form.error_files))
            return HttpResponseRedirect(node.get_admin_url())

    if not execute:
        if len(orphaned_files_choices) > 0:
            form = DeleteOrphanedFilesForm(queryset, orphaned_files_choices)
        else:
            form = None

    c = get_actions_context(modeladmin)
    c.update({
        'title': _('Orphaned files'),
        'submit_label': _('Delete selected files'),
        'form': form,
        'select_all': 'selected_files',
        'node_list_title': _('The following files in the database do not exist in storage. You should fix these media objects:'),
        'node_list': broken_node_links,
    })
    return render_to_response('admin/media_tree/filenode/actions_form.html', c, context_instance=RequestContext(request))
开发者ID:DjangoBD,项目名称:django-media-tree,代码行数:55,代码来源:maintenance_actions.py

示例7: __init__

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
    def __init__(self, allowed_node_types=None, allowed_media_types=None, allowed_extensions=None, level_indicator=LEVEL_INDICATOR, rel=None, *args, **kwargs):
        self.allowed_node_types = allowed_node_types
        self.allowed_media_types = allowed_media_types
        self.allowed_extensions = allowed_extensions
        kwargs['level_indicator'] = level_indicator;
        if not kwargs.has_key('widget'):
            kwargs['widget'] = self.widget

            # TODO: FileNodeForeignKeyRawIdWidget should only be the standard widget when in admin
            # TODO: It currently does not work with move/copy form
            #kwargs['widget'] = FileNodeForeignKeyRawIdWidget(rel)

        super(FileNodeChoiceField, self).__init__(*args, **kwargs)
        # TODO there should nonetheless be an "empty item", also if not required
        if not self.required:
            self.empty_label = FileNode.get_top_node().name
        else:
            self.empty_label = '---------'
开发者ID:TAMUArch,项目名称:django-media-tree,代码行数:20,代码来源:fields.py

示例8: delete_orphaned_files

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
def delete_orphaned_files(modeladmin, request, queryset=None):
    from unicodedata import normalize

    execute = request.POST.get("execute")
    media_subdir = app_settings.MEDIA_TREE_UPLOAD_SUBDIR

    files_in_storage = []
    storage = get_media_storage()

    files_in_db = []
    nodes_with_missing_file_links = []
    for node in FileNode.objects.filter(node_type=FileNode.FILE):
        path = node.file.path
        # need to normalize unicode path due to https://code.djangoproject.com/ticket/16315
        path = normalize("NFC", path)
        files_in_db.append(path)
        if not storage.exists(node.file):
            link = mark_safe('<a href="%s">%s</a>' % (node.get_admin_url(), node.__unicode__()))
            nodes_with_missing_file_links.append(link)

    files_in_storage = [
        storage.path(os.path.join(media_subdir, filename)) for filename in storage.listdir(media_subdir)[1]
    ]

    orphaned_files_choices = []
    for file_path in files_in_storage:
        # need to normalize unicode path due to https://code.djangoproject.com/ticket/16315
        file_path = normalize("NFC", file_path)
        if not file_path in files_in_db:
            storage_name = os.path.join(media_subdir, os.path.basename(file_path))
            link = mark_safe('<a href="%s">%s</a>' % (storage.url(storage_name), file_path))
            orphaned_files_choices.append((storage_name, link))

    if not len(orphaned_files_choices) and not len(nodes_with_missing_file_links):
        request.user.message_set.create(message=_("There are no orphaned files."))
        return HttpResponseRedirect("")

    if execute:
        form = DeleteOrphanedFilesForm(queryset, orphaned_files_choices, request.POST)
        if form.is_valid():
            form.save()
            node = FileNode.get_top_node()
            request.user.message_set.create(
                message=ungettext(
                    "Deleted %i file from storage.", "Deleted %i files from storage.", len(form.success_files)
                )
                % len(form.success_files)
            )
            if form.error_files:
                request.user.message_set.create(
                    message=_("The following files could not be deleted from storage:") + " " + repr(form.error_files)
                )
            return HttpResponseRedirect(node.get_admin_url())

    if not execute:
        if len(orphaned_files_choices) > 0:
            form = DeleteOrphanedFilesForm(queryset, orphaned_files_choices)
        else:
            form = None

    c = get_actions_context(modeladmin)
    c.update(
        {
            "title": _("Orphaned files"),
            "submit_label": _("Delete selected files"),
            "form": form,
            "select_all": "selected_files",
            "node_list_title": _(
                "The following files in the database do not exist in storage. You should fix these media objects:"
            ),
            "node_list": nodes_with_missing_file_links,
        }
    )
    return render_to_response(
        "admin/media_tree/filenode/actions_form.html", c, context_instance=RequestContext(request)
    )
开发者ID:sentido,项目名称:django-media-tree,代码行数:78,代码来源:maintenance_actions.py

示例9: get_actions_context

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
def get_actions_context(modeladmin):
    return {'node': FileNode.get_top_node(), # TODO get current folder
            'opts': modeladmin.model._meta,
            'root_path': modeladmin.admin_site.root_path,
            'app_label': modeladmin.model._meta.app_label,
            'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME}
开发者ID:loungelogic,项目名称:django-media-tree,代码行数:8,代码来源:utils.py

示例10: __init__

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
 def __init__(self, request, *args, **kwargs):
     super(MediaTreeChangeList, self).__init__(request, *args, **kwargs)
     # self.parent_folder is set in get_queryset()
     self.title = self.parent_folder.name if self.parent_folder else FileNode.get_top_node().name
开发者ID:dzonder,项目名称:django-media-tree,代码行数:6,代码来源:change_list.py

示例11: clear_cache

# 需要导入模块: from media_tree.models import FileNode [as 别名]
# 或者: from media_tree.models.FileNode import get_top_node [as 别名]
def clear_cache(modeladmin, request, queryset=None):
    """
    """
    from unicodedata import normalize

    execute = request.POST.get("execute")

    files_in_storage = []
    storage = get_media_storage()

    cache_files_choices = []

    for cache_dir in get_media_backend().get_cache_paths():
        if storage.exists(cache_dir):
            files_in_dir = [
                storage.path(os.path.join(cache_dir, filename)) for filename in storage.listdir(cache_dir)[1]
            ]
            for file_path in files_in_dir:
                # need to normalize unicode path due to https://code.djangoproject.com/ticket/16315
                file_path = normalize("NFC", file_path)
                storage_name = os.path.join(cache_dir, os.path.basename(file_path))
                link = mark_safe('<a href="%s">%s</a>' % (storage.url(storage_name), storage_name))
                cache_files_choices.append((storage_name, link))

    if not len(cache_files_choices):
        messages.warning(request, message=_("There are no cache files."))
        return HttpResponseRedirect("")

    if execute:
        form = DeleteCacheFilesForm(queryset, cache_files_choices, request.POST)
        if form.is_valid():
            form.save()
            node = FileNode.get_top_node()
            message = ungettext("Deleted %i cache file.", "Deleted %i cache files.", len(form.success_files)) % len(
                form.success_files
            )
            if len(form.success_files) == len(cache_files_choices):
                message = "%s %s" % (_("The cache was cleared."), message)
            messages.success(request, message=message)
            if form.error_files:
                messages.error(
                    request, message=_("The following files could not be deleted:") + " " + repr(form.error_files)
                )
            return HttpResponseRedirect(node.get_admin_url())

    if not execute:
        if len(cache_files_choices) > 0:
            form = DeleteCacheFilesForm(queryset, cache_files_choices)
        else:
            form = None

    c = get_actions_context(modeladmin)
    c.update(
        {
            "title": _("Clear cache"),
            "submit_label": _("Delete selected files"),
            "form": form,
            "select_all": "selected_files",
        }
    )
    return render_to_response(
        "admin/media_tree/filenode/actions_form.html", c, context_instance=RequestContext(request)
    )

    return HttpResponseRedirect("")
开发者ID:aramboi,项目名称:django-media-tree,代码行数:67,代码来源:maintenance_actions.py


注:本文中的media_tree.models.FileNode.get_top_node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。