Blame view

src/devices/views.py 2.21 KB
ba1d1f2b   Quentin Durand   implémentation Fr...
1
2
from django.shortcuts import render, get_object_or_404
from common.models import Log, Config
76dfa189   Unknown   Adding devices lo...
3
from django.http import HttpResponse
76dfa189   Unknown   Adding devices lo...
4
5
from django.core import serializers
from django.contrib.auth.decorators import login_required
5f148e7d   Unknown   Update to django2...
6
import django.urls
64501c9d   Etienne Pallier   first full projec...
7

76dfa189   Unknown   Adding devices lo...
8
MAX_LOGS_LINES = 200
64501c9d   Etienne Pallier   first full projec...
9
# Create your views here.
76dfa189   Unknown   Adding devices lo...
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
@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
    '''
ba1d1f2b   Quentin Durand   implémentation Fr...
46
    config = get_object_or_404(Config, id=1)
76dfa189   Unknown   Adding devices lo...
47
48
49
50
51
    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')
ba1d1f2b   Quentin Durand   implémentation Fr...
52
    return render(request, 'dashboard/observation_status.html', locals())