示例#1
0
def del_notification(notification_id):
    try:
        notification = Notification(notification_id)
        notification.delete()
        res = make_response('', 204)
    except Exception as e:
        res = make_response(jsonify({'error': str(e)}), 401)
    return res
示例#2
0
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)