diff --git a/application/dash/templates/edit_service.html b/application/dash/templates/edit_service.html index 0ed5287..2ccd3a6 100644 --- a/application/dash/templates/edit_service.html +++ b/application/dash/templates/edit_service.html @@ -5,7 +5,7 @@ Edit service {% endblock %} {% block content %} -
+ {{ form.hidden_tag() }}
{{ form.name.label }}
{{ form.name() }} diff --git a/application/dash/views.py b/application/dash/views.py index 71b05ac..a8192fc 100644 --- a/application/dash/views.py +++ b/application/dash/views.py @@ -3,9 +3,7 @@ from flask import Blueprint, render_template, redirect, url_for from application.dash.forms import ServiceForm from flask_login import login_required, current_user # type: ignore from application.dash.models import Service -import os -from application import app -from werkzeug.utils import secure_filename +from application.utils import saveImage dash_blueprint = Blueprint("dash", __name__, template_folder="templates") @@ -44,15 +42,7 @@ def service(): url = service_form.url.data filename2 = "google.png" if 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 + filename2 = saveImage(image) new_service = Service( name=name, # type: ignore @@ -85,14 +75,35 @@ def edit_service(service_id: int): # Correcte gebruiker form = ServiceForm() - print("test") if form.validate_on_submit(): # type: ignore - print("test2") - if service.name != form.name.data or service.url != form.url.data: + commit = False + if service.name != form.name.data: service.name = form.name.data + commit = True + if 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() return redirect(url_for("dash.index")) # Fill in correct data form = ServiceForm(name=service.name, url=service.url) 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 +""" diff --git a/application/static/icons/1/Google__G__logo.svg.png b/application/static/icons/1/Google__G__logo.svg.png new file mode 100644 index 0000000..ef2d979 Binary files /dev/null and b/application/static/icons/1/Google__G__logo.svg.png differ diff --git a/application/static/icons/google.png b/application/static/icons/google.png index ef2d979..893d332 100644 Binary files a/application/static/icons/google.png and b/application/static/icons/google.png differ diff --git a/application/utils.py b/application/utils.py new file mode 100644 index 0000000..9cbc656 --- /dev/null +++ b/application/utils.py @@ -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