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


Python FileObject.delete_versions方法代码示例

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


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

示例1: detail

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [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
        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)

        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)
                    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()
                        self.storage.move(fileobject.path, os.path.join(fileobject.head, new_name))
                        signals.filebrowser_post_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name, site=self)
                        messages.add_message(request, messages.SUCCESS, _('Renaming was successful.'))
                    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={"name": fileobject.filename}, path=path, fileobject=fileobject, filebrowser_site=self)

        return render(
            admin_request(request, self.name),
            'filebrowser/detail.html',
            admin_context({
                'form': form,
                'fileobject': fileobject,
                'query': query,
                'title': u'%s' % fileobject.filename,
                'is_popup': "pop" in request.GET,
                'settings_var': get_settings_var(directory=self.directory),
                'breadcrumbs': get_breadcrumbs(query, query.get('dir', '')),
                'breadcrumbs_title': u'%s' % fileobject.filename,
                'filebrowser_site': self
            }, request),
        )
开发者ID:TitanEntertainmentGroup,项目名称:django-filebrowser-no-grappelli,代码行数:60,代码来源:sites.py

示例2: detail

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [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

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

        if request.method == "POST":
            form = ChangeForm(request.POST, path=abs_path, fileobject=fileobject, 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
                        self.filebrowser_actions_pre_apply.send(
                            sender=request, action_name=action_name, fileobject=[fileobject]
                        )
                        # Call the action to action
                        action_response = action(request=request, fileobjects=[fileobject])
                        # Post-action signal
                        self.filebrowser_actions_post_apply.send(
                            sender=request, action_name=action_name, fileobject=[fileobject], result=action_response
                        )
                    if new_name != fileobject.filename:
                        self.filebrowser_pre_rename.send(
                            sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name
                        )
                        fileobject.delete_versions()
                        os.rename(fileobject.path, os.path.join(fileobject.head, new_name))
                        self.filebrowser_post_rename.send(
                            sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name
                        )
                        messages.add_message(request, messages.SUCCESS, _("Renaming was successful."))
                    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, (errno, strerror):
                    form.errors["name"] = forms.util.ErrorList([_("Error.")])
开发者ID:avanheuvelen,项目名称:django-filebrowser,代码行数:58,代码来源:sites.py

示例3: delete

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [as 别名]
    def delete(self, request):
        "Delete existing File/Directory."
        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)

        if request.GET:
            try:
                signals.filebrowser_pre_delete.send(sender=request, path=fileobject.path, name=fileobject.filename, site=self)
                fileobject.delete_versions()
                fileobject.delete()
                signals.filebrowser_post_delete.send(sender=request, path=fileobject.path, name=fileobject.filename, site=self)
                messages.add_message(request, messages.SUCCESS, _('Successfully deleted %s') % fileobject.filename)
            except OSError, (errno, strerror):
                # TODO: define error-message
                pass
开发者ID:Scopart,项目名称:django-filebrowser-no-grappelli,代码行数:18,代码来源:sites.py

示例4: delete

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [as 别名]
    def delete(self, request):
        "Delete existing File/Directory."
        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)

        if request.GET:
            try:
                signals.filebrowser_pre_delete.send(sender=request, path=fileobject.path, name=fileobject.filename, site=self)
                fileobject.delete_versions()
                fileobject.delete()
                signals.filebrowser_post_delete.send(sender=request, path=fileobject.path, name=fileobject.filename, site=self)
                messages.add_message(request, messages.SUCCESS, _('Successfully deleted %s') % fileobject.filename)
            except OSError:
                # TODO: define error-message
                pass
        redirect_url = reverse("filebrowser:fb_browse", current_app=self.name) + query_helper(query, "", "filename,filetype")
        return HttpResponseRedirect(redirect_url)
开发者ID:oelium,项目名称:django-filebrowser-no-grappelli,代码行数:20,代码来源:sites.py

