Skip to content

Commit

Permalink
add management command to copy demo images
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienReuiller committed Mar 22, 2024
1 parent 1fd1fc3 commit cbd30d9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lemarche/cms/management/commands/populate_demo_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os

from django.core.files.storage import default_storage

from lemarche.utils.commands import BaseCommand


class Command(BaseCommand):
"""
Script to copy images in Django storage system, to use them in fixtures for example
Usage:
python manage.py populate_demo_images --images_demo=lemarche/fixtures/django/images/ --folder=original_images
"""

help = "Ajoute des images de démonstrations au système de stockage de Django"

def add_arguments(self, parser):
parser.add_argument(
"--images_demo", dest="images_demo", type=str, help="Chemin du dossier contenant les images de démo"
)
parser.add_argument(
"--folder", dest="folder", type=str, help="Chemin du dossier de destination", default="original_images"
)

def handle(self, *args, **options):
images_folder = options["images_demo"]
dest_folder = options["folder"]

for image_name in os.listdir(images_folder):
image_path = f"{dest_folder}/{image_name}"
if not default_storage.exists(image_path):
with open(os.path.join(images_folder, image_name), "rb") as image_file:
default_storage.save(image_path, image_file)

0 comments on commit cbd30d9

Please sign in to comment.