Skip to content

Commit

Permalink
custom django storage, so boto push happens on collectstatic
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Levinger committed May 6, 2013
1 parent 9a290f4 commit 37b458d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion boris/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ def get_cache():
AWS_STORAGE_BUCKET_NAME = 'register2.rockthevote.com'
AWS_S3_CUSTOM_DOMAIN = 'dyw5n6uc3lgo5.cloudfront.net'
STATIC_URL = 'https://dyw5n6uc3lgo5.cloudfront.net/'
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.CachedStaticFilesStorage'
#storage
DEFAULT_FILE_STORAGE = 'storage.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'storage.StaticRootS3BotoStorage'
#use heroku db
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
Expand Down
24 changes: 24 additions & 0 deletions boris/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.conf import settings
from django.contrib.staticfiles.storage import CachedFilesMixin
from storages.backends.s3boto import S3BotoStorage

class CachedStaticS3BotoStorage(CachedFilesMixin, S3BotoStorage):
pass

class StaticRootS3BotoStorage(CachedStaticS3BotoStorage):
"""
Storage for static files.
"""

def __init__(self, *args, **kwargs):
kwargs['location'] = 'static'
super(CachedStaticS3BotoStorage, self).__init__(*args, **kwargs)

class MediaRootS3BotoStorage(CachedStaticS3BotoStorage):
"""
Storage for uploaded media files.
"""

def __init__(self, *args, **kwargs):
kwargs['location'] = 'media'
super(CachedStaticS3BotoStorage, self).__init__(*args, **kwargs)

0 comments on commit 37b458d

Please sign in to comment.