示例5: delete

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [as 别名]
def delete(request):
    """
    Delete existing File/Directory.
    When trying to delete a Directory, the Directory has to be empty.
    """
    query = request.GET
    abs_path = u'%s' % os.path.join(MEDIA_ROOT, DIRECTORY, query.get('dir', ''))
    fileobject = FileObject(os.path.join(abs_path, query.get('filename', '')))
    
    if request.GET:
        try:
            filebrowser_pre_delete.send(sender=request, path=fileobject.path, name=fileobject.filename)
            fileobject.delete_versions()
            fileobject.delete()
            filebrowser_post_delete.send(sender=request, path=fileobject.path, name=fileobject.filename)
            messages.add_message(request, messages.SUCCESS, _('Successfully deleted %s') % fileobject.filename)
        except OSError, (errno, strerror):
            # TODO: define error-message
            pass
开发者ID:dblundell,项目名称:django-filebrowser,代码行数:21,代码来源:views.py

示例6: delete

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [as 别名]
    def delete(self, request):
        """
        Delete existing File/Directory.
        When trying to delete a Directory, the Directory has to be empty.
        """
        query = request.GET
        abs_path = u"%s" % os.path.join(self.media_root, query.get("dir", ""))
        fileobject = FileObject(
            os.path.join(abs_path, query.get("filename", "")), media_root=self.media_root, media_url=self.media_url
        )

        if request.GET:
            try:
                self.filebrowser_pre_delete.send(sender=request, path=fileobject.path, name=fileobject.filename)
                fileobject.delete_versions()
                fileobject.delete()
                self.filebrowser_post_delete.send(sender=request, path=fileobject.path, name=fileobject.filename)
                messages.add_message(request, messages.SUCCESS, _("Successfully deleted %s") % fileobject.filename)
            except OSError, (errno, strerror):
                # TODO: define error-message
                pass
开发者ID:avanheuvelen,项目名称:django-filebrowser,代码行数:23,代码来源:sites.py

示例7: detail

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [as 别名]
def detail(request):
    """
    Show detail page for a file.
    
    Rename existing File/Directory (deletes existing Image Versions/Thumbnails).
    """
    from filebrowser.forms import ChangeForm
    query = request.GET
    abs_path = u'%s' % os.path.join(MEDIA_ROOT, DIRECTORY, query.get('dir', ''))
    fileobject = FileObject(os.path.join(abs_path, query.get('filename', '')))
    
    if request.method == 'POST':
        form = ChangeForm(request.POST, path=abs_path, fileobject=fileobject)
        if form.is_valid():
            new_name = form.cleaned_data['name']
            transpose = form.cleaned_data['transpose']
            try:
                if transpose:
                    im = Image.open(fileobject.path)
                    new_image = im.transpose(int(transpose))
                    try:
                        new_image.save(fileobject.path, quality=VERSION_QUALITY, optimize=(os.path.splitext(fileobject.path)[1].lower() != '.gif'))
                    except IOError:
                        new_image.save(fileobject.path, quality=VERSION_QUALITY)
                    fileobject.delete_versions()
                    messages.add_message(request, messages.SUCCESS, _('Transposing was successful.'))
                if new_name != fileobject.filename:
                    filebrowser_pre_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name)
                    fileobject.delete_versions()
                    os.rename(fileobject.path, os.path.join(fileobject.head, new_name))
                    filebrowser_post_rename.send(sender=request, path=fileobject.path, name=fileobject.filename, new_name=new_name)
                    messages.add_message(request, messages.SUCCESS, _('Renaming was successful.'))
                if "_continue" in request.POST:
                    redirect_url = reverse("fb_detail") + query_helper(query, "filename="+new_name, "filename")
                else:
                    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:dblundell,项目名称:django-filebrowser,代码行数:41,代码来源:views.py

示例8: FileObjectAttributeTests

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(f_version.exists, True)
        self.assertEqual(f_version.is_version, True)
        self.assertEqual(f_version.original_filename, "testimage.jpg")
        self.assertEqual(f_version.original.path, self.f_image.path)
        # FIXME: versions should not have versions or admin_versions

    def test_version_attributes_3(self):
        """
        FileObject version attributes/methods
        with alternative versions_basedir

        # is_version
        # original
        # versions_basedir
        # versions
        # admin_versions
        # version_name(suffix)
        # version_generate(suffix)
        """
        # new settings
        filebrowser.base.VERSIONS_BASEDIR = "_versionstestdirectory"
        filebrowser.base.VERSIONS = {
            'admin_thumbnail': {'verbose_name': 'Admin Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
            'large': {'verbose_name': 'Large', 'width': 600, 'height': '', 'opts': ''},
        }
        filebrowser.base.ADMIN_VERSIONS = ['large']
        # expected test results
        version_list = ['_versionstestdirectory/fb_tmp_dir/fb_tmp_dir_sub/testimage_large.jpg', '_versionstestdirectory/fb_tmp_dir/fb_tmp_dir_sub/testimage_admin_thumbnail.jpg']
        admin_version_list = ['_versionstestdirectory/fb_tmp_dir/fb_tmp_dir_sub/testimage_large.jpg']

        self.assertEqual(self.f_image.is_version, False)
        self.assertEqual(self.f_image.original.path, self.f_image.path)
        self.assertEqual(self.f_image.versions_basedir, "_versionstestdirectory")
        self.assertEqual(self.f_image.versions(), version_list)
        self.assertEqual(self.f_image.admin_versions(), admin_version_list)
        self.assertEqual(self.f_image.version_name("large"), "testimage_large.jpg")
        self.assertEqual(self.f_image.version_path("large"), "_versionstestdirectory/fb_tmp_dir/fb_tmp_dir_sub/testimage_large.jpg")

        # version does not exist yet
        f_version = FileObject(os.path.join(self.directory, self.tmpdir_name, "testimage_large.jpg"), site=site)
        self.assertEqual(f_version.exists, False)
        # generate version
        f_version = self.f_image.version_generate("large")
        self.assertEqual(f_version.path, "_versionstestdirectory/fb_tmp_dir/fb_tmp_dir_sub/testimage_large.jpg")
        self.assertEqual(f_version.exists, True)
        self.assertEqual(f_version.is_version, True)
        self.assertEqual(f_version.original_filename, "testimage.jpg")
        self.assertEqual(f_version.original.path, self.f_image.path)
        # FIXME: versions should not have versions or admin_versions

    def test_delete(self):
        """
        FileObject delete methods

        # delete
        # delete_versions
        # delete_admin_versions
        """

        # new settings
        filebrowser.base.VERSIONS_BASEDIR = ""
        filebrowser.base.VERSIONS = {
            'admin_thumbnail': {'verbose_name': 'Admin Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
            'large': {'verbose_name': 'Large', 'width': 600, 'height': '', 'opts': ''},
        }
        filebrowser.base.ADMIN_VERSIONS = ['large']

        # version does not exist yet
        f_version = FileObject(os.path.join(self.directory, self.tmpdir_name, "testimage_large.jpg"), site=site)
        self.assertEqual(f_version.exists, False)
        # generate version
        f_version = self.f_image.version_generate("large")
        f_version_thumb = self.f_image.version_generate("admin_thumbnail")
        self.assertEqual(f_version.exists, True)
        self.assertEqual(f_version_thumb.exists, True)
        self.assertEqual(f_version.path, "fb_test_directory/fb_tmp_dir/fb_tmp_dir_sub/testimage_large.jpg")
        self.assertEqual(f_version_thumb.path, "fb_test_directory/fb_tmp_dir/fb_tmp_dir_sub/testimage_admin_thumbnail.jpg")

        # delete admin versions (large)
        self.f_image.delete_admin_versions()
        self.assertEqual(site.storage.exists(f_version.path), False)

        # delete versions (admin_thumbnail)
        self.f_image.delete_versions()
        self.assertEqual(site.storage.exists(f_version_thumb.path), False)

        
    def tearDown(self):
        """
        Restore original values/functions
        """
        filebrowser.base.os.path = self.original_path
        site.directory = self.original_directory
        filebrowser.base.VERSIONS_BASEDIR = self.original_versions_basedir
        filebrowser.base.VERSIONS = self.original_versions
        filebrowser.base.ADMIN_VERSIONS = self.original_admin_versions

        # remove temporary directory and test folder
        shutil.rmtree(self.directory_path)
        shutil.rmtree(self.versions_path)
开发者ID:23critters,项目名称:django-filebrowser,代码行数:104,代码来源:base.py

示例9: detail

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import delete_versions [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.base.FileObject.delete_versions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。