[pricelist] now can delete pictures, add no-image
This commit is contained in:
parent
6dbb135621
commit
6fce88c120
|
@ -6,7 +6,7 @@ from flaschengeist.config import config
|
|||
from flaschengeist.database import db
|
||||
from .models import Drink, DrinkPrice, Ingredient, Tag, DrinkType, DrinkPriceVolume, DrinkIngredient, ExtraIngredient
|
||||
|
||||
from flaschengeist.utils.picture import save_picture, get_picture, delete_picture
|
||||
from flaschengeist.utils.picture import save_picture, get_picture, delete_picture, get_no_image
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
|
@ -383,13 +383,13 @@ def save_drink_picture(identifier, file):
|
|||
def get_drink_picture(identifier, size=None):
|
||||
drink = get_drink(identifier)
|
||||
if not drink.uuid:
|
||||
raise FileNotFoundError
|
||||
return get_no_image()
|
||||
path = config["pricelist"]["path"]
|
||||
return get_picture(f"{path}/{drink.uuid}")
|
||||
|
||||
def delete_drink_picture(identifier):
|
||||
drink = get_drink(identifier)
|
||||
if not drink.uuid:
|
||||
if drink.uuid:
|
||||
delete_picture(f"{config['pricelist']['path']}/{drink.uuid}")
|
||||
drink.uuid = None
|
||||
db.session.commit()
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 46 KiB |
|
@ -1,4 +1,4 @@
|
|||
import os, sys
|
||||
import os, sys, shutil
|
||||
from PIL import Image
|
||||
from flask import Response
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
@ -20,12 +20,18 @@ def save_picture(picture, path):
|
|||
if file_type != "png":
|
||||
image.save(f"{filename}.png", "PNG")
|
||||
os.remove(f"{filename}.{file_type}")
|
||||
image.show()
|
||||
for thumbnail_size in thumbnail_sizes:
|
||||
work_image = image.copy()
|
||||
work_image.thumbnail(thumbnail_size)
|
||||
work_image.save(f"{filename}-{thumbnail_size[0]}.png", "PNG")
|
||||
|
||||
def get_no_image():
|
||||
path = os.path.dirname(__file__)
|
||||
with open(f"{path}/no-image.png", "rb") as file:
|
||||
image = file.read()
|
||||
response = Response(image, mimetype="image/png")
|
||||
response.add_etag()
|
||||
return response
|
||||
|
||||
def get_picture(path, size=None):
|
||||
try:
|
||||
|
@ -45,8 +51,10 @@ def get_picture(path, size=None):
|
|||
response.add_etag()
|
||||
return response
|
||||
except:
|
||||
raise FileNotFoundError
|
||||
get_no_image()
|
||||
|
||||
|
||||
|
||||
|
||||
def delete_picture(path):
|
||||
os.remove(path)
|
||||
|
||||
shutil.rmtree(path)
|
||||
|
|
Loading…
Reference in New Issue