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 django.core.management.base import BaseCommand
|
||||||
from photologue.models import Gallery
|
from photologue.models import Gallery
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from tqdm import tqdm
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
|
|
@ -15,22 +14,22 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
media_dir = Path(settings.MEDIA_ROOT)
|
media_dir = Path(settings.MEDIA_ROOT)
|
||||||
for gallery in tqdm(Gallery.objects.all()):
|
for gallery in Gallery.objects.all():
|
||||||
# Create gallery directory
|
# Create gallery directory
|
||||||
gallery_year = str(gallery.extended.date_start.year)
|
gallery_year = str(gallery.extended.date_start.year)
|
||||||
gallery_dir = Path('photos') / gallery_year / gallery.slug
|
gallery_dir = Path('photos') / gallery_year / gallery.slug
|
||||||
gallery_path = media_dir / gallery_dir
|
gallery_path = media_dir / gallery_dir
|
||||||
if not gallery_path.exists():
|
if not gallery_path.exists():
|
||||||
tqdm.write(f"Creating {gallery_dir}")
|
self.stdout.write(f"Creating {gallery_dir}")
|
||||||
if options["apply"]:
|
if options["apply"]:
|
||||||
gallery_path.mkdir(parents=True)
|
gallery_path.mkdir(parents=True)
|
||||||
|
|
||||||
# Move photos in gallery folder
|
# 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])
|
photo_name = str(gallery_dir / photo.image.name.split("/")[-1])
|
||||||
if photo.image.name == photo_name:
|
if photo.image.name == photo_name:
|
||||||
continue
|
continue
|
||||||
tqdm.write(f" Moving {photo.image.name} -> {photo_name}")
|
self.stdout.write(f" Moving {photo.image.name} -> {photo_name}")
|
||||||
if options["apply"]:
|
if options["apply"]:
|
||||||
if not (media_dir / photo_name).exists():
|
if not (media_dir / photo_name).exists():
|
||||||
os.rename(photo.image.path, media_dir / photo_name)
|
os.rename(photo.image.path, media_dir / photo_name)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue