Horrible things for nice storage

master
Nick Sergeant 2011-10-23 22:44:37 -04:00
parent 477cf2f1bb
commit 18b47de71f
5 changed files with 60 additions and 35 deletions

View File

@ -3,7 +3,7 @@ boto
Django Django
django-annoying django-annoying
django-bcrypt django-bcrypt
django-css django-compressor
django-grappelli django-grappelli
django-pagination django-pagination
django-postmark django-postmark

View File

@ -515,3 +515,7 @@ article.snipt {
.hidden { .hidden {
display: none; display: none;
} }
body {
background: blue;
}

View File

@ -4,6 +4,7 @@ import os
DEBUG = True DEBUG = True
TEMPLATE_DEBUG = DEBUG TEMPLATE_DEBUG = DEBUG
BASE_PATH = os.path.dirname(__file__)
ADMINS = ( ADMINS = (
('Nick Sergeant', 'nick@snipt.net'), ('Nick Sergeant', 'nick@snipt.net'),
@ -49,20 +50,22 @@ USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files. # Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/" # Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/Users/Nick/Code/snipt/snipt/media/' MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a # URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash. # trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" # Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = '/media/' MEDIA_URL = ''
# Absolute path to the directory static files should be collected to. # Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files # Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/" # Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/Users/Nick/Code/snipt/snipt/static/' STATIC_ROOT = os.path.join(BASE_PATH, 'static')
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage' STATICFILES_STORAGE = 'snipt.storage.CachedS3BotoStorage'
STATIC_URL = 'https://dn2p0mzo970os.cloudfront.net/' STATIC_URL = 'https://dn2p0mzo970os.cloudfront.net/'
# S3 Settings
AWS_ACCESS_KEY_ID = 'AKIAJTFDHBCXHJLXINKQ' AWS_ACCESS_KEY_ID = 'AKIAJTFDHBCXHJLXINKQ'
AWS_SECRET_ACCESS_KEY = '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' AWS_SECRET_ACCESS_KEY = 'olt18bexb9Yoxb0GmKEKwLwG385/zSYvCz1KRVTo'
AWS_STORAGE_BUCKET_NAME = 'snipt' AWS_STORAGE_BUCKET_NAME = 'snipt'
@ -74,7 +77,7 @@ ADMIN_MEDIA_PREFIX = STATIC_URL + 'grappelli/'
# Additional locations of static files # Additional locations of static files
STATICFILES_DIRS = ( STATICFILES_DIRS = (
'/Users/Nick/Code/snipt/snipt/media', os.path.join(BASE_PATH, 'media'),
) )
# List of finder classes that know how to find static files in # List of finder classes that know how to find static files in
@ -82,7 +85,7 @@ STATICFILES_DIRS = (
STATICFILES_FINDERS = ( STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder', 'compressor.finders.CompressorFinder',
) )
# Make this unique, and don't share it with anybody. # Make this unique, and don't share it with anybody.
@ -94,12 +97,21 @@ TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.Loader', 'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader', # 'django.template.loaders.eggs.Loader',
) )
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.request',
'django.core.context_processors.static',
)
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
'snipt.middleware.www.WWWMiddleware', 'snipt.middleware.www.WWWMiddleware',
'django.middleware.cache.CacheMiddleware', 'django.middleware.cache.CacheMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
@ -169,20 +181,18 @@ GRAPPELLI_ADMIN_TITLE = '<a href="/">Snipt</a>'
# Virtualenv # Virtualenv
VIRTUALENV_PATH = '/Users/Nick/.virtualenvs/snipt/lib/python2.7/site-packages/' VIRTUALENV_PATH = '/Users/Nick/.virtualenvs/snipt/lib/python2.7/site-packages/'
# Compressor
COMPRESS_ENABLED = True
COMPRESS_OUTPUT_DIR = 'cache'
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_URL = STATIC_URL
COMPRESS_STORAGE = STATICFILES_STORAGE
# Account settings # Account settings
LOGIN_REDIRECT_URL = '/' LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/login/' LOGIN_URL = '/login/'
LOGOUT_URL = '/logout/' LOGOUT_URL = '/logout/'
# CSS compression
COMPRESS_OUTPUT_DIR = 'cache'
COMPILER_FORMATS = {
'.less': {
'binary_path':'lessc',
'arguments': '*.less *.css'
},
}
# User absolute URLs # User absolute URLs
ABSOLUTE_URL_OVERRIDES = { ABSOLUTE_URL_OVERRIDES = {
'auth.user': lambda u: "/%s/" % u.username, 'auth.user': lambda u: "/%s/" % u.username,

19
snipt/storage.py Normal file
View File

@ -0,0 +1,19 @@
from django.core.files.storage import get_storage_class
from storages.backends.s3boto import S3BotoStorage
class CachedS3BotoStorage(S3BotoStorage):
"""
S3 storage backend that saves the files locally, too.
"""
def __init__(self, *args, **kwargs):
super(CachedS3BotoStorage, self).__init__(*args, **kwargs)
self.local_storage = get_storage_class(
"compressor.storage.CompressorFileStorage")()
def save(self, name, content):
name = super(CachedS3BotoStorage, self).save(name, content)
self.local_storage._save(name, content)
return name
def path(self, name):
return self.local_storage.path(name)

View File

@ -1,32 +1,24 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" class="{% block html-class %}{% endblock %}"> <html lang="en" class="{% block html-class %}{% endblock %}">
<head> <head>
{% load compress %}
<title>{% block page-title %}Snipt{% endblock %}</title> <title>{% block page-title %}Snipt{% endblock %}</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="description" content="Long-term memory for coders. Share and store code snippets." /> <meta name="description" content="Long-term memory for coders. Share and store code snippets." />
{% load compress %}
{% compress css %} {% compress css %}
<link rel="stylesheet" href="/media/css/reset.css" /> <link rel="stylesheet" href="{{ STATIC_URL }}css/reset.css" />
<link rel="stylesheet" href="/media/css/themes.css" /> <link rel="stylesheet" href="{{ STATIC_URL }}css/themes.css" />
{% if not debug %} <link rel="stylesheet" href="{{ STATIC_URL }}css/style.less" />
<link rel="stylesheet" href="/media/css/style.less" />
{% endif %}
{% endcompress %} {% endcompress %}
{% if debug %}
<link rel="stylesheet/less" href="/media/css/style.less" />
{% endif %}
{% compress js %} {% compress js %}
<script type="text/javascript" src="/media/js/jquery.js"></script> <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.js"></script>
<script type="text/javascript" src="/media/js/jquery.infieldlabel.js"></script> <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.infieldlabel.js"></script>
<script type="text/javascript" src="/media/js/jquery.hotkeys.js"></script> <script type="text/javascript" src="{{ STATIC_URL }}js/jquery.hotkeys.js"></script>
<script type="text/javascript" src="/media/js/coffee-script.js"></script> <script type="text/javascript" src="{{ STATIC_URL }}js/coffee-script.js"></script>
<script type="text/coffeescript" src="/media/js/script.coffee"></script> <script type="text/coffeescript" src="{{ STATIC_URL }}js/script.coffee"></script>
{% if debug %}
<script type="text/javascript" src="/media/js/less.js"></script>
{% endif %}
{% endcompress %} {% endcompress %}
<!--[if IE]> <!--[if IE]>