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:
Darks 2019-09-01 22:33:00 +02:00
parent c2fbef7ace
commit 7971e47522
Signed by: Darks
GPG Key ID: F61F10FA138E797C
3 changed files with 13 additions and 5 deletions

View File

@ -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)

View File

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

View File

@ -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">