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


Python RenameForm.errors["name"]方法代码示例

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


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

示例1: rename

# 需要导入模块: from filebrowser.forms import RenameForm [as 别名]
# 或者: from filebrowser.forms.RenameForm import errors["name"] [as 别名]
def rename(request):
    """
    Rename existing File/Directory.
    
    Includes renaming existing Image Versions/Thumbnails.
    """

    from filebrowser.forms import RenameForm

    # QUERY / PATH CHECK
    query = request.GET
    path = get_path(query.get("dir", ""))
    filename = get_file(query.get("dir", ""), query.get("filename", ""))
    if path is None or filename is None:
        if path is None:
            msg = _("The requested Folder does not exist.")
        else:
            msg = _("The requested File does not exist.")
        messages.warning(request, message=msg)
        return HttpResponseRedirect(reverse("fb_browse"))
    abs_path = os.path.join(fb_settings.MEDIA_ROOT, fb_settings.DIRECTORY, path)
    file_extension = os.path.splitext(filename)[1].lower()

    if request.method == "POST":
        form = RenameForm(abs_path, file_extension, request.POST)
        if form.is_valid():
            relative_server_path = os.path.join(fb_settings.DIRECTORY, path, filename)
            new_filename = form.cleaned_data["name"] + file_extension
            new_relative_server_path = os.path.join(fb_settings.DIRECTORY, path, new_filename)
            try:
                # PRE RENAME SIGNAL
                filebrowser_pre_rename.send(sender=request, path=path, filename=filename, new_filename=new_filename)
                # DELETE IMAGE VERSIONS/THUMBNAILS
                # regenerating versions/thumbs will be done automatically
                for version in VERSIONS:
                    try:
                        os.unlink(os.path.join(fb_settings.MEDIA_ROOT, get_version_path(relative_server_path, version)))
                    except:
                        pass
                # RENAME ORIGINAL
                os.rename(
                    os.path.join(fb_settings.MEDIA_ROOT, relative_server_path),
                    os.path.join(fb_settings.MEDIA_ROOT, new_relative_server_path),
                )
                # POST RENAME SIGNAL
                filebrowser_post_rename.send(sender=request, path=path, filename=filename, new_filename=new_filename)
                # MESSAGE & REDIRECT
                msg = _("Renaming was successful.")
                messages.success(request, message=msg)
                redirect_url = reverse("fb_browse") + query_helper(query, "", "filename")
                return HttpResponseRedirect(redirect_url)
            except OSError, (errno, strerror):
                form.errors["name"] = forms.util.ErrorList([_("Error.")])
开发者ID:pavelm2007,项目名称:django-filebrowser-no-grappelli,代码行数:55,代码来源:views.py


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