mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-13 14:30:17 +02:00
Front-end notification system
Currently only creates notifications for logging events Addresses #75
This commit is contained in:
parent
1d99ef69d1
commit
5e2c828c3b
@ -410,67 +410,72 @@ LOGGING = {
|
|||||||
'level': 'DEBUG', # edit this line to change logging level to console
|
'level': 'DEBUG', # edit this line to change logging level to console
|
||||||
'class': 'logging.StreamHandler',
|
'class': 'logging.StreamHandler',
|
||||||
'formatter': 'verbose',
|
'formatter': 'verbose',
|
||||||
}
|
},
|
||||||
|
'notifications': { # creates notifications for users with logging_notifications permission
|
||||||
|
'level': 'ERROR', # edit this line to change logging level to notifications
|
||||||
|
'class': 'notifications.handlers.NotificationHandler',
|
||||||
|
'formatter': 'verbose',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'loggers': {
|
'loggers': {
|
||||||
'authentication': {
|
'authentication': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'celerytask': {
|
'celerytask': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'eveonline': {
|
'eveonline': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'groupmanagement': {
|
'groupmanagement': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'hrapplications': {
|
'hrapplications': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'portal': {
|
'portal': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'registration': {
|
'registration': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'services': {
|
'services': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'srp': {
|
'srp': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'timerboard': {
|
'timerboard': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'sigtracker': {
|
'sigtracker': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'optimer': {
|
'optimer': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'corputils': {
|
'corputils': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'util': {
|
'util': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'DEBUG',
|
'level': 'DEBUG',
|
||||||
},
|
},
|
||||||
'django': {
|
'django': {
|
||||||
'handlers': ['log_file', 'console'],
|
'handlers': ['log_file', 'console', 'notifications'],
|
||||||
'level': 'ERROR',
|
'level': 'ERROR',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -186,4 +186,7 @@ urlpatterns = patterns('',
|
|||||||
url(r'^remove_optimer/(\w+)', 'optimer.views.remove_optimer', name='auth_remove_optimer'),
|
url(r'^remove_optimer/(\w+)', 'optimer.views.remove_optimer', name='auth_remove_optimer'),
|
||||||
url(r'^edit_optimer/(\w+)$', 'optimer.views.edit_optimer', name='auth_edit_optimer'),
|
url(r'^edit_optimer/(\w+)$', 'optimer.views.edit_optimer', name='auth_edit_optimer'),
|
||||||
|
|
||||||
|
# Notifications
|
||||||
|
url(r'^notifications/$', 'notifications.views.notification_list', name='auth_notification_list'),
|
||||||
|
url(r'^notifications/(\w+)/$', 'notifications.views.notification_view', name='auth_notification_view'),
|
||||||
)
|
)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from.models import Notification
|
||||||
|
|
||||||
# Register your models here.
|
admin.site.register(Notification)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from .models import Notification
|
from .models import Notification
|
||||||
|
|
||||||
def user_notification_count(request):
|
def user_notification_count(request):
|
||||||
return len(Notification.objects.filter(user=request.user).filter(viewed=False))
|
return {'notifications':len(Notification.objects.filter(user__id=request.user.id).filter(viewed=False))}
|
||||||
|
@ -2,13 +2,13 @@ import logging
|
|||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from .models import Notification
|
from .models import Notification
|
||||||
|
|
||||||
def NotificationHandler(logging.Handler):
|
class NotificationHandler(logging.Handler):
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
for user in User.objects.all():
|
for user in User.objects.all():
|
||||||
if user.has_perm('auth.logging_notifications'):
|
if user.has_perm('auth.logging_notifications'):
|
||||||
notif = Notification()
|
notif = Notification()
|
||||||
notif.user = user
|
notif.user = user
|
||||||
notif.title = "%s [%s:%s]" % (record.levelname, record.funcName, record.lineno)
|
notif.title = "%s [%s:%s]" % (record.levelname, record.funcName, record.lineno)
|
||||||
notif.level = str([item[0] for item in Notification.LEVEL_CHOICES if item[1] == record.levelname])
|
notif.level = str([item[0] for item in Notification.LEVEL_CHOICES if item[1] == record.levelname][0])
|
||||||
notif.message = record.getMessage()
|
notif.message = record.getMessage()
|
||||||
notif.save()
|
notif.save()
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Notification(models.Model):
|
class Notification(models.Model):
|
||||||
|
|
||||||
@ -15,8 +18,8 @@ class Notification(models.Model):
|
|||||||
level = models.CharField(choices=LEVEL_CHOICES, max_length=10)
|
level = models.CharField(choices=LEVEL_CHOICES, max_length=10)
|
||||||
title = models.CharField(max_length=254)
|
title = models.CharField(max_length=254)
|
||||||
message = models.TextField()
|
message = models.TextField()
|
||||||
created = models.DateTimeField(auto_now_add=True)
|
timestamp = models.DateTimeField(auto_now_add=True)
|
||||||
viewed = models.BooleanField()
|
viewed = models.BooleanField(default=False)
|
||||||
|
|
||||||
def view(self):
|
def view(self):
|
||||||
logger.info("Marking notification as viewed: %s" % self)
|
logger.info("Marking notification as viewed: %s" % self)
|
||||||
@ -26,3 +29,6 @@ class Notification(models.Model):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
output = "%s: %s" % (self.user, self.title)
|
output = "%s: %s" % (self.user, self.title)
|
||||||
return output.encode('utf-8')
|
return output.encode('utf-8')
|
||||||
|
|
||||||
|
def set_level(self, level):
|
||||||
|
self.level = [item[0] for item in self.LEVEL_CHOICES if item[1] == level][0]
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
from django.shortcuts import render, get_object_or_404
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
from .models import Notification
|
from .models import Notification
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def notification_list(request):
|
def notification_list(request):
|
||||||
logger.debug("notification_list called by user %s" % request.user)
|
logger.debug("notification_list called by user %s" % request.user)
|
||||||
new_notifs = Notification.objects.filter(user=request.user).filter(read=False)
|
new_notifs = Notification.objects.filter(user=request.user).filter(viewed=False)
|
||||||
old_notifs = Notification.objects.filter(user=request.user).filter(read=True)
|
old_notifs = Notification.objects.filter(user=request.user).filter(viewed=True)
|
||||||
logger.debug("User %s has %s unread and %s read notifications" % (request.user, len(new_notifs), len(old_notifs)))
|
logger.debug("User %s has %s unread and %s read notifications" % (request.user, len(new_notifs), len(old_notifs)))
|
||||||
context = {
|
context = {
|
||||||
'read': old_notifs,
|
'read': old_notifs,
|
||||||
@ -16,11 +20,12 @@ def notification_list(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def notification_view(request, notif_id):
|
def notification_view(request, notif_id):
|
||||||
logger.debug("notification_view called by user %s for notif_id %s" % (request.user, notif_id))
|
logger.debug("notification_view called by user %s for notif_id %s" % (request.user, notif_id))
|
||||||
notif = get_object_or_404(notification, pk=notif_id)
|
notif = get_object_or_404(Notification, pk=notif_id)
|
||||||
if notif.user == request.user:
|
if notif.user == request.user:
|
||||||
logger.debug("Providing notification for user %s" % request.user)
|
logger.debug("Providing notification for user %s" % request.user)
|
||||||
context = {'notification': notif}
|
context = {'notif': notif}
|
||||||
notif.view()
|
notif.view()
|
||||||
return render(request, 'registered/notification_view.html', context)
|
return render(request, 'registered/notification_view.html', context)
|
||||||
else:
|
else:
|
||||||
logger.warn("User %s not authorized to view notif_id %s belonging to user %s" % (request.user, notif_id, notif.user))
|
logger.warn("User %s not authorized to view notif_id %s belonging to user %s" % (request.user, notif_id, notif.user))
|
||||||
|
return redirect('auth_notification_list')
|
||||||
|
@ -47,6 +47,15 @@
|
|||||||
<!-- /.navbar-header -->
|
<!-- /.navbar-header -->
|
||||||
|
|
||||||
<ul class="nav navbar-top-links navbar-right">
|
<ul class="nav navbar-top-links navbar-right">
|
||||||
|
{% if notifications %}
|
||||||
|
<li class="nav-link active"><a href="{% url 'auth_notification_list' %}">
|
||||||
|
<span class="glyphicon glyphicon-alert"></span></a>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="nav-link"><a href="{% url 'auth_notification_list' %}">
|
||||||
|
<span class="glyphicon glyphicon-warning-sign"></span></a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li><a href="{% url 'auth_logout_user' %}">Logout</a></li>
|
<li><a href="{% url 'auth_logout_user' %}">Logout</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
74
stock/templates/registered/notification_list.html
Normal file
74
stock/templates/registered/notification_list.html
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
{% extends "public/base.html" %}
|
||||||
|
{% load staticfiles %}
|
||||||
|
|
||||||
|
{% block title %}Notifications{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<h1 class="page-header text-center">Notifications</h1>
|
||||||
|
<div class="col-lg-12 container" id="example">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<ul class="nav nav-tabs">
|
||||||
|
<li class="active"><a data-toggle="tab" href="#unread">Unread <b>({{unread|length}})</b></a></li>
|
||||||
|
<li><a data-toggle="tab" href="#read">Read <b>({{read|length}})</b></a></li>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content">
|
||||||
|
<div id="unread" class="tab-pane fade in active">
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-condensed table-hover table-striped">
|
||||||
|
<tr>
|
||||||
|
<th class="text-center">Timestamp</th>
|
||||||
|
<th class="text-center">Title</th>
|
||||||
|
<th class="text-center">View</th>
|
||||||
|
</tr>
|
||||||
|
{% for notif in unread %}
|
||||||
|
<tr class="{{ notif.level }}">
|
||||||
|
<td class="text-center">{{ notif.timestamp }}</td>
|
||||||
|
<td class="text-center">{{ notif.title }}</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<a href="{% url 'auth_notification_view' notif.id %}">
|
||||||
|
<button type="button" class="btn btn-success" title="View">
|
||||||
|
<span class="glyphicon glyphicon-eye-open"></span>
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="read" class="tab-pane fade">
|
||||||
|
<div class="panel-body">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-condensed table-hover table-striped">
|
||||||
|
<tr>
|
||||||
|
<th class="text-center">Timestamp</th>
|
||||||
|
<th class="text-center">Title</th>
|
||||||
|
<th class="text-center">View</th>
|
||||||
|
</tr>
|
||||||
|
{% for notif in read %}
|
||||||
|
<tr class="{{ notif.level }}">
|
||||||
|
<td class="text-center">{{ notif.timestamp }}</td>
|
||||||
|
<td class="text-center">{{ notif.title }}</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<a href="{% url 'auth_notification_view' notif.id %}">
|
||||||
|
<button type="button" class="btn btn-success" title="View">
|
||||||
|
<span class="glyphicon glyphicon-eye-open"></span>
|
||||||
|
</button>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
22
stock/templates/registered/notification_view.html
Normal file
22
stock/templates/registered/notification_view.html
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{% extends "public/base.html" %}
|
||||||
|
{% load staticfiles %}
|
||||||
|
|
||||||
|
{% block title %}View Notification{% endblock title %}
|
||||||
|
{% block page_title %}View Notification{% endblock page_title %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<h1 class="page-header text-center">View Notification</h1>
|
||||||
|
<div class="col-lg-12 container" id="example">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12">
|
||||||
|
<div class="panel panel-{{ notif.level }}">
|
||||||
|
<div class="panel-heading">{{ notif.timestamp }} {{ notif.title }}</div>
|
||||||
|
<div class="panel-body">{{ notif.message }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user