diff --git a/application/dash/forms.py b/application/dash/forms.py index 76397af..69bfe06 100644 --- a/application/dash/forms.py +++ b/application/dash/forms.py @@ -1,7 +1,7 @@ from flask_wtf import FlaskForm # type: ignore from wtforms import StringField, SubmitField, URLField from wtforms.validators import DataRequired -from flask_wtf.file import FileField, FileAllowed, FileRequired # type: ignore +from flask_wtf.file import FileField, FileAllowed # type: ignore class ServiceForm(FlaskForm): @@ -10,7 +10,6 @@ class ServiceForm(FlaskForm): image = FileField( "Icon:", validators=[ - FileRequired(), FileAllowed(["jpg", "jpeg", "png"], "Unsupported file format"), ], ) diff --git a/application/dash/models.py b/application/dash/models.py index 919ed95..588a913 100644 --- a/application/dash/models.py +++ b/application/dash/models.py @@ -5,7 +5,7 @@ class Service(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String, nullable=False) url = db.Column(db.String, nullable=False) - icon = db.Column(db.String, nullable=False, default="google.png") + icon = db.Column(db.String, default="google.png") user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) diff --git a/application/dash/views.py b/application/dash/views.py index aea0bc8..71b05ac 100644 --- a/application/dash/views.py +++ b/application/dash/views.py @@ -42,20 +42,23 @@ def service(): image = service_form.image.data name = service_form.name.data url = service_form.url.data - 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 = "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 new_service = Service( name=name, # type: ignore url=url, # type: ignore user_id=current_user.id, - icon=str(current_user.id) + "/" + filename, + icon=filename2, ) # type: ignore db.session.add(new_service) db.session.commit() @@ -82,7 +85,9 @@ 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: service.name = form.name.data service.url = form.url.data