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 }}