Blame view

src/core/pyros_django/monitoring/views.py 2.1 KB
ae04c9dd   Patrick Maeght   __init__
1
from django.http import HttpResponse
3df2d31a   haribo   #3430 : dates are...
2
from django.shortcuts import render
4475e3d4   Etienne Pallier   Commande bien env...
3
from common.models import Command
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
9
10
def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

5c9a5545   Patrick Maeght   send others weath...
11

ae04c9dd   Patrick Maeght   __init__
12
13
14
15
16
17
18
19
20
21
22
23
24
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...
25
        _struct = {"origin":plc_checker.origin, "sensors_table":plc_checker.sensors_table, "monitoring_names":list(plc_checker.monitoring_names.keys())}
ae04c9dd   Patrick Maeght   __init__
26
27
28
29
        # 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...
30
31
32
33
34
35
36
37
38


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...
39
        cmd_name, cmd_args = request.GET["data"].split(" ", 1)
e970e46d   Patrick Maeght   weather config up...
40
        # ['nom', 'monitoring_name actuel', 'id(json path) du capteur', 'nouveau monitoring_name']
e2f16220   Patrick Maeght   weather config up...
41
        # <class 'list'>: ['monitor_name_switch', 'None', 'Came:/S/N_A5EM:/Power_input', 'Rain_boolean']
12086fdb   Patrick Maeght   weather config up...
42
43
        if "Error_code" in cmd_args:
            something = 5/0
4475e3d4   Etienne Pallier   Commande bien env...
44
        Command.send_command('Dashboard', 'AgentM', cmd_name, cmd_args)
ea7ad435   Patrick Maeght   weather config up...
45

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

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