From 7971e47522c4f306d020c33210b9b1278a2c6fb5 Mon Sep 17 00:00:00 2001 From: Darks Date: Sun, 1 Sep 2019 22:33:00 +0200 Subject: [PATCH] =?UTF-8?q?Debug=20sur=20notifs,=20ajout=20du=20nombre=20d?= =?UTF-8?q?ans=20le=20menu=20lat=C3=A9ral=20L'affichage=20du=20nombre=20de?= =?UTF-8?q?=20notifs=20m=C3=A9ritera=20peut=20=C3=AAtre=20un=20coup=20de?= =?UTF-8?q?=20peinture=E2=80=A6=20=C3=80=20voir.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routes/account/notification.py | 14 +++++++++++--- app/templates/account/notifications.html | 2 +- app/templates/base/navbar/account.html | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/routes/account/notification.py b/app/routes/account/notification.py index 2b3a3b9..daea674 100644 --- a/app/routes/account/notification.py +++ b/app/routes/account/notification.py @@ -1,4 +1,4 @@ -from flask import redirect, url_for, request, flash +from flask import redirect, url_for, request, flash, abort from flask_login import login_required, current_user from app import app, db from app.models.notification import Notification @@ -15,8 +15,15 @@ def list_notifications(): @app.route('/notifications/delete/', methods=['GET']) @login_required def delete_notification(id=None): + # Try to convert id to int + try: + id = int(id) + except ValueError: + pass + if type(id) == int: notification = Notification.query.get(id) + print(">", notification) if notification: # Only current user or admin can delete notifications if notification.owner_id == current_user.id: @@ -26,8 +33,9 @@ def delete_notification(id=None): elif 'delete_notification' in current_user.privs: db.session.delete(notification) db.session.commit() - # TODO: change this redirection - return redirect(url_for('list_notifications')) + if request.referrer: + return redirect(request.referrer) + return redirect(url_for('adm')) else: abort(403) abort(404) diff --git a/app/templates/account/notifications.html b/app/templates/account/notifications.html index 0d25c63..42b19eb 100644 --- a/app/templates/account/notifications.html +++ b/app/templates/account/notifications.html @@ -21,7 +21,7 @@ {{ n.text }} {% if n.href %}{% endif %} - Supprimer + Supprimer {% endfor %} diff --git a/app/templates/base/navbar/account.html b/app/templates/base/navbar/account.html index fb2e481..a05b801 100644 --- a/app/templates/base/navbar/account.html +++ b/app/templates/base/navbar/account.html @@ -9,7 +9,7 @@ - Notifications + Notifications{{ " ({})".format(current_user.notifications|length) if current_user.notifications|length }}