Blame view

src/core/pyros_django/monitoring/views.py 2.42 KB
ae04c9dd   Patrick Maeght   __init__
1
from django.http import HttpResponse
3df2d31a   haribo   #3430 : dates are...
2
from django.shortcuts import render
8e15e893   Etienne Pallier   Renommé classes C...
3
from common.models import AgentCmd
3df2d31a   haribo   #3430 : dates are...
4
5

# Create your views here.
ae04c9dd   Patrick Maeght   __init__
6

5c9a5545   Patrick Maeght   send others weath...
7

ae04c9dd   Patrick Maeght   __init__
8
def index(request):
b41fdcf9   Alexis Koralewski   fixing home redir...
9
10
    if request.user.is_authenticated:
        # return the initial view (the dashboard's one)
6df730cd   ALEXIS-PC\alexis   fixing display of...
11
        return render(request, 'dashboard/index.html', {'USER_LEVEL': request.user.get_priority(), 'base_template' : "base.html"})                              
b41fdcf9   Alexis Koralewski   fixing home redir...
12
13
    return render(request, 'dashboard/index.html', {'USER_LEVEL': 0, 'base_template' : "base_unlogged.html"})                              

ae04c9dd   Patrick Maeght   __init__
14

5c9a5545   Patrick Maeght   send others weath...
15

ae04c9dd   Patrick Maeght   __init__
16
17
18
19
20
21
22
23
24
25
26
27
28
def weather_config(request):
    """ PM 20180926 prototype without database
        http://127.0.0.1:8000/dashboard/weather/config
        Moved to monitoring
    """
    try:
        # Import PLC status sensor parser
        from monitoring.plc_checker import PlcChecker
        # Parse PLC status in colibri-new-fixed-2.json
        #colibri_json = open("../simulators/plc/colibri-new-fixed-2.json")
        #colibri_struct = json.load(colibri_json)
        #plc_status = colibri_struct["statuses"][1]["entities"][0]
        plc_checker = PlcChecker()
e2f16220   Patrick Maeght   weather config up...
29
        _struct = {"origin":plc_checker.origin, "sensors_table":plc_checker.sensors_table, "monitoring_names":list(plc_checker.monitoring_names.keys())}
ae04c9dd   Patrick Maeght   __init__
30
31
32
33
        # Return template with sensors list
        return render(request, 'dashboard/config_weather.html', {'weather_config' : _struct, 'base_template' : "base.html"})
    except Config.DoesNotExist:
        return render(request, 'dashboard/config_weather.html', {'weather_info' : None})
e68e2cea   Patrick Maeght   weather config up...
34
35
36
37
38
39
40
41
42


def weather_config_update(request):
    """ PM 20190716 ajax
        http://127.0.0.1:8000/dashboard/weather/config/update
        Get data...
    """
    try:
        # print(request.GET["data"])
4475e3d4   Etienne Pallier   Commande bien env...
43
        cmd_name, cmd_args = request.GET["data"].split(" ", 1)
e970e46d   Patrick Maeght   weather config up...
44
        # ['nom', 'monitoring_name actuel', 'id(json path) du capteur', 'nouveau monitoring_name']
e2f16220   Patrick Maeght   weather config up...
45
        # <class 'list'>: ['monitor_name_switch', 'None', 'Came:/S/N_A5EM:/Power_input', 'Rain_boolean']
12086fdb   Patrick Maeght   weather config up...
46
47
        if "Error_code" in cmd_args:
            something = 5/0
8e15e893   Etienne Pallier   Renommé classes C...
48
        AgentCmd.send_command('Dashboard', 'AgentM', cmd_name, cmd_args)
ea7ad435   Patrick Maeght   weather config up...
49

4475e3d4   Etienne Pallier   Commande bien env...
50
        #TODO: Pour l'instant, on ne recupere pas encore ce retour
25c7f6db   Patrick Maeght   weather config up...
51

94b23031   Patrick Maeght   send others weath...
52
        return HttpResponse('{"update":"OK", "cmd_name":"' + cmd_name + '"}', content_type="application/json")
e68e2cea   Patrick Maeght   weather config up...
53
    except:
94b23031   Patrick Maeght   send others weath...
54
        return HttpResponse('{"update":"ERROR", "cmd_name":"' + cmd_name + '"}', content_type="application/json", status="500")