rename_media: do not depend on tqdm
This commit is contained in:
parent
19eb5a420e
commit
712bf6ad85
1 changed files with 4 additions and 5 deletions
|
|
@ -4,7 +4,6 @@ import os
|
|||
from django.core.management.base import BaseCommand
|
||||
from photologue.models import Gallery
|
||||
from django.conf import settings
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
|
|
@ -15,22 +14,22 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
media_dir = Path(settings.MEDIA_ROOT)
|
||||
for gallery in tqdm(Gallery.objects.all()):
|
||||
for gallery in Gallery.objects.all():
|
||||
# Create gallery directory
|
||||
gallery_year = str(gallery.extended.date_start.year)
|
||||
gallery_dir = Path('photos') / gallery_year / gallery.slug
|
||||
gallery_path = media_dir / gallery_dir
|
||||
if not gallery_path.exists():
|
||||
tqdm.write(f"Creating {gallery_dir}")
|
||||
self.stdout.write(f"Creating {gallery_dir}")
|
||||
if options["apply"]:
|
||||
gallery_path.mkdir(parents=True)
|
||||
|
||||
# Move photos in gallery folder
|
||||
for photo in tqdm(gallery.photos.all()):
|
||||
for photo in gallery.photos.all():
|
||||
photo_name = str(gallery_dir / photo.image.name.split("/")[-1])
|
||||
if photo.image.name == photo_name:
|
||||
continue
|
||||
tqdm.write(f" Moving {photo.image.name} -> {photo_name}")
|
||||
self.stdout.write(f" Moving {photo.image.name} -> {photo_name}")
|
||||
if options["apply"]:
|
||||
if not (media_dir / photo_name).exists():
|
||||
os.rename(photo.image.path, media_dir / photo_name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue