Skip to content

Commit

Permalink
Merge pull request #280 from CoderDojoChi/feature/s3-media
Browse files Browse the repository at this point in the history
Feature/s3 media
  • Loading branch information
karbassi committed Apr 27, 2016
2 parents 90dcbe2 + 926d481 commit 7a0b0a2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
8 changes: 8 additions & 0 deletions coderdojochi/custom_storages.py
@@ -0,0 +1,8 @@
from django.conf import settings
from storages.backends.s3boto import S3BotoStorage

# class StaticStorage(S3BotoStorage):
# location = settings.STATICFILES_LOCATION

class MediaStorage(S3BotoStorage):
location = settings.MEDIAFILES_LOCATION
48 changes: 38 additions & 10 deletions coderdojochi/settings.py
Expand Up @@ -59,6 +59,7 @@
'djrill',
'loginas',
'paypal.standard.ipn',
'storages',

#coderdojochi
'coderdojochi',
Expand Down Expand Up @@ -154,16 +155,6 @@
USE_L10N = True


# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: 'http://example.com/media/', 'http://media.example.com/'
MEDIA_URL = '/media/'

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: '/var/www/example.com/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media')


# URL prefix for static files.
# Example: 'http://example.com/static/', 'http://static.example.com/'
STATIC_URL = '/static/'
Expand All @@ -184,6 +175,34 @@
# Should be 2MB, current recommended
AVATAR_MAX_SIZE = 2*1024*1024

# AWS S3
AWS_HEADERS = {
'Expires': 'Thu, 31 Dec 2099 20:00:00 GMT',
'Cache-Control': 'max-age=94608000',
}

AWS_STORAGE_BUCKET_NAME = os.environ.get('AWS_STORAGE_BUCKET_NAME')
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')

# Tell django-storages that when coming up with the URL for an item in S3 storage, keep
# it simple - just use this domain plus the path. (If this isn't set, things get complicated).
# This controls how the `static` template tag from `staticfiles` gets expanded, if you're using it.
# We also use it in the next setting.
AWS_S3_CUSTOM_DOMAIN = '%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME

# STATICFILES_LOCATION = 'static'
# STATICFILES_STORAGE = 'custom_storages.StaticStorage'
# STATIC_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)

# MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN)
# DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

MEDIAFILES_LOCATION = 'media'
MEDIA_URL = "https://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION)
DEFAULT_FILE_STORAGE = 'coderdojochi.custom_storages.MediaStorage'


# Paypal

PAYPAL_RECEIVER_EMAIL = 'info@coderdojochi.org'
Expand Down Expand Up @@ -219,3 +238,12 @@ def custom_show_toolbar(request):
'TAG': 'div',
'ENABLE_STACKTRACES': True,
}

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: 'http://example.com/media/', 'http://media.example.com/'
MEDIA_URL = '/media/'

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: '/var/www/example.com/media/'
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'media')
1 change: 0 additions & 1 deletion coderdojochi/templates/avatar/add.html
@@ -1,6 +1,5 @@
{% extends "avatar/base.html" %}
{% load i18n avatar_tags bootstrap3 %}
{% load url from future %}

{% block content %}
<div class="row">
Expand Down
1 change: 0 additions & 1 deletion coderdojochi/templates/avatar/change.html
@@ -1,6 +1,5 @@
{% extends "avatar/base.html" %}
{% load i18n avatar_tags bootstrap3 %}
{% load url from future %}

{% block content %}
<div class="row">
Expand Down
1 change: 0 additions & 1 deletion coderdojochi/templates/avatar/confirm_delete.html
@@ -1,6 +1,5 @@
{% extends "avatar/base.html" %}
{% load i18n bootstrap3 %}
{% load url from future %}

{% block content %}
<p>{% trans "Please select the avatars that you would like to delete." %}</p>
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
@@ -1,4 +1,5 @@
arrow==0.7.0
boto==2.39.0
dealer==2.0.5
Django==1.9.5
django-allauth==0.25.2
Expand All @@ -11,6 +12,7 @@ django-debug-toolbar==1.4
django-html5==1.0.0
django-loginas==0.1.9
django-paypal==0.3.2
django-storages==1.4.1
djrill==2.0
gunicorn==19.4.5
httplib2==0.9.2
Expand Down

0 comments on commit 7a0b0a2

Please sign in to comment.