views.py 1.96 KB
from django.shortcuts import render, redirect
from django.core import urlresolvers
from django.contrib.auth.decorators import login_required
from common.models import Log

import utils.Logger as l
log = l.setupLogger("dashboard", "dashboard")

@login_required
def index(request):
    return render(request, 'dashboard/index.html')

@login_required
def users(request):
    url_ = urlresolvers.reverse('admin:auth_user_changelist')
    return redirect(url_)

@login_required
def routines(request):
    url_ = urlresolvers.reverse('admin:common_request_changelist')
    return redirect(url_)


@login_required
def weather(request):
    url_ = urlresolvers.reverse('admin:common_weatherwatch_changelist')
    return redirect(url_)


@login_required
def site(request):
    url_ = urlresolvers.reverse('admin:common_sitewatch_changelist')
    return redirect(url_)


@login_required
def devices(request):
    url_ = urlresolvers.reverse('admin:common_device_changelist')
    return redirect(url_)

@login_required
def system(request):
    return render(request, 'dashboard/system.html')

@login_required
def system_retrieve_logs(request):
    '''
        Called by the dashboard system page with ajax request every seconds, to get the logs and print them
    '''
    if request.is_ajax():
        alert_logs = Log.objects.filter(agent='Alert manager')
        scheduler_logs = Log.objects.filter(agent='Scheduler')
        majordome_logs = Log.objects.filter(agent='Majordome')
        obs_logs = Log.objects.filter(agent='Observation manager')
        analyzer_logs = Log.objects.filter(agent='Analyzer')
        monitoring_logs = Log.objects.filter(agent='Monitoring')
        return render(request, 'dashboard/system_logs.html', locals())


@login_required
def schedule(request):
    url_ = urlresolvers.reverse('admin:common_schedule_changelist')
    return redirect(url_)


@login_required
def quotas(request):
    url_ = urlresolvers.reverse('admin:common_pyrosuser_changelist')
    return redirect(url_)