views.py
2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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())