Fixed? Idek

This commit is contained in:
2025-04-16 15:38:15 +02:00
parent b8a131e990
commit a7d68ae07d
5 changed files with 44 additions and 16 deletions

View File

@@ -5,7 +5,7 @@ Edit service
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<form class="form bg-body-tertiary" method="POST"> <form class="form bg-body-tertiary" method="POST" enctype="multipart/form-data">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<div> <div>
{{ form.name.label }} <br> {{ form.name() }} {{ form.name.label }} <br> {{ form.name() }}

View File

@@ -3,9 +3,7 @@ from flask import Blueprint, render_template, redirect, url_for
from application.dash.forms import ServiceForm from application.dash.forms import ServiceForm
from flask_login import login_required, current_user # type: ignore from flask_login import login_required, current_user # type: ignore
from application.dash.models import Service from application.dash.models import Service
import os from application.utils import saveImage
from application import app
from werkzeug.utils import secure_filename
dash_blueprint = Blueprint("dash", __name__, template_folder="templates") dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
@@ -44,15 +42,7 @@ def service():
url = service_form.url.data url = service_form.url.data
filename2 = "google.png" filename2 = "google.png"
if image: if image:
filename = secure_filename(image.filename) filename2 = saveImage(image)
save_path = os.path.join(
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
filename2 = str(current_user.id) + "/" + filename
new_service = Service( new_service = Service(
name=name, # type: ignore name=name, # type: ignore
@@ -85,14 +75,35 @@ def edit_service(service_id: int):
# Correcte gebruiker # Correcte gebruiker
form = ServiceForm() form = ServiceForm()
print("test")
if form.validate_on_submit(): # type: ignore if form.validate_on_submit(): # type: ignore
print("test2") commit = False
if service.name != form.name.data or service.url != form.url.data: if service.name != form.name.data:
service.name = form.name.data service.name = form.name.data
commit = True
if service.url != form.url.data:
service.url = form.url.data service.url = form.url.data
commit = True
if form.image.data:
service.icon = saveImage(form.image.data)
commit = True
if commit:
db.session.commit() db.session.commit()
return redirect(url_for("dash.index")) return redirect(url_for("dash.index"))
# Fill in correct data # Fill in correct data
form = ServiceForm(name=service.name, url=service.url) form = ServiceForm(name=service.name, url=service.url)
return render_template("edit_service.html", form=form) return render_template("edit_service.html", form=form)
"""
def saveImage(image: ...):
filename = secure_filename(image.filename)
save_path = os.path.join(
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
filename2 = str(current_user.id) + "/" + filename
return filename2
"""

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 86 KiB

After

Width:  |  Height:  |  Size: 16 KiB

17
application/utils.py Normal file
View File

@@ -0,0 +1,17 @@
from werkzeug.utils import secure_filename
import os
from application import app
from flask_login import current_user # type: ignore
def saveImage(image: ...):
filename = secure_filename(image.filename)
save_path = os.path.join(
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
filename2 = str(current_user.id) + "/" + filename
return filename2