Highlight unread notifications

This commit is contained in:
Mouse Reeve 2020-03-10 13:31:57 -07:00
parent 3ddd4a0490
commit e8cfa99cd9
3 changed files with 8 additions and 1 deletions

View file

@ -221,3 +221,7 @@ th, td {
.post.depth-4 { .post.depth-4 {
margin-left: 3em; margin-left: 3em;
} }
.unread {
background-color: #F3FFBD;
}

View file

@ -9,7 +9,7 @@
<button type="submit">Delete notifications</button> <button type="submit">Delete notifications</button>
</form> </form>
{% for notification in notifications %} {% for notification in notifications %}
<div class="notification{% if not notification.read %}unread{% endif %}"> <div class="notification{% if notification.id in unread %} unread{% endif %}">
<p> <p>
{% if notification.notification_type == 'FAVORITE' %} {% if notification.notification_type == 'FAVORITE' %}
{% include 'snippets/username.html' with user=notification.related_user %} {% include 'snippets/username.html' with user=notification.related_user %}

View file

@ -139,12 +139,15 @@ def register(request):
return redirect('/') return redirect('/')
@login_required
def notifications_page(request): def notifications_page(request):
''' list notitications ''' ''' list notitications '''
notifications = request.user.notification_set.all() \ notifications = request.user.notification_set.all() \
.order_by('-created_date') .order_by('-created_date')
unread = [n.id for n in notifications.filter(read=False)]
data = { data = {
'notifications': notifications, 'notifications': notifications,
'unread': unread,
} }
notifications.update(read=True) notifications.update(read=True)
return TemplateResponse(request, 'notifications.html', data) return TemplateResponse(request, 'notifications.html', data)