Skip to content

Commit

Permalink
Adds support for s3 storage and forces layer uploads to use the FileS…
Browse files Browse the repository at this point in the history
…ystemStorage
  • Loading branch information
davisc committed Jun 22, 2016
1 parent 117bd63 commit 777d89c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
4 changes: 3 additions & 1 deletion geonode/layers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.core.files.storage import FileSystemStorage

from geonode.base.models import ResourceBase, ResourceBaseManager, resourcebase_post_save
from geonode.people.utils import get_valid_user
Expand Down Expand Up @@ -287,7 +288,8 @@ class LayerFile(models.Model):
upload_session = models.ForeignKey(UploadSession)
name = models.CharField(max_length=255)
base = models.BooleanField(default=False)
file = models.FileField(upload_to='layers', max_length=255)
file = models.FileField(upload_to='layers',
storage=FileSystemStorage(base_url=settings.LOCAL_MEDIA_URL), max_length=255)


class AttributeManager(models.Manager):
Expand Down
29 changes: 28 additions & 1 deletion geonode/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = "/uploaded/"
MEDIA_URL = LOCAL_MEDIA_URL = "/uploaded/"

# Absolute path to the directory that holds static files like app media.
# Example: "/home/media/media.lawrence.com/apps/"
Expand Down Expand Up @@ -289,6 +289,7 @@
'mptt',
#'modeltranslation',
'djcelery',
'storages',

# Theme
"pinax_theme_bootstrap_account",
Expand Down Expand Up @@ -877,6 +878,32 @@
Queue('email', routing_key='email'),
]


# AWS S3 Settings

S3_STATIC_ENABLED = os.environ.get('S3_STATIC_ENABLED', False)
S3_MEDIA_ENABLED = os.environ.get('S3_MEDIA_ENABLED', False)

# Required to run Sync Media to S3
AWS_BUCKET_NAME = os.environ.get('S3_BUCKET_NAME', '')

AWS_STORAGE_BUCKET_NAME = os.environ.get('S3_BUCKET_NAME', '')
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', '')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', '')
AWS_S3_BUCKET_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME

AWS_QUERYSTRING_AUTH = False

if S3_STATIC_ENABLED:
STATICFILES_LOCATION = 'static'
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATIC_URL = "https://%s/%s/" % (AWS_S3_BUCKET_DOMAIN, STATICFILES_LOCATION)

if S3_MEDIA_ENABLED:
MEDIAFILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
MEDIA_URL = "https://%s/%s/" % (AWS_S3_BUCKET_DOMAIN, MEDIAFILES_LOCATION)

import djcelery
djcelery.setup_loader()

Expand Down
2 changes: 1 addition & 1 deletion geonode/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@

# Serve static files
urlpatterns += staticfiles_urlpatterns()
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.LOCAL_MEDIA_URL, document_root=settings.MEDIA_ROOT)
handler403 = 'geonode.views.err403'

# Featured Maps Pattens
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ def fullsplit(path, result=None):
# datetimepicker widget
"django-bootstrap3-datetimepicker==2.2.3",
"flake8==2.3.0",
"pep8==1.6.2"
"pep8==1.6.2",

#AWS S3 dependencies
"django-storages==1.1.8",
"boto==2.38.0"
],
zip_safe=False,
)

0 comments on commit 777d89c

Please sign in to comment.