views.py 2.22 KB
from django.shortcuts import render, get_object_or_404
from common.models import Log, Config
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
    '''
    # config = get_object_or_404(Config, id=1)
    # 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')
    return render(request, 'dashboard/observation_status.html', locals())