components.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:nhsuk-content-store 作者: nhsuk 项目源码 文件源码
def transform(self, data):
        path = self.find_biggest_image(data['props']['srcset'])
        name = os.path.basename(path)

        image = Image(
            caption=data['props'].get('caption', ''),
            title=data['props']['alt'] or self.page.title
        )

        # save temp file
        img_temp = NamedTemporaryFile()
        img_temp.write(self.get_image_data_from_file(path))
        img_temp.flush()

        # save file and image
        image.file.save(name, File(img_temp), save=True)
        image.save()

        return {
            'type': 'image',
            'value': image.id
        }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号