views.py 2.29 KB
from django.shortcuts import render
from common.models import Log
from django.http import HttpResponse
from django.core import serializers
from django.contrib.auth.decorators import login_required
import django.urls

MAX_LOGS_LINES = 200
# Create your views here.
@login_required
def update_cagire_logs(request):
    if request.is_ajax():
        cagire_logs = Log.objects.filter(agent='CameraNIR').order_by('-created')[:MAX_LOGS_LINES]
        logs = serializers.serialize('json', cagire_logs)
        return HttpResponse(logs, content_type="application/json")
        #return render("dashboard/observation_status.html", logs, content_type="application/json")


@login_required
def update_telescope_logs(request):
    if request.is_ajax():
        telescope_logs = Log.objects.filter(agent='Telescope').order_by('-created')[:MAX_LOGS_LINES]
        logs = serializers.serialize('json', telescope_logs)
        return HttpResponse(logs, content_type="application/json")

@login_required
def update_ddrago_r_logs(request):
    if request.is_ajax():
        ddrago_r_logs = Log.objects.filter(agent='CameraVIS').order_by('-created')[:MAX_LOGS_LINES]
        logs = serializers.serialize('json', ddrago_r_logs)
        return HttpResponse(logs, content_type="application/json")

@login_required
def update_ddrago_b_logs(request):
    if request.is_ajax():
        ddrago_b_logs = Log.objects.filter(agent='CameraVIS').order_by('-created')[:MAX_LOGS_LINES]
        logs = serializers.serialize('json', ddrago_b_logs)
        return HttpResponse(logs, content_type="application/json")


@login_required
def observation_status(request):
    '''
        Called by the dashboard system page with ajax request every seconds, to get the logs and print them
    '''
    if request.is_ajax():
        telescope_logs = Log.objects.filter(agent='Telescope').order_by('-created')
        cagire_logs = Log.objects.filter(agent='CameraNIR').order_by('-created')
        ddrago_b_logs = Log.objects.filter(agent='CameraVIS').order_by('-created')
        ddrago_r_logs = Log.objects.filter(agent='CameraVIS').order_by('-created')
        logs = telescope_logs + cagire_logs + ddrago_r_logs + ddrago_b_logs
        return render('dashboard/observation_status.html', {logs: object})
    else:
        return render(request, "dashboard/observation_status.html")