categorylanri import qilish qoshildi
This commit is contained in:
@@ -1,8 +1,20 @@
|
||||
from typing import Optional, Union
|
||||
|
||||
from storages.backends.s3boto3 import S3Boto3Storage
|
||||
from config.env import env
|
||||
|
||||
|
||||
class CustomMediaStorage(S3Boto3Storage):
|
||||
"""Media fayllar uchun nisbiy URL qaytaradigan storage."""
|
||||
def url(self, name, parameters=None, expire=None, http_method=None):
|
||||
# Name: products/img.png -> /resources/media/products/img.png
|
||||
return f"/resources/media/{name}"
|
||||
|
||||
class CustomStaticStorage(S3Boto3Storage):
|
||||
"""Static fayllar uchun nisbiy URL qaytaradigan storage."""
|
||||
def url(self, name, parameters=None, expire=None, http_method=None):
|
||||
return f"/resources/static/{name}"
|
||||
|
||||
|
||||
class Storage:
|
||||
|
||||
storages = ["AWS", "MINIO", "FILE", "STATIC"]
|
||||
@@ -16,13 +28,15 @@ class Storage:
|
||||
def get_backend(self) -> Optional[str]:
|
||||
match self.storage:
|
||||
case "AWS" | "MINIO":
|
||||
return "storages.backends.s3boto3.S3Boto3Storage"
|
||||
if self.sorage_type == "default":
|
||||
return "core.utils.storage.CustomMediaStorage"
|
||||
return "core.utils.storage.CustomStaticStorage"
|
||||
case "FILE":
|
||||
return "django.core.files.storage.FileSystemStorage"
|
||||
case "STATIC":
|
||||
return "django.contrib.staticfiles.storage.StaticFilesStorage"
|
||||
|
||||
def get_options(self) -> Optional[str]:
|
||||
def get_options(self) -> Optional[dict]:
|
||||
match self.storage:
|
||||
case "AWS" | "MINIO":
|
||||
if self.sorage_type == "default":
|
||||
@@ -31,3 +45,4 @@ class Storage:
|
||||
return {"bucket_name": env.str("STORAGE_BUCKET_STATIC")}
|
||||
case _:
|
||||
return {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user