views.py 1.1 KB
from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.

def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

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()
        _struct = {"origin":plc_checker.origin, "sensors_table":plc_checker.sensors_table}
        # 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})