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


Python FileObject.version_path方法代码示例

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


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

示例1: generate_version_add_watermark

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import version_path [as 别名]
def generate_version_add_watermark(original_path, version_suffix):
    """
        Generate the given version of an image and adds watermark to it
        NOTE: this function only generates a new version from original file (i.e in db) when
          1. the version does not exists.
          2. the modified date of original image is newer than version
        :param original_path: relative path to original image
        :param version_suffix: version prefix as defined in common settings
        'medium'|'large'|'thumbnail'
        :return: image object.
    """

    from filebrowser.base import FileObject
    from filebrowser.sites import site
    from core.models import Image

    fob = FileObject(original_path, site=site)
    version_path = fob.version_path(version_suffix)
    if not site.storage.isfile(version_path):
        version_path = fob._generate_version(version_suffix)
        # abs_path = os.path.join(settings.MEDIA_ROOT, version_path)
        # Image.create_image_watermark(abs_path, abs_path, settings.WATERMARK_IMAGE_LOCATION)
    elif site.storage.modified_time(original_path) > site.storage.modified_time(version_path):
        version_path = fob._generate_version(version_suffix)
        # abs_path = os.path.join(settings.MEDIA_ROOT, version_path)
        # Image.create_image_watermark(abs_path, abs_path, settings.WATERMARK_IMAGE_LOCATION)
    return FileObject(version_path, site=site)
开发者ID:anshul-choudhary,项目名称:photography-awards,代码行数:29,代码来源:utils.py

示例2: DetailViewTests

# 需要导入模块: from filebrowser.base import FileObject [as 别名]
# 或者: from filebrowser.base.FileObject import version_path [as 别名]
class DetailViewTests(TestCase):
    def setUp(self):
        super(DetailViewTests, self).setUp()
        self.url = reverse('filebrowser:fb_detail')
        self.client.login(username=self.user.username, password='password')
        shutil.copy(self.STATIC_IMG_PATH, self.FOLDER_PATH)

    def test_get(self):
        """ Check the detail view and version generation. Check also renaming of files. """
        response = self.client.get(self.url, {'dir': self.F_IMAGE.dirname, 'filename': self.F_IMAGE.filename})

        self.assertTrue(response.status_code == 200)

        # At this moment all versions should be generated. Check that.
        pre_rename_versions = []
        for version_suffix in VERSIONS:
            path = self.F_IMAGE.version_path(version_suffix)
            pre_rename_versions.append(path)
            self.assertTrue(site.storage.exists(path))

        # Attemp renaming the file
        url = '?'.join([self.url, urlencode({'dir': self.F_IMAGE.dirname, 'filename': self.F_IMAGE.filename})])
        response = self.client.post(url, {'name': 'testpic.jpg'})

        # Check we get 302 response for renaming
        self.assertTrue(response.status_code == 302)

        # Check the file was renamed correctly:
        self.assertTrue(site.storage.exists(os.path.join(self.F_IMAGE.head, 'testpic.jpg')))

        # Store the renamed file
        self.F_IMAGE = FileObject(os.path.join(self.F_IMAGE.head, 'testpic.jpg'), site=site)

        # Check if all pre-rename versions were deleted:
        for path in pre_rename_versions:
            self.assertFalse(site.storage.exists(path))

        # Check if all post–rename versions were deleted (resp. not being generated):
        for version_suffix in VERSIONS:
            path = self.F_IMAGE.version_path(version_suffix)
            self.assertFalse(site.storage.exists(path))
开发者ID:TitanEntertainmentGroup,项目名称:django-filebrowser-no-grappelli,代码行数:43,代码来源:test_sites.py

示例3: FileObjectAttributeTests

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

#.........这里部分代码省略.........
        self.assertEqual(self.f_folder.is_empty, False)

    def test_version_attributes_1(self):
        """
        FileObject version attributes/methods
        without versions_basedir

        # is_version
        # original
        # versions_basedir
        # versions
        # admin_versions
        # version_name(suffix)
        # version_path(suffix)
        # version_generate(suffix)
        """
        # 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']
        # expected test results
        version_list = ['fb_test_directory/fb_tmp_dir/fb_tmp_dir_sub/testimage_large.jpg', 'fb_test_directory/fb_tmp_dir/fb_tmp_dir_sub/testimage_admin_thumbnail.jpg']
        admin_version_list = ['fb_test_directory/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, "fb_test_directory/")
        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"), "fb_test_directory/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, "fb_test_directory/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_version_attributes_2(self):
        """
        FileObject version attributes/methods
        with versions_basedir

        # is_version
        # original
        # versions_basedir
        # versions
        # admin_versions
        # version_name(suffix)
        # version_generate(suffix)
        """
        # new settings
        filebrowser.base.VERSIONS_BASEDIR = "fb_test_directory/_versions"
        filebrowser.base.VERSIONS = {
            'admin_thumbnail': {'verbose_name': 'Admin Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
            'large': {'verbose_name': 'Large', 'width': 600, 'height': '', 'opts': ''},
        }
开发者ID:23critters,项目名称:django-filebrowser,代码行数:70,代码来源:base.py


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