You can delete services

This commit is contained in:
2025-04-16 09:47:11 +02:00
parent e95abd16cd
commit 5f083928ba
3 changed files with 35 additions and 4 deletions

View File

@@ -5,9 +5,14 @@
{%block content%}
<div class="grid-container">
{% for service in services%}
<div onclick="location.href='{{service.url}}';" style="cursor: pointer;" class="container-xxl">
Name: {{service["name"]}} <br>
URL: {{service["url"]}}
<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">
Name: {{service["name"]}} <br>
URL: {{service["url"]}}
</div>
</div>
{% endfor %}
</div>

View File

@@ -1,5 +1,5 @@
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 flask_login import login_required, current_user # type: ignore
from application.dash.models import Service
@@ -56,6 +56,20 @@ def admin():
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"])
@login_required
def service():

12
seed.py
View File

@@ -22,11 +22,23 @@ new_users = [
password=generate_password_hash("test123"),
is_admin=False,
),
User(
username="stef",
password=generate_password_hash("stef123"),
is_admin=False,
),
]
new_services = [
Service(name="test123", url="http://google.com", user_id=1),
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():