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


Python ChangeForm.save方法代码示例

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


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

示例1: detail

# 需要导入模块: from filebrowser.forms import ChangeForm [as 别名]
# 或者: from filebrowser.forms.ChangeForm import save [as 别名]
    def detail(self, request):
        """
        Show detail page for a file.
        Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
        """
        from filebrowser.forms import ChangeForm
        from filebrowser.models import FileDescription

        query = request.GET
        path = u"%s" % os.path.join(self.directory, query.get("dir", ""))
        fileobject = FileObject(os.path.join(path, query.get("filename", "")), site=self)

        try:
            file_description = FileDescription.objects.get(file_path=fileobject)
        except:
            file_description = FileDescription(file_path=fileobject.path)

        if request.method == "POST":
            form = ChangeForm(request.POST, path=path, fileobject=fileobject, filebrowser_site=self)
            if form.is_valid():
                new_name = form.cleaned_data["name"]
                action_name = form.cleaned_data["custom_action"]
                try:
                    action_response = None
                    if action_name:
                        action = self.get_action(action_name)
                        # Pre-action signal
                        signals.filebrowser_actions_pre_apply.send(
                            sender=request, action_name=action_name, fileobject=[fileobject], site=self
                        )
                        # Call the action to action
                        action_response = action(request=request, fileobjects=[fileobject])
                        # Post-action signal
                        signals.filebrowser_actions_post_apply.send(
                            sender=request,
                            action_name=action_name,
                            fileobject=[fileobject],
                            result=action_response,
                            site=self,
                        )
                    new_file_description = form.save(commit=False)
                    new_file_description.file_path = fileobject.path
                    new_file_description.pk = file_description.pk
                    if new_name != fileobject.filename:
                        signals.filebrowser_pre_rename.send(
                            sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self
                        )
                        fileobject.delete_versions()
                        new_path = os.path.join(fileobject.head, new_name)
                        self.storage.move(fileobject.path, os.path.join(fileobject.head, new_name))
                        if new_file_description:
                            new_file_description.file_path = new_path
                        signals.filebrowser_post_rename.send(
                            sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self
                        )
                        if fileobject.filetype == "Folder":
                            for fd in FileDescription.objects.filter(file_path__startswith=fileobject.path):
                                fd.file_path = new_path + fd.file_path.path[len(fileobject.path) :]
                                fd.save()
                        messages.add_message(request, messages.SUCCESS, _("Renaming was successful."))
                    new_file_description.save()
                    if isinstance(action_response, HttpResponse):
                        return action_response
                    if "_continue" in request.POST:
                        redirect_url = reverse("filebrowser:fb_detail", current_app=self.name) + query_helper(
                            query, "filename=" + new_name, "filename"
                        )
                    else:
                        redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(
                            query, "", "filename"
                        )
                    return HttpResponseRedirect(redirect_url)
                except OSError:
                    form.errors["name"] = forms.util.ErrorList([_("Error.")])
        else:
            form = ChangeForm(
                initial=dict(name=fileobject.filename, **file_description.__dict__),
                path=path,
                fileobject=fileobject,
                filebrowser_site=self,
                instance=file_description,
            )

        return render_to_response(
            "filebrowser/detail.html",
            {
                "form": form,
                "fileobject": fileobject,
                "query": query,
                "title": u"%s" % fileobject.filename,
                "settings_var": get_settings_var(directory=self.directory),
                "breadcrumbs": get_breadcrumbs(query, query.get("dir", "")),
                "breadcrumbs_title": u"%s" % fileobject.filename,
                "filebrowser_site": self,
            },
            context_instance=Context(request, current_app=self.name),
        )
开发者ID:archatas,项目名称:django-filebrowser,代码行数:99,代码来源:sites.py


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