mirror of
https://github.com/StefBuwalda/WebTech.git
synced 2025-10-29 19:00:00 +00:00
IDK 1234
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1 +1,9 @@
|
||||
# venv's
|
||||
venv/
|
||||
|
||||
# DB stuff
|
||||
migrations/
|
||||
instance/
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
9
app.py
9
app.py
@@ -1,11 +1,16 @@
|
||||
from application import app
|
||||
from flask import render_template
|
||||
from flask import redirect, url_for
|
||||
from flask_login import current_user, login_required
|
||||
|
||||
|
||||
# home route
|
||||
@app.route("/")
|
||||
@login_required
|
||||
def index():
|
||||
return render_template("home.html")
|
||||
if current_user.is_authenticated:
|
||||
return redirect(url_for("application.dash"))
|
||||
else:
|
||||
return redirect(url_for("application.auth"))
|
||||
|
||||
|
||||
# App deployment
|
||||
|
||||
@@ -17,8 +17,7 @@ migrate = Migrate(app, db)
|
||||
|
||||
# bp import
|
||||
from application.auth.views import auth_blueprint
|
||||
|
||||
# from application.strike.views import strike_blueprint
|
||||
from application.dash.views import dash_blueprint
|
||||
|
||||
# Login manager
|
||||
from application.auth.models import User
|
||||
@@ -35,5 +34,5 @@ def load_user(user_id): # type: ignore
|
||||
|
||||
# Blueprint magic
|
||||
|
||||
# app.register_blueprint(strike_blueprint, url_prefix="/staking")
|
||||
app.register_blueprint(dash_blueprint, url_prefix="/dash")
|
||||
app.register_blueprint(auth_blueprint, url_prefix="/auth")
|
||||
|
||||
@@ -25,7 +25,7 @@ def login():
|
||||
user.password, password # type: ignore
|
||||
):
|
||||
login_user(user) # type: ignore
|
||||
return redirect(url_for("staking.strikers"))
|
||||
return redirect(url_for("application.dash"))
|
||||
else:
|
||||
feedback = "Foutieve login."
|
||||
|
||||
|
||||
9
application/dash/forms.py
Normal file
9
application/dash/forms.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, SubmitField, URLField
|
||||
from wtforms.validators import DataRequired
|
||||
|
||||
|
||||
class ServiceForm(FlaskForm):
|
||||
name = StringField("Service name:", validators=[DataRequired()])
|
||||
url = URLField("Service URL:", validators=[DataRequired()])
|
||||
submit = SubmitField("Add")
|
||||
7
application/dash/models.py
Normal file
7
application/dash/models.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from application import db
|
||||
|
||||
|
||||
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)
|
||||
0
application/dash/templates/dash.html
Normal file
0
application/dash/templates/dash.html
Normal file
61
application/dash/views.py
Normal file
61
application/dash/views.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from flask import (
|
||||
Blueprint,
|
||||
render_template,
|
||||
redirect,
|
||||
url_for,
|
||||
request,
|
||||
flash,
|
||||
session,
|
||||
get_flashed_messages,
|
||||
)
|
||||
from application import db
|
||||
from application.dash.models import Service
|
||||
from application.dash.forms import ServiceForm
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
dash_blueprint = Blueprint("dash", __name__, template_folder="templates")
|
||||
|
||||
# Routes
|
||||
|
||||
"""
|
||||
@strike_blueprint.route("/bedankt", methods=["GET"])
|
||||
def thanks():
|
||||
return render_template("bedankt.html")
|
||||
"""
|
||||
|
||||
|
||||
@dash_blueprint.route("/", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def index():
|
||||
session["_flashes"] = []
|
||||
my_form = ServiceForm()
|
||||
|
||||
if request.method == "POST":
|
||||
if my_form.validate_on_submit():
|
||||
flash("Het formulier is succesvol gePOST")
|
||||
|
||||
session["naam"] = my_form.name.data
|
||||
session["url"] = my_form.url.data
|
||||
flash("De gegevens zijn in de sessie opgeslagen")
|
||||
|
||||
new_service = Service(name=my_form.name.data, url=my_form.url.data)
|
||||
db.session.add(new_service)
|
||||
db.session.commit()
|
||||
flash("De gegevens zijn in de database opgeslagen")
|
||||
|
||||
return redirect(url_for("application.dash"))
|
||||
else:
|
||||
flash("Het formulier is niet goed ingevuld")
|
||||
|
||||
return render_template("dash.html", form=my_form)
|
||||
|
||||
|
||||
"""
|
||||
@strike_blueprint.route("/stakers")
|
||||
@login_required
|
||||
def strikers():
|
||||
rows = Striker.query.all()
|
||||
return render_template(
|
||||
"strikers.html", rows=rows, user=current_user.username
|
||||
)
|
||||
"""
|
||||
@@ -7,7 +7,6 @@
|
||||
<title>{% block title %}{% endblock %}</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="{{url_for('static', filename='my.css')}}">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}
|
||||
Staak-app
|
||||
Idk applicatie
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Welkom bij de staak-app!</h1>
|
||||
<h1>Dit is de home page, hopelijk redirect de pagina</h1>
|
||||
{% endblock %}
|
||||
4
forms.py
4
forms.py
@@ -7,7 +7,3 @@ class ServiceForm(FlaskForm):
|
||||
name = StringField("Service name:", validators=[DataRequired()])
|
||||
url = URLField("Service URL:", validators=[DataRequired()])
|
||||
submit = SubmitField("Add")
|
||||
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user