From de7be3652a82172a45197ab92394e1bd0fa15500 Mon Sep 17 00:00:00 2001 From: Tano Abeleyra Date: Sat, 18 May 2019 20:23:48 -0300 Subject: [PATCH] Make cloud_provider optional Some projects may not need AWS or GCS --- README.rst | 3 ++- cookiecutter.json | 3 ++- docs/project-generation-options.rst | 1 + hooks/post_gen_project.py | 6 ++++++ tests/test_cookiecutter_generation.py | 2 +- {{cookiecutter.project_slug}}/config/settings/production.py | 4 +++- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 8a92edda..efcfd506 100644 --- a/README.rst +++ b/README.rst @@ -185,7 +185,8 @@ Answer the prompts with your own desired options_. For example:: Select cloud_provider: 1 - AWS 2 - GCS - Choose from 1, 2 [1]: 1 + 3 - None + Choose from 1, 2, 3 [1]: 1 custom_bootstrap_compilation [n]: n Select open_source_license: 1 - MIT diff --git a/cookiecutter.json b/cookiecutter.json index a66bb732..d4a977bb 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -33,7 +33,8 @@ ], "cloud_provider": [ "AWS", - "GCE" + "GCE", + "None" ], "custom_bootstrap_compilation": "n", "use_compressor": "n", diff --git a/docs/project-generation-options.rst b/docs/project-generation-options.rst index c3c4d3a2..3e4ac47c 100644 --- a/docs/project-generation-options.rst +++ b/docs/project-generation-options.rst @@ -69,6 +69,7 @@ cloud_provider: 1. AWS_ 2. GCS_ + 3. None custom_bootstrap_compilation: Indicates whether the project should support Bootstrap recompilation diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 292f6e7f..ff84f180 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -328,6 +328,12 @@ def main(): if "{{ cookiecutter.use_docker }}".lower() == "y": remove_node_dockerfile() + if "{{ cookiecutter.cloud_provider}}".lower() == "none": + print( + WARNING + "You chose not to use a cloud provider, " + "media files won't be served in production." + TERMINATOR + ) + if "{{ cookiecutter.use_celery }}".lower() == "n": remove_celery_files() if "{{ cookiecutter.use_docker }}".lower() == "y": diff --git a/tests/test_cookiecutter_generation.py b/tests/test_cookiecutter_generation.py index 2be23b86..be05e79b 100755 --- a/tests/test_cookiecutter_generation.py +++ b/tests/test_cookiecutter_generation.py @@ -11,7 +11,7 @@ PATTERN = "{{(\s?cookiecutter)[.](.*?)}}" RE_OBJ = re.compile(PATTERN) YN_CHOICES = ["y", "n"] -CLOUD_CHOICES = ["AWS", "GCE"] +CLOUD_CHOICES = ["AWS", "GCE", "None"] @pytest.fixture diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 1a5889d5..c2fcd575 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -68,8 +68,10 @@ SECURE_CONTENT_TYPE_NOSNIFF = env.bool( # STORAGES # ------------------------------------------------------------------------------ +{% if cookiecutter.cloud_provider != 'None' -%} # https://django-storages.readthedocs.io/en/latest/#installation INSTALLED_APPS += ["storages"] # noqa F405 +{%- endif -%} {% if cookiecutter.cloud_provider == 'AWS' %} # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings AWS_ACCESS_KEY_ID = env("DJANGO_AWS_ACCESS_KEY_ID") @@ -193,7 +195,7 @@ COMPRESS_ENABLED = env.bool("COMPRESS_ENABLED", default=True) # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE COMPRESS_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" # https://django-compressor.readthedocs.io/en/latest/settings/#django.conf.settings.COMPRESS_URL -COMPRESS_URL = STATIC_URL{% if cookiecutter.use_whitenoise == 'y' %} # noqa F405{% endif %} +COMPRESS_URL = STATIC_URL{% if cookiecutter.use_whitenoise == 'y' or cookiecutter.cloud_provider == 'None' %} # noqa F405{% endif %} {% endif %} {%- if cookiecutter.use_whitenoise == 'n' -%} # Collectfast