geonode icon indicating copy to clipboard operation
geonode copied to clipboard

[Upload Improvements] Allow the LayerUploadForm to fetch files locally too

Open afabiani opened this issue 4 years ago • 0 comments

Currently the geonode.layers.forms.LayerUploadForm forces us to recognize the files from the request.FILES only.

We need to generalize this and allow the form to be able to eventually fetch the files from a local path too, avoiding to store them again on the local storage.

EDIT: Envisage using the StorageManager in order to save the uploaded files. e.g.:

In Django we can do something like this: If you want to do this permanently, you need to create your own FileStorage class

import os
from django.conf import settings
from django.core.files.storage import FileSystemStorage

class MyFileStorage(FileSystemStorage):

    # This method is actually defined in Storage
    def get_available_name(self, name):
        if self.exists(name):
            os.remove(os.path.join(settings.MEDIA_ROOT, name))
        return name # simply returns the name passed

Now in your model, you use your modified MyFileStorage

from mystuff.customs import MyFileStorage

mfs = MyFileStorage()

class SomeModel(model.Model):
   my_file = model.FileField(storage=mfs)

afabiani avatar Jan 19 '22 09:01 afabiani