mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2024-11-10 19:57:09 +03:00
Move storages classes into their own module
This commit is contained in:
parent
0c36c57f2d
commit
c4b1666707
|
@ -292,6 +292,10 @@ def remove_drf_starter_files():
|
|||
shutil.rmtree(os.path.join("{{cookiecutter.project_slug}}", "users", "api"))
|
||||
|
||||
|
||||
def remove_storages_module():
|
||||
os.remove(os.path.join("{{cookiecutter.project_slug}}", "utils", "storages.py"))
|
||||
|
||||
|
||||
def main():
|
||||
debug = "{{ cookiecutter.debug }}".lower() == "y"
|
||||
|
||||
|
@ -352,6 +356,7 @@ def main():
|
|||
WARNING + "You chose not to use a cloud provider, "
|
||||
"media files won't be served in production." + TERMINATOR
|
||||
)
|
||||
remove_storages_module()
|
||||
|
||||
if "{{ cookiecutter.use_celery }}".lower() == "n":
|
||||
remove_celery_files()
|
||||
|
|
|
@ -104,11 +104,11 @@ GS_DEFAULT_ACL = "publicRead"
|
|||
{% if cookiecutter.use_whitenoise == 'y' -%}
|
||||
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
|
||||
{% elif cookiecutter.cloud_provider == 'AWS' -%}
|
||||
STATICFILES_STORAGE = "config.settings.production.StaticRootS3Boto3Storage"
|
||||
STATICFILES_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.StaticRootS3Boto3Storage"
|
||||
COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy"
|
||||
STATIC_URL = f"https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/static/"
|
||||
{% elif cookiecutter.cloud_provider == 'GCP' -%}
|
||||
STATICFILES_STORAGE = "config.settings.production.StaticRootGoogleCloudStorage"
|
||||
STATICFILES_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.StaticRootGoogleCloudStorage"
|
||||
COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy"
|
||||
STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/"
|
||||
{% endif -%}
|
||||
|
@ -116,39 +116,10 @@ STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/"
|
|||
# MEDIA
|
||||
# ------------------------------------------------------------------------------
|
||||
{%- if cookiecutter.cloud_provider == 'AWS' %}
|
||||
# region http://stackoverflow.com/questions/10390244/
|
||||
# Full-fledge class: https://stackoverflow.com/a/18046120/104731
|
||||
from storages.backends.s3boto3 import S3Boto3Storage # noqa E402
|
||||
|
||||
|
||||
class StaticRootS3Boto3Storage(S3Boto3Storage):
|
||||
location = "static"
|
||||
default_acl = "public-read"
|
||||
|
||||
|
||||
class MediaRootS3Boto3Storage(S3Boto3Storage):
|
||||
location = "media"
|
||||
file_overwrite = False
|
||||
|
||||
|
||||
# endregion
|
||||
DEFAULT_FILE_STORAGE = "config.settings.production.MediaRootS3Boto3Storage"
|
||||
DEFAULT_FILE_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.MediaRootS3Boto3Storage"
|
||||
MEDIA_URL = f"https://{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com/media/"
|
||||
{%- elif cookiecutter.cloud_provider == 'GCP' %}
|
||||
from storages.backends.gcloud import GoogleCloudStorage # noqa E402
|
||||
|
||||
|
||||
class StaticRootGoogleCloudStorage(GoogleCloudStorage):
|
||||
location = "static"
|
||||
default_acl = "publicRead"
|
||||
|
||||
|
||||
class MediaRootGoogleCloudStorage(GoogleCloudStorage):
|
||||
location = "media"
|
||||
file_overwrite = False
|
||||
|
||||
|
||||
DEFAULT_FILE_STORAGE = "config.settings.production.MediaRootGoogleCloudStorage"
|
||||
DEFAULT_FILE_STORAGE = "{{cookiecutter.project_slug}}.utils.storages.MediaRootGoogleCloudStorage"
|
||||
MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/"
|
||||
{%- endif %}
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
{% if cookiecutter.cloud_provider == 'AWS' -%}
|
||||
from storages.backends.s3boto3 import S3Boto3Storage # noqa E402
|
||||
|
||||
|
||||
class StaticRootS3Boto3Storage(S3Boto3Storage):
|
||||
location = "static"
|
||||
default_acl = "public-read"
|
||||
|
||||
|
||||
class MediaRootS3Boto3Storage(S3Boto3Storage):
|
||||
location = "media"
|
||||
file_overwrite = False
|
||||
{%- elif cookiecutter.cloud_provider == 'GCP' -%}
|
||||
from storages.backends.gcloud import GoogleCloudStorage # noqa E402
|
||||
|
||||
|
||||
class StaticRootGoogleCloudStorage(GoogleCloudStorage):
|
||||
location = "static"
|
||||
default_acl = "publicRead"
|
||||
|
||||
|
||||
class MediaRootGoogleCloudStorage(GoogleCloudStorage):
|
||||
location = "media"
|
||||
file_overwrite = False
|
||||
{%- endif %}
|
Loading…
Reference in New Issue
Block a user