add notification detail page

This commit is contained in:
Son 2022-01-24 15:22:01 +01:00
parent 5b7949f346
commit 1de6fefc59
3 changed files with 64 additions and 0 deletions

View File

@ -30,4 +30,5 @@ from .views import (
alias_transfer,
app,
delete_account,
notification,
)

View File

@ -0,0 +1,33 @@
from flask import redirect, url_for, flash, render_template, request
from flask_login import login_required, current_user
from app.dashboard.base import dashboard_bp
from app.db import Session
from app.models import Notification
@dashboard_bp.route("/notification/<notification_id>", methods=["GET", "POST"])
@login_required
def notification_route(notification_id):
notification = Notification.get(notification_id)
if not notification:
flash("Incorrect link. Redirect you to the home page", "warning")
return redirect(url_for("dashboard.index"))
if notification.user_id != current_user.id:
flash(
"You don't have access to this page. Redirect you to the home page",
"warning",
)
return redirect(url_for("dashboard.index"))
if request.method == "POST":
notification_title = notification.title or notification.message[:20]
Notification.delete(notification_id)
Session.commit()
flash(f"{notification_title} has been deleted", "success")
return redirect(url_for("dashboard.index"))
else:
return render_template("dashboard/notification.html", notification=notification)

View File

@ -0,0 +1,30 @@
{% extends 'default.html' %}
{% set active_page = "dashboard" %}
{% block title %}
{{ notification.title }}
{% endblock %}
{% block default_content %}
<div class="card">
<div class="card-body">
<h1 class="h3">
{{ notification.title }}
</h1>
<div>
{{ notification.message | safe }}
</div>
<hr>
<form method="post" class="mt-3" onsubmit="return confirm('This operation is not reversible, please confirm');">
<button class="btn btn-outline-danger">Delete</button>
</form>
</div>
</div>
{% endblock %}