From 8d9f8096f5de6bd4d9d8ed2fe05ce8bfbd6792d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=A5=D0=BB=D0=B8?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD=D0=B5=D0=BD=D0=BA=D0=BE=D0=B2?= Date: Fri, 5 Jul 2024 13:54:06 +0300 Subject: [PATCH] =?UTF-8?q?=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D1=91=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D1=84=D0=BE=D1=82=D0=BE=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=84=D0=B8=D0=BB=D1=8F=20=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=BC=20volume:=20backend=5Fstatic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/profile.py | 4 ++-- app/services/utils.py | 2 +- infra/docker-compose.yml | 3 +++ media/{cats => default_photo}/cat1.png | Bin media/{cats => default_photo}/cat2.png | Bin media/{cats => default_photo}/cat3.png | Bin media/{cats => default_photo}/cat4.png | Bin media/{cats => default_photo}/cat5.png | Bin 8 files changed, 6 insertions(+), 3 deletions(-) rename media/{cats => default_photo}/cat1.png (100%) rename media/{cats => default_photo}/cat2.png (100%) rename media/{cats => default_photo}/cat3.png (100%) rename media/{cats => default_photo}/cat4.png (100%) rename media/{cats => default_photo}/cat5.png (100%) diff --git a/app/models/profile.py b/app/models/profile.py index bd3d3df..5fa1e59 100644 --- a/app/models/profile.py +++ b/app/models/profile.py @@ -19,7 +19,7 @@ def _random_photo(path: Path): """Возвращает рандомный файл из указанной папки.""" - files = [f'cats/{file.name}' for file in path.iterdir()] + files = [f'default_photo/{file.name}' for file in path.iterdir()] random_index = randint(0, len(files) - 1) return str(files[random_index]) @@ -44,7 +44,7 @@ class Profile(Base): image: Mapped[str] = Column( String(), nullable=True, - default=_random_photo(settings.base_dir / settings.media_url / 'cats/') + default=_random_photo(settings.base_dir / settings.media_url / 'default_photo/') ) def __repr__(self): diff --git a/app/services/utils.py b/app/services/utils.py index 2f31828..8d6c945 100644 --- a/app/services/utils.py +++ b/app/services/utils.py @@ -19,7 +19,7 @@ def end(self): def create_filename(file: UploadFile) -> str: """Создаёт имя файла.""" file_extension = file.filename.split('.')[-1] - return f'{uuid4()}.{file_extension}' + return f'photo_profile/{uuid4()}.{file_extension}' async def save_content(file: UploadFile): diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index 80a2358..406d76f 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -25,6 +25,8 @@ services: - ./.env depends_on: - db + volumes: + - backend_static:/app/media/photo_profile/ nginx: container_name: proxy @@ -39,3 +41,4 @@ services: volumes: db_volume_qactf: + backend_static: \ No newline at end of file diff --git a/media/cats/cat1.png b/media/default_photo/cat1.png similarity index 100% rename from media/cats/cat1.png rename to media/default_photo/cat1.png diff --git a/media/cats/cat2.png b/media/default_photo/cat2.png similarity index 100% rename from media/cats/cat2.png rename to media/default_photo/cat2.png diff --git a/media/cats/cat3.png b/media/default_photo/cat3.png similarity index 100% rename from media/cats/cat3.png rename to media/default_photo/cat3.png diff --git a/media/cats/cat4.png b/media/default_photo/cat4.png similarity index 100% rename from media/cats/cat4.png rename to media/default_photo/cat4.png diff --git a/media/cats/cat5.png b/media/default_photo/cat5.png similarity index 100% rename from media/cats/cat5.png rename to media/default_photo/cat5.png