Search code examples
djangocumulus

How do I turn off django cumulus in my local_settings.py


I have taken over a project that uses django cumulus for cloud storage. On my development machine, some times I use a slow internet connection, and every time I save a change, django recompiles and tries to make a connection to the racksapace store

Starting new HTTPS connection (1): identity.api.rackspacecloud.com

This sometimes takes 15 seconds and is a real pain. I read a post where someone said they turned off cumulus for local development. I think this was done by setting

DEFAULT_FILE_STORAGE

but unfortunately the poster did not specify. If someone knows a simple setting I can put in my local settings to serve media and static files from my local machine and stop django trying to connect to my cloud storage on every save, that is what I want to do.


Solution

  • The constant reloading of the rackspace bucket was because the previous developer had

    from cumulus.storage import SwiftclientStorage
    class PrivateStorage(SwiftclientStorage):
    

    and in models.py

    from common.storage import PrivateStorage
    PRIVATE_STORE = PrivateStorage()
    ...
    class Upload(models.Model):
        upload = models.FileField(storage=PRIVATE_STORE, upload_to=get_upload_path)
    

    This meant every time the project reloaded, it would create a new https connection to rackspace, and time out if the connection was poor. I created a settings flag to control this by putting the import of SwiftclientStorage and defining of PrivateStorage like so

    from django.conf import settings
    if settings.USECUMULUS:
        from cumulus.storage import SwiftclientStorage
    
        class PrivateStorage(SwiftclientStorage):
    ...
    else:
        class PrivateStorage():
            pass