From c95d86545435cdf2e873cae3926cc9c20c264ebf Mon Sep 17 00:00:00 2001 From: Stef Date: Wed, 16 Apr 2025 15:06:01 +0200 Subject: [PATCH] 123 --- application/dash/models.py | 4 +++- application/dash/views.py | 7 +++++-- application/static/icons/{ => 1}/123123123.png | Bin 3 files changed, 8 insertions(+), 3 deletions(-) rename application/static/icons/{ => 1}/123123123.png (100%) diff --git a/application/dash/models.py b/application/dash/models.py index 59f9ea6..919ed95 100644 --- a/application/dash/models.py +++ b/application/dash/models.py @@ -9,7 +9,9 @@ class Service(db.Model): user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) - def __init__(self, name: str, url: str, user_id: int, icon: str): + def __init__( + self, name: str, url: str, user_id: int, icon: str = "google.png" + ): self.name = name self.url = url self.user_id = user_id diff --git a/application/dash/views.py b/application/dash/views.py index 94f1175..4a6b65b 100644 --- a/application/dash/views.py +++ b/application/dash/views.py @@ -44,15 +44,18 @@ def service(): url = service_form.url.data filename = secure_filename(image.filename) save_path = os.path.join( - app.config["UPLOAD_FOLDER"], filename # type: ignore + app.config["UPLOAD_FOLDER"], # type: ignore + str(current_user.id), + filename, ) + os.makedirs(os.path.dirname(save_path), exist_ok=True) image.save(save_path) # type: ignore new_service = Service( name=name, # type: ignore url=url, # type: ignore user_id=current_user.id, - icon=filename, # type: ignore + icon=os.path.join(str(current_user.id), filename), # type: ignore ) db.session.add(new_service) db.session.commit() diff --git a/application/static/icons/123123123.png b/application/static/icons/1/123123123.png similarity index 100% rename from application/static/icons/123123123.png rename to application/static/icons/1/123123123.png