Django第三方库中的覆盖方法(Filebrowser)

时间:2014-05-15 13:47:59

标签: django override django-grappelli django-filebrowser

我正在使用Grappelli和Filebrowser,我在上传带有大写文件扩展名的图像(image.PNG)时发现了一个错误。如果它们以大写结尾,则每次刷新文件浏览器页面时都会创建一个缩略图。

我在filebrowser包中找到了这个方法:

def handle_file_upload(path, file, site):
    """
    Handle File Upload.
    """

    uploadedfile = None
    try:
        file_path = os.path.join(path, file.name)
        uploadedfile = site.storage.save(file_path, file)
    except Exception, inst:
        raise inst
    return uploadedfile

要解决这个问题,我希望它看起来像这样:

def handle_file_upload(path, file, site):
        """
        Handle File Upload.
        """

        uploadedfile = None
        try:
            file_path = os.path.join(path, file.name.lower())
            uploadedfile = site.storage.save(file_path, file)
        except Exception, inst:
            raise inst
        return uploadedfile

如何在不更改包文件的情况下执行此操作?当我更新Filebrowser时,我不希望我的修复程序消失。

我可以覆盖那个方法吗?或者我应该使用信号还是什么?

1 个答案:

答案 0 :(得分:0)

我的答案是如何覆盖类方法的。但那是错的......这不是一种你想要改变的阶级方法。

我认为,你最好的选择是在项目的github中创建一个分支,然后发出一个pull请求并详细说明你为什么这样做。如果他们分享您的意见,他们将接受拉取请求,您可以继续而不用担心覆盖。

https://github.com/sehmaschine/django-filebrowser

相关问题