Unverified Commit 2c191357 authored by Marco Marinello's avatar Marco Marinello
Browse files

Add a non acked alarms global view

parent 6f5dcf2d
......@@ -78,6 +78,12 @@
{% trans "Tickets" %}
</a>
</li>
<li>
<a href="{% url 'non_acked_alarms' %}">
<span class="fa fa-exclamation-triangle"></span>
{% trans "Alarms" %}
</a>
</li>
<li>
<a href="{% url 'search_activities' %}">
<span class="fa fa-search"></span>
......
{% extends "base.html" %}
{% load i18n %}
{% block title %}{% trans "Active alarms in managed schools" %}{% endblock title %}
{% block content %}
<h1>{% trans "Active alarms in managed schools" %}</h1>
<script type="text/javascript">
$(function() {
$("#alarms_table").DataTable();
});
</script>
<table class="table table-striped" id="alarms_table">
<thead>
<tr>
<th>{% trans 'Generated on' %}</th>
<th>{% trans 'School' %}</th>
<th>{% trans 'Host' %}</th>
<th>{% trans 'Description' %}</th>
<th>{% trans 'Hush up' %}</th>
</tr>
</thead>
<tbody>
{% for a in alarms %}
<tr>
<td>{{ a.timestamp|date:"d/m/Y H:i:s" }}</td>
<td><a href="{% url 'school_detail' pk=a.host.school.pk %}">{{ a.host.school.name }}</a></td>
<td><a href="{% url 'host' id=a.host.pk %}">{{ a.host.hostname }}</a></td>
<td>{{ a.description }}</td>
<td>
<a href="{% url 'id_do_ack_alarm' id=a.pk %}"
class="btn btn-danger fa fa-close"
onclick="return confirm('Really hush up this alarm?');"></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
from django.conf.urls import patterns, url
urlpatterns = patterns('',
url(r'^alarms/non_ack', 'problems.views.list_non_acked_alarms', name="non_acked_alarms"),
url(r'^alarm/do_ack/(?P<id>[0-9]+)$', 'problems.views.ack_alarm', name="id_do_ack_alarm"),
url(r'^alarms/ack/$', 'problems.views.ack_alarms', name="ack_alarms"),
url(r'^tickets/open$', 'problems.views.list_open_tickets', name="list_open_tickets"),
url(r'^tickets/closed$', 'problems.views.list_closed_tickets', name="list_closed_tickets"),
......
......@@ -11,6 +11,7 @@ import schools.models as smodels
import hosts.models as hmodels
import problems.models as pmodels
import problems.forms as pforms
from django.forms.models import model_to_dict
def annotate_tickets(tickets):
......@@ -19,7 +20,6 @@ def annotate_tickets(tickets):
and adds various data to it, useful for the views that list open
and closed tickets.
"""
from django.forms.models import model_to_dict
annotated_tickets = []
for ticket in tickets:
this_ticket = model_to_dict(ticket)
......@@ -145,3 +145,35 @@ def close_ticket(request, id):
ticket.save()
messages.info(request, _('Ticket closed successfully'))
return redirect('list_closed_tickets')
@login_required
def list_non_acked_alarms(request):
schools = request.user.schools.all()
if request.user.is_superuser:
schools = smodels.School.objects.all()
alarms = pmodels.Alarm.objects.filter(host__school__in=schools, ack=False)
return render(request, "problems/non_acked_alarms.html", {"alarms": alarms})
@login_required
def ack_alarm(request, id):
if not request.user.has_perm('problems.change_alarm'):
messages.error(request, _("You don't have the permission to modify alarms"))
return HttpResponseRedirect(reverse('non_acked_alarms'))
alarm = get_object_or_404(pmodels.Alarm, pk=int(id))
if alarm.host.school not in request.user.schools.all() and not user.is_superuser:
messages.error(request, _("You cannot operate on this school"))
return HttpResponseRedirect(reverse('non_acked_alarms'))
if alarm.ack:
messages.error(request, _("This alarm is already hushed up"))
return HttpResponseRedirect(reverse('non_acked_alarms'))
alarm.ack = True
alarm.ack_by = request.user
alarm.ack_when = datetime.now()
alarm.save()
messages.success(request, _("Alarm %(desc)s on %(host)s has been hushed up") % {
"desc": alarm.description,
"host": alarm.host
})
return redirect("non_acked_alarms")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment