From 2577d8d9cf0a4da5c4576d40cfa2d2fc51becfd7 Mon Sep 17 00:00:00 2001 From: Rahul Gupta Date: Mon, 1 Aug 2022 22:27:26 +0530 Subject: [PATCH] feat[backend]: add s3 storage chore[backend]: update requirements.txt, rename image path --- .env.example | 6 +++- .gitignore | 1 + about/models.py | 2 +- backend/settings.py | 46 +++++++++---------------- gallery/models.py | 2 +- requirements.txt | 83 ++++++++++++++++++++++++++++----------------- shop/models.py | 6 ++-- 7 files changed, 79 insertions(+), 67 deletions(-) diff --git a/.env.example b/.env.example index 0aafb75..4dec200 100644 --- a/.env.example +++ b/.env.example @@ -2,4 +2,8 @@ STRIPE_TEST_PUBLIC_KEY= STRIPE_TEST_SECRET_KEY= EMAIL_HOST_USER=email_for_sending_emails -EMAIL_HOST_PASSWORD=email_password \ No newline at end of file +EMAIL_HOST_PASSWORD=email_password + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_STORAGE_BUCKET_NAME= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9db0883..22b8094 100644 --- a/.gitignore +++ b/.gitignore @@ -145,3 +145,4 @@ config.py .vscode/ .DS_Store +static/ diff --git a/about/models.py b/about/models.py index 20a5dad..0127f9c 100644 --- a/about/models.py +++ b/about/models.py @@ -2,7 +2,7 @@ class AboutDetail(models.Model): - image = models.ImageField(upload_to='about_images') + image = models.ImageField(upload_to='about-images') heading1 = models.CharField(max_length=30) heading2 = models.CharField(max_length=30) paragraph = models.TextField() diff --git a/backend/settings.py b/backend/settings.py index 06ea99a..89ac6f2 100644 --- a/backend/settings.py +++ b/backend/settings.py @@ -18,7 +18,6 @@ ALLOWED_HOSTS = ['*'] - # Application definition INSTALLED_APPS = [ @@ -41,7 +40,8 @@ 'gallery.apps.GalleryConfig', 'shop.apps.ShopConfig', 'about.apps.AboutConfig', - 'emailverification' + 'emailverification', + 'storages', ] SITE_ID = 3 @@ -128,6 +128,7 @@ # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' +STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATICFILES_DIRS = [ os.path.join(BASE_DIR, "frontend/build/static"), @@ -160,33 +161,18 @@ ] } +# S3 BUCKET CONFIG + +AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID') +AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY') +AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME') +AWS_QUERYSTRING_AUTH = False + +AWS_S3_FILE_OVERWRITE = False +AWS_DEFAULT_ACL = None +AWS_S3_REGION_NAME = 'ap-south-1' +DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' +STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' STRIPE_PUBLIC_KEY = config('STRIPE_TEST_PUBLIC_KEY') -STRIPE_SECRET_KEY = config('STRIPE_TEST_SECRET_KEY') - -SOCIALACCOUNT_EMAIL_VERIFICATION = 'none' - - -SOCIALACCOUNT_PROVIDERS = { - 'facebook': { - 'METHOD': 'oauth2', - 'SDK_URL': '//connect.facebook.net/{locale}/sdk.js', - 'SCOPE': ['email', 'public_profile'], - 'AUTH_PARAMS': {'auth_type': 'reauthenticate'}, - 'INIT_PARAMS': {'cookie': True}, - 'FIELDS': [ - 'id', - 'first_name', - 'last_name', - 'middle_name', - 'name', - 'name_format', - 'picture', - 'short_name' - ], - 'EXCHANGE_TOKEN': True, - 'LOCALE_FUNC': 'path.to.callable', - 'VERIFIED_EMAIL': False, - 'VERSION': 'v7.0', - } -} +STRIPE_SECRET_KEY = config('STRIPE_TEST_SECRET_KEY') \ No newline at end of file diff --git a/gallery/models.py b/gallery/models.py index 12e256c..964f6c3 100644 --- a/gallery/models.py +++ b/gallery/models.py @@ -3,7 +3,7 @@ class GalleryImage(models.Model): title = models.CharField(max_length=30) - imagesrc = models.ImageField(upload_to='gallery_images') + imagesrc = models.ImageField(upload_to='gallery-images') date_uploaded = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) diff --git a/requirements.txt b/requirements.txt index 3b9a5f1..022746e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,31 +1,52 @@ -asgiref==3.2.10 -autopep8==1.5.3 -certifi==2020.6.20 -chardet==3.0.4 -DateTime==4.3 -defusedxml==0.6.0 -dj-rest-auth==1.0.9 -Django==3.0.7 -django-admin-interface==0.12.2 -django-allauth==0.42.0 -django-colorfield==0.3.1 -django-cors-headers==3.4.0 -django-flat-responsive==2.0 -django-flat-theme==1.1.4 -django-rest-framework==0.1.0 -djangorestframework==3.11.0 -idna==2.10 -oauthlib==3.1.0 -pycodestyle==2.6.0 -python-decouple==3.3 -python3-openid==3.2.0 -pytz==2020.1 -requests==2.24.0 -requests-oauthlib==1.3.0 -six==1.15.0 -sqlparse==0.3.1 -stripe==2.49.0 -toml==0.10.1 -urllib3==1.25.9 -zope.interface==5.1.0 -Pillow==9.2.0 +asgiref==3.2.10 +async-generator==1.10 +attrs==21.2.0 +autopep8==1.5.3 +boto3==1.24.42 +botocore==1.27.42 +certifi==2020.6.20 +cffi==1.15.0 +chardet==3.0.4 +cryptography==36.0.1 +DateTime==4.3 +defusedxml==0.6.0 +dj-rest-auth==1.0.9 +Django==3.0.7 +django-admin-interface==0.12.2 +django-colorfield==0.3.1 +django-cors-headers==3.4.0 +django-flat-responsive==2.0 +django-flat-theme==1.1.4 +django-rest-framework==0.1.0 +django-storages==1.12.3 +djangorestframework==3.11.0 +greenlet==1.1.2 +h11==0.12.0 +idna==2.10 +jmespath==1.0.1 +msgpack==1.0.3 +oauthlib==3.1.0 +outcome==1.1.0 +Pillow==9.2.0 +pycodestyle==2.6.0 +pycparser==2.21 +pynvim==0.4.3 +pyOpenSSL==21.0.0 +python-dateutil==2.8.2 +python-decouple==3.3 +python3-openid==3.2.0 +pytz==2020.1 +requests==2.24.0 +requests-oauthlib==1.3.0 +s3transfer==0.6.0 +six==1.15.0 +sniffio==1.2.0 +sortedcontainers==2.4.0 +sqlparse==0.3.1 +stripe==2.49.0 +toml==0.10.1 +trio==0.19.0 +trio-websocket==0.9.2 +urllib3==1.25.9 +wsproto==1.0.0 +zope.interface==5.1.0 diff --git a/shop/models.py b/shop/models.py index 7cfffee..b371bd0 100644 --- a/shop/models.py +++ b/shop/models.py @@ -14,9 +14,9 @@ def __str__(self): class Item(models.Model): title = models.CharField(max_length=30) - keyimage = models.ImageField(upload_to='shop_images') - subimage1 = models.ImageField(upload_to='shop_images') - subimage2 = models.ImageField(upload_to='shop_images', blank=True) + keyimage = models.ImageField(upload_to='shop-images') + subimage1 = models.ImageField(upload_to='shop-images') + subimage2 = models.ImageField(upload_to='shop-images', blank=True) price = models.FloatField() discount_price = models.FloatField(blank=True, null=True) designed_by = models.CharField(max_length=30)