From b8152ba6cbfb33c64e4c0b8d48bf78d592c5bb92 Mon Sep 17 00:00:00 2001 From: Stef Date: Wed, 16 Apr 2025 14:51:06 +0200 Subject: [PATCH] Custom images --- application/__init__.py | 5 +++ application/dash/forms.py | 8 ++++ application/dash/models.py | 4 +- application/dash/static/style.css | 22 ----------- application/dash/templates/add_service.html | 41 ++++++++++++-------- application/dash/templates/dashboard.html | 3 +- application/dash/views.py | 11 ++++++ application/static/icons/123123123.png | Bin 0 -> 11202 bytes application/static/icons/google.png | Bin 0 -> 87916 bytes test/123123123.png | Bin 0 -> 11202 bytes 10 files changed, 53 insertions(+), 41 deletions(-) delete mode 100644 application/dash/static/style.css create mode 100644 application/static/icons/123123123.png create mode 100644 application/static/icons/google.png create mode 100644 test/123123123.png diff --git a/application/__init__.py b/application/__init__.py index b3b5ada..d4cd08f 100644 --- a/application/__init__.py +++ b/application/__init__.py @@ -2,12 +2,17 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from flask_login import LoginManager # type: ignore +import os # App Config app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///services.sqlite" app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False # Wat is dit? app.config["SECRET_KEY"] = "bvjchsygvduycgsyugc" # Andere secret key +app.config["UPLOAD_FOLDER"] = r"application\static\icons" + +# Ensure the upload folder exists +os.makedirs(app.config["UPLOAD_FOLDER"], exist_ok=True) # type: ignore # Object Relational Management db = SQLAlchemy() diff --git a/application/dash/forms.py b/application/dash/forms.py index 48735f8..76397af 100644 --- a/application/dash/forms.py +++ b/application/dash/forms.py @@ -1,9 +1,17 @@ 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 class ServiceForm(FlaskForm): name = StringField("Service name:", validators=[DataRequired()]) url = URLField("Service URL:", validators=[DataRequired()]) + image = FileField( + "Icon:", + validators=[ + FileRequired(), + FileAllowed(["jpg", "jpeg", "png"], "Unsupported file format"), + ], + ) submit = SubmitField("Submit") diff --git a/application/dash/models.py b/application/dash/models.py index bd95027..59f9ea6 100644 --- a/application/dash/models.py +++ b/application/dash/models.py @@ -5,10 +5,12 @@ 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") user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) - def __init__(self, name: str, url: str, user_id: int): + def __init__(self, name: str, url: str, user_id: int, icon: str): self.name = name self.url = url self.user_id = user_id + self.icon = icon diff --git a/application/dash/static/style.css b/application/dash/static/style.css deleted file mode 100644 index b912c98..0000000 --- a/application/dash/static/style.css +++ /dev/null @@ -1,22 +0,0 @@ -body { - background-color: lightslategray; -} - -.grid-container { - display: grid; - grid-template-columns: auto auto auto; - gap: 20px; - background-color: lightslategray; - padding-top: 20px; - margin-left: 10%; - margin-right: 10%; -} - -.grid-container > div { - text-align: center; - height: 100px; - padding-top: 5px; - border: 2px solid black; - border-radius: 10px; - background-color: whitesmoke; -} \ No newline at end of file diff --git a/application/dash/templates/add_service.html b/application/dash/templates/add_service.html index 8839282..576c352 100644 --- a/application/dash/templates/add_service.html +++ b/application/dash/templates/add_service.html @@ -5,32 +5,38 @@ Add service {% endblock %} {% block content %} -
+ {{ form.hidden_tag() }} - + - + {% if feedback %} - {% if feedback=="Service succesfully added" %} -