mirror of
https://github.com/StefBuwalda/WebTech.git
synced 2025-10-30 11:19:58 +00:00
You can delete services
This commit is contained in:
@@ -5,10 +5,15 @@
|
|||||||
{%block content%}
|
{%block content%}
|
||||||
<div class="grid-container">
|
<div class="grid-container">
|
||||||
{% for service in services%}
|
{% for service in services%}
|
||||||
|
<div>
|
||||||
|
<form action="{{ url_for('dash.delete_item', service_id=service.id) }}" method="POST" style="display:inline;">
|
||||||
|
<button class="delete-btn" type="submit">×</button>
|
||||||
|
</form>
|
||||||
<div onclick="location.href='{{service.url}}';" style="cursor: pointer;" class="container-xxl">
|
<div onclick="location.href='{{service.url}}';" style="cursor: pointer;" class="container-xxl">
|
||||||
Name: {{service["name"]}} <br>
|
Name: {{service["name"]}} <br>
|
||||||
URL: {{service["url"]}}
|
URL: {{service["url"]}}
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{%endblock%}
|
{%endblock%}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
from application import db
|
from application import db
|
||||||
from flask import Blueprint, render_template
|
from flask import Blueprint, render_template, redirect, url_for
|
||||||
from application.dash.forms import RegisterForm, ServiceForm
|
from application.dash.forms import RegisterForm, 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
|
||||||
@@ -56,6 +56,20 @@ def admin():
|
|||||||
return render_template("admin.html", form=register_form)
|
return render_template("admin.html", form=register_form)
|
||||||
|
|
||||||
|
|
||||||
|
@dash_blueprint.route("/delete_item/<int:service_id>", methods=["POST"])
|
||||||
|
@login_required
|
||||||
|
def delete_item(service_id: int):
|
||||||
|
service = Service.query.get_or_404(service_id)
|
||||||
|
|
||||||
|
# Check ownership
|
||||||
|
if service.user_id != current_user.id:
|
||||||
|
return redirect(url_for("dash.index"))
|
||||||
|
|
||||||
|
db.session.delete(service)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect(url_for("dash.index"))
|
||||||
|
|
||||||
|
|
||||||
@dash_blueprint.route("/service", methods=["GET", "POST"])
|
@dash_blueprint.route("/service", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def service():
|
def service():
|
||||||
|
|||||||
12
seed.py
12
seed.py
@@ -22,11 +22,23 @@ new_users = [
|
|||||||
password=generate_password_hash("test123"),
|
password=generate_password_hash("test123"),
|
||||||
is_admin=False,
|
is_admin=False,
|
||||||
),
|
),
|
||||||
|
User(
|
||||||
|
username="stef",
|
||||||
|
password=generate_password_hash("stef123"),
|
||||||
|
is_admin=False,
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
new_services = [
|
new_services = [
|
||||||
Service(name="test123", url="http://google.com", user_id=1),
|
Service(name="test123", url="http://google.com", user_id=1),
|
||||||
Service(name="Netflix", url="https://www.netflix.com", user_id=2),
|
Service(name="Netflix", url="https://www.netflix.com", user_id=2),
|
||||||
|
# Stef services
|
||||||
|
Service(name="Plex", url="https://plex.local", user_id=3),
|
||||||
|
Service(name="TrueNAS", url="https://truenas.local", user_id=3),
|
||||||
|
Service(name="Transmission", url="https://transmission.local", user_id=3),
|
||||||
|
Service(name="Tautulli", url="https://tautulli.local", user_id=3),
|
||||||
|
Service(name="Overseerr", url="https://overseerr.local", user_id=3),
|
||||||
|
Service(name="Plex", url="https://plex.local", user_id=3),
|
||||||
]
|
]
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
|||||||
Reference in New Issue
Block a user