models.py 文件源码

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

项目:Wagtail-Image-Folders 作者: anteatersa 项目源码 文件源码
def get_upload_to(self, filename):
        filename = self.file.field.storage.get_valid_name(filename)

        # do a unidecode in the filename and then
        # replace non-ascii characters in filename with _ , to sidestep issues with filesystem encoding
        filename = "".join((i if ord(i) < 128 else '_') for i in unidecode(filename))

        # Truncate filename so it fits in the 100 character limit
        # https://code.djangoproject.com/ticket/9893
        if self.folder:
            full_path = os.path.join(self.folder.path, filename)
        else:
            full_path = os.path.join(IMAGES_FOLDER_NAME, filename)

        if len(full_path) >= 95:
            chars_to_trim = len(full_path) - 94
            prefix, extension = os.path.splitext(filename)
            filename = prefix[:-chars_to_trim] + extension
            if self.folder:
                full_path = os.path.join(self.folder.path, filename)
            else:
                full_path = os.path.join(IMAGES_FOLDER_NAME, filename)
        return full_path
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号