mirror of
https://github.com/ae-utbm/sith.git
synced 2025-04-15 18:40:23 +00:00
fixed string conversion bugs and logical error
This commit is contained in:
parent
c0abdcdd7e
commit
468ff731fa
@ -1,10 +1,9 @@
|
||||
import pathlib
|
||||
|
||||
from django.apps import apps
|
||||
from django.core.management.base import BaseCommand
|
||||
from PIL import Image
|
||||
|
||||
from sith.settings import BASE_DIR
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def add_arguments(self, parser):
|
||||
@ -13,22 +12,28 @@ class Command(BaseCommand):
|
||||
parser.add_argument("-f", "--force", action="store_true")
|
||||
|
||||
def handle(self, number: int, path: pathlib.Path, force: int, *args, **options):
|
||||
if path.exists():
|
||||
dest_path = pathlib.Path(
|
||||
BASE_DIR / "core" / "static" / "core" / "img" / f"promo_{number}.png"
|
||||
)
|
||||
if dest_path.exists() and not force:
|
||||
over = input("File already exists, do you want to overwrite it? (y/N):")
|
||||
if over.lower() != "y":
|
||||
return
|
||||
try:
|
||||
with Image.open(options["path"]) as im:
|
||||
im.resize((120, 120)).save(dest_path, format="PNG")
|
||||
|
||||
self.stdout.write(
|
||||
f"Promo logo moved and resized successfully at {dest_path}"
|
||||
)
|
||||
except IOError as ioe:
|
||||
self.stderr.write(ioe)
|
||||
else:
|
||||
if not path.exists() or path.is_dir():
|
||||
self.stdout.write("input file does not exist.")
|
||||
return
|
||||
|
||||
dest_path = pathlib.Path(
|
||||
pathlib.Path(apps.get_app_config("core").path)
|
||||
/ "static"
|
||||
/ "core"
|
||||
/ "img"
|
||||
/ f"promo_{number}.png"
|
||||
)
|
||||
|
||||
if dest_path.exists() and not force:
|
||||
over = input("File already exists, do you want to overwrite it? (y/N):")
|
||||
if over.lower() != "y":
|
||||
return
|
||||
try:
|
||||
with Image.open(path) as im:
|
||||
im.resize((120, 120)).save(dest_path, format="PNG")
|
||||
|
||||
self.stdout.write(
|
||||
f"Promo logo moved and resized successfully at {dest_path}"
|
||||
)
|
||||
except IOError as ioe:
|
||||
self.stderr.write(ioe)
|
||||
|
Loading…
x
Reference in New Issue
Block a user