コード例 #1
0
    def get(self, instance_id):
        if self.is_exist(instance_id) is None:
            abort(404)

        return send_from_directory(
            directory=thumbnail_utils.get_folder_name(self.data_type),
            filename=thumbnail_utils.get_file_name(instance_id)
        )
コード例 #2
0
ファイル: resources.py プロジェクト: Tesla-Coil/zou
    def get(self, instance_id):
        if not self.is_exist(instance_id):
            abort(404)

        if not self.is_allowed(instance_id):
            abort(403)

        return send_from_directory(
            directory=thumbnail_utils.get_folder_name(self.subfolder),
            filename=thumbnail_utils.get_file_name(instance_id))
コード例 #3
0
ファイル: resources.py プロジェクト: Tesla-Coil/zou
    def get(self, instance_id):
        if not self.is_exist(instance_id):
            abort(404)

        if not self.is_allowed(instance_id):
            abort(403)

        folder_path = thumbnail_utils.get_preview_folder_name(
            self.subfolder, instance_id)
        file_name = thumbnail_utils.get_file_name(instance_id)

        # Use legacy folder name if the file cannot be found.
        if not os.path.exists(os.path.join(folder_path, file_name)):
            folder_path = thumbnail_utils.get_folder_name("preview-files")

        return send_from_directory(directory=folder_path, filename=file_name)
コード例 #4
0
ファイル: test_thumbnail.py プロジェクト: tpolson/zou
    def test_turn_into_thumbnail(self):
        file_path_fixture = self.get_fixture_file_path("thumbnails/th01.png")
        full_path = os.path.join(TEST_FOLDER,
                                 thumbnail.get_file_name("instance-id"))
        fs.copyfile(file_path_fixture, full_path)

        thumbnail.turn_into_thumbnail(full_path)
        im = Image.open(full_path)
        (width, height) = im.size
        self.assertEqual(width, 180)
        self.assertEqual(height, 101)

        thumbnail.turn_into_thumbnail(full_path, thumbnail.RECTANGLE_SIZE)
        im = Image.open(full_path)
        (width, height) = im.size
        self.assertEqual(width, 150)
        self.assertEqual(height, 100)
コード例 #5
0
ファイル: test_thumbnail.py プロジェクト: tpolson/zou
    def test_generate_preview_variants(self):
        preview_id = "123413-12312"
        file_path_fixture = self.get_fixture_file_path("thumbnails/th01.png")
        file_name = thumbnail.get_file_name(preview_id)
        original_path = os.path.join(TEST_FOLDER, file_name)
        fs.copyfile(file_path_fixture, original_path)
        thumbnail.generate_preview_variants(original_path, preview_id)

        file_path = os.path.join(TEST_FOLDER, "previews-%s.png" % preview_id)
        self.assertTrue(os.path.exists(file_path))
        self.assertTrue(Image.open(file_path).size, thumbnail.PREVIEW_SIZE)

        file_path = os.path.join(TEST_FOLDER, "thumbnails-%s.png" % preview_id)
        self.assertTrue(os.path.exists(file_path))
        self.assertTrue(Image.open(file_path).size, thumbnail.RECTANGLE_SIZE)

        file_path = os.path.join(TEST_FOLDER,
                                 "thumbnails-square-%s.png" % preview_id)
        self.assertTrue(os.path.exists(file_path))
        self.assertTrue(Image.open(file_path).size, thumbnail.SQUARE_SIZE)
コード例 #6
0
    def test_generate_preview_variants(self):
        preview_id = "123413-12312"
        file_path_fixture = self.get_fixture_file_path("thumbnails/th01.png")
        file_name = thumbnail.get_file_name(preview_id)
        folder_path = thumbnail.get_preview_folder_name(
            "originals", preview_id)
        fs.mkdir_p(folder_path)
        fs.copyfile(file_path_fixture, os.path.join(folder_path, file_name))
        thumbnail.generate_preview_variants(preview_id)

        file_path = thumbnail.get_preview_file_path("previews", preview_id)
        self.assertTrue(os.path.exists(file_path))
        self.assertTrue(Image.open(file_path).size, thumbnail.PREVIEW_SIZE)

        folder_path = thumbnail.get_preview_folder_name(
            "thumbnails", preview_id)
        self.assertTrue(os.path.exists(file_path))
        self.assertTrue(Image.open(file_path).size, thumbnail.RECTANGLE_SIZE)

        folder_path = thumbnail.get_preview_folder_name(
            "thumbnails-square", preview_id)
        self.assertTrue(os.path.exists(file_path))
        self.assertTrue(Image.open(file_path).size, thumbnail.SQUARE_SIZE)
コード例 #7
0
 def test_get_file_name(self):
     file_name = thumbnail.get_file_name("instance-id")
     self.assertEqual(file_name, "instance-id.png")