Debug sur notifs, ajout du nombre dans le menu latéral
L'affichage du nombre de notifs méritera peut être un coup de peinture… À voir.
This commit is contained in:
parent
c2fbef7ace
commit
7971e47522
|
@ -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/<id>', 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)
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
{{ n.text }}
|
||||
{% if n.href %}</a>{% endif %}
|
||||
</td>
|
||||
<td><a href="{{ url_for('delete_notification', id=n.id)}}">Supprimer</a>
|
||||
<td style="text-align: center;"><a href="{{ url_for('delete_notification', id=n.id)}}">Supprimer</a>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<a href="{{ url_for('list_notifications') }}">
|
||||
<svg viewBox="0 0 24 24">
|
||||
<path fill="#ffffff" d="M20,2A2,2 0 0,1 22,4V16A2,2 0 0,1 20,18H6L2,22V4C2,2.89 2.9,2 4,2H20M4,4V17.17L5.17,16H20V4H4M6,7H18V9H6V7M6,11H15V13H6V11Z"></path>
|
||||
</svg>Notifications
|
||||
</svg>Notifications{{ " ({})".format(current_user.notifications|length) if current_user.notifications|length }}
|
||||
</a>
|
||||
<a href="#">
|
||||
<svg viewBox="0 0 24 24">
|
||||
|
|
Loading…
Reference in New Issue