djangooverridingdjango-grappellidjango-filebrowser

Override method in Django third party library (Filebrowser)


I'm using Grappelli together with Filebrowser and I found a bug when uploading images with a file extension in uppercase(image.PNG). If they end in uppercase a thumbnail will be created everytime the filebrowser page is refreshed.

I found this method in the filebrowser package:

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

To solve the bug I want it to look like this:

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

How do I do this without changing the package file? I don't want my fix to disappeare when I update Filebrowser.

Can I override just that method? Or should I use signals or something?


Solution

  • I made my answer expling how to override a class method. but that's wrong... it is not a class method what you want to change.

    I think, your best option is to make a branch in github of the project and then make a pull request and explein why you did it. If they share your opinion, they will take the pull request and you can go on without worry about override.

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