Skip to content

Commit

Permalink
For #71 start aws s3
Browse files Browse the repository at this point in the history
  • Loading branch information
lissa3 committed Nov 3, 2023
1 parent df56663 commit c3efad7
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
4 changes: 3 additions & 1 deletion reqs/req.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ django-ckeditor-5
unidecode
psycopg2==2.9.5
django-rosetta==0.9.9
django-recaptcha==3.0.0
django-recaptcha==3.0.0
django-storages==1.14.2
boto3==1.28.77
20 changes: 20 additions & 0 deletions reqs/req.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#
asgiref==3.6.0
# via django
boto3==1.28.77
# via -r reqs\req.in
botocore==1.31.77
# via
# boto3
# s3transfer
certifi==2023.5.7
# via
# requests
Expand All @@ -28,6 +34,7 @@ django==4.2.1
# django-modeltranslation
# django-recaptcha
# django-rosetta
# django-storages
# django-taggit
# django-treebeard
django-allauth==0.54.0
Expand All @@ -48,6 +55,8 @@ django-recaptcha==3.0.0
# via -r reqs\req.in
django-rosetta==0.9.9
# via -r reqs\req.in
django-storages==1.14.2
# via -r reqs\req.in
django-taggit==3.1.0
# via -r reqs\req.in
django-treebeard==4.7
Expand All @@ -56,6 +65,10 @@ django-widget-tweaks==1.4.12
# via -r reqs\req.in
idna==3.4
# via requests
jmespath==1.0.1
# via
# boto3
# botocore
oauthlib==3.2.2
# via requests-oauthlib
pillow==9.5.0
Expand All @@ -70,6 +83,8 @@ pycparser==2.21
# via cffi
pyjwt[crypto]==2.7.0
# via django-allauth
python-dateutil==2.8.2
# via botocore
python-magic-bin==0.4.14
# via -r reqs\req.in
python3-openid==3.2.0
Expand All @@ -83,8 +98,12 @@ requests==2.30.0
# requests-oauthlib
requests-oauthlib==1.3.1
# via django-allauth
s3transfer==0.7.0
# via boto3
sentry-sdk==1.29.2
# via -r reqs\req.in
six==1.16.0
# via python-dateutil
sqlparse==0.4.4
# via django
typing-extensions==4.7.1
Expand All @@ -95,5 +114,6 @@ unidecode==1.3.6
# via -r reqs\req.in
urllib3==2.0.2
# via
# botocore
# requests
# sentry-sdk
4 changes: 3 additions & 1 deletion reqs/reqlinux.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ django-ckeditor-5==0.2.9
unidecode==1.3.6
psycopg2==2.9.5
django-rosetta==0.9.9
django-recaptcha==3.0.0
django-recaptcha==3.0.0
django-storages==1.14.2
boto3==1.28.77
3 changes: 3 additions & 0 deletions reqs/reqlinux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ django==4.2.1
# django-modeltranslation
# django-recaptcha
# django-rosetta
# django-storages
# django-taggit
# django-treebeard
django-allauth==0.54.0
Expand All @@ -48,6 +49,8 @@ django-recaptcha==3.0.0
# via -r reqs\reqlinux.in
django-rosetta==0.9.9
# via -r reqs\reqlinux.in
django-storages==1.14.2
# via -r reqs\reqlinux.in
django-taggit==3.1.0
# via -r reqs\reqlinux.in
django-treebeard==4.7
Expand Down
15 changes: 15 additions & 0 deletions sandbox/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,18 @@
# RECAPTCHA_PUBLIC_KEY = env("RECAPTCHA_PUBLIC_KEY")
# RECAPTCHA_PRIVATE_KEY = env("RECAPTCHA_PRIVATE_KEY")
SILENCED_SYSTEM_CHECKS = ["captcha.recaptcha_test_key_error"]


# AWS

AWS_ACCESS_KEY_ID = env("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = env("AWS_STORAGE_BUCKET_NAME")

AWS_S3_FILE_OVERWRITE = False
AWS_DEFAULT_ACL = None
DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"

AWS_QUERYSTRING_AUTH = False # key will be not present in url
AWS_S3_MAX_MEMORY_SIZE = 2200000
AWS_S3_REGION_NAME = "eu-central-1"
4 changes: 2 additions & 2 deletions sandbox/conf/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# use in-memory-db
# let op: email confirmation will be NOT in console
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"

# EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

USE_CAPCHA = False
26 changes: 22 additions & 4 deletions src/profiles/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import uuid

from boto3.session import Session
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.shortcuts import reverse
Expand Down Expand Up @@ -37,10 +39,26 @@ def get_absolute_url(self):
def __str__(self) -> str:
return self.user.username

def delete(self):
"""if profile obj deleted; remove avatar file"""
self.avatar.delete()
super().delete()
# def delete(self):
# """if profile obj deleted; remove avatar file"""
# self.avatar.delete()
# super().delete()
# def delete(self, *args, **kwargs):
# session = Session (settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
# s3_resource = session.resource('s3')
# s3_bucket = s3_resource.Bucket(settings.AWS_STORAGE_BUCKET_NAME)

# file_path = f"avatar/{self.id}" + str(self.avatar)
# print("path is ",file_path)
# response = s3_bucket.delete_objects(
# Delete={
# 'Objects': [
# {
# 'Key': file_path
# }
# ]
# })
# super().delete(*args, **kwargs)


class ProfileChart(Profile):
Expand Down

0 comments on commit c3efad7

Please sign in to comment.