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,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>
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user