Add django-compressor suport (#568)

* #342 Add compressor option to requirements

* #342 Add compressor to production settings

* #342 Add compressor to base template

* #342 Add settings to common.py and add tags to base template

* #342 Flake8 fix for tox tests

* #342 Remove redundant line

* #342 Add required options for S3 to production.py and added Env variable to enable/disable compression

* #342 Add required options for compressor on S3 to production.py
This commit is contained in:
Andres Gonzalez 2016-06-17 22:07:45 -04:00 committed by Daniel Roy Greenfeld
parent e085b40ab5
commit 3d2385a3b6
6 changed files with 28 additions and 4 deletions

View File

@ -17,6 +17,7 @@
"use_python2": "n", "use_python2": "n",
"use_docker": "y", "use_docker": "y",
"use_heroku": "n", "use_heroku": "n",
"use_compressor": "n",
"js_task_runner": ["Gulp", "Grunt", "None"], "js_task_runner": ["Gulp", "Grunt", "None"],
"use_lets_encrypt": "n", "use_lets_encrypt": "n",
"open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"] "open_source_license": ["MIT", "BSD", "Apache Software License 2.0", "Not open source"]

View File

@ -233,6 +233,13 @@ BROKER_URL = env('CELERY_BROKER_URL', default='django://')
########## END CELERY ########## END CELERY
{% endif %} {% endif %}
# django-compressor
# ------------------------------------------------------------------------------
{% if cookiecutter.use_compressor == 'y'-%}
INSTALLED_APPS += ("compressor", )
STATICFILES_FINDERS += ("compressor.finders.CompressorFinder", )
{%- endif %}
# Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %} # Location of root django.contrib.admin URL, use {% raw %}{% url 'admin:index' %}{% endraw %}
ADMIN_URL = r'^admin/' ADMIN_URL = r'^admin/'

View File

@ -140,14 +140,19 @@ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
{% else %} {% else %}
STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME STATIC_URL = 'https://s3.amazonaws.com/%s/static/' % AWS_STORAGE_BUCKET_NAME
STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage' STATICFILES_STORAGE = 'config.settings.production.StaticRootS3BotoStorage'
# See: https://github.com/antonagestam/collectfast # See: https://github.com/antonagestam/collectfast
# For Django 1.7+, 'collectfast' should come before # For Django 1.7+, 'collectfast' should come before
# 'django.contrib.staticfiles' # 'django.contrib.staticfiles'
AWS_PRELOAD_METADATA = True AWS_PRELOAD_METADATA = True
INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS INSTALLED_APPS = ('collectfast', ) + INSTALLED_APPS
{%- endif %} {%- endif %}
{% if cookiecutter.use_compressor == 'y'-%}
# COMPRESSOR
# ------------------------------------------------------------------------------
COMPRESS_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
COMPRESS_URL = STATIC_URL
COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)
{%- endif %}
# EMAIL # EMAIL
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL', DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',

View File

@ -31,3 +31,6 @@ DJANGO_OPBEAT_ORGANIZATION_ID
DJANGO_OPBEAT_APP_ID DJANGO_OPBEAT_APP_ID
DJANGO_OPBEAT_SECRET_TOKEN DJANGO_OPBEAT_SECRET_TOKEN
{% endif %} {% endif %}
{% if cookiecutter.use_compressor == 'y' -%}
COMPRESS_ENABLED=
{% endif %}

View File

@ -54,4 +54,8 @@ redis>=2.10.0
celery==3.1.23 celery==3.1.23
{% endif %} {% endif %}
{% if cookiecutter.use_compressor == "y" %}
django_compressor==2.0
{% endif %}
# Your custom requirements go here # Your custom requirements go here

View File

@ -1,4 +1,4 @@
{% raw %}{% load staticfiles i18n %}<!DOCTYPE html> {% raw %}{% load staticfiles i18n {% endraw %}{% if cookiecutter.use_compressor == "y" %}compress{% endif %}{% raw %}%}<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
@ -18,9 +18,10 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
<!-- Your stuff: Third-party css libraries go here --> <!-- Your stuff: Third-party css libraries go here -->
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress css %}{% endraw %}{% endif %}{% raw %}
<!-- This file store project specific CSS --> <!-- This file store project specific CSS -->
<link href="{% static 'css/project.css' %}" rel="stylesheet"> <link href="{% static 'css/project.css' %}" rel="stylesheet">
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %}
{% endblock %} {% endblock %}
</head> </head>
@ -100,7 +101,10 @@
<!-- Your stuff: Third-party javascript libraries go here --> <!-- Your stuff: Third-party javascript libraries go here -->
<!-- place project specific Javascript in this file --> <!-- place project specific Javascript in this file -->
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% compress js %}{% endraw %}{% endif %}{% raw %}
<script src="{% static 'js/project.js' %}"></script> <script src="{% static 'js/project.js' %}"></script>
{% endraw %}{% if cookiecutter.use_compressor == "y" %}{% raw %}{% endcompress %}{% endraw %}{% endif %}{% raw %}
{% endblock javascript %} {% endblock javascript %}
</body> </body>
</html> </html>