예제 #1
0
파일: hooks.py 프로젝트: SEC-i/ecoControl
def login_user(request):
    if 'username' in request.POST and 'password' in request.POST:
        user = authenticate(username=request.POST[
                            'username'], password=request.POST['password'])
        if user is not None:
            if user.is_active:
                login(request, user)
                return create_json_response({"login": "******", "user": request.user.get_full_name()}, request)
            else:
                return create_json_response({"login": "******", "user": request.user.get_full_name()}, request)
        else:
            return create_json_response({"login": "******"}, request)
    else:
        return create_json_response({"login": "******"}, request)
예제 #2
0
def list_notifications(request, start, end):
    if not request.user.is_authenticated():
        raise PermissionDenied

    start = 0 if start is None else start
    end = 25 if end is None else end

    if request.user.is_superuser:
        notifications = Notification.objects.all()
    else:
        notifications = Notification.objects.filter(
            threshold__show_manager=True)

    notifications = notifications.select_related()

    output = {'total': len(notifications), 'notifications': []}

    for notification in notifications.order_by(
            '-sensor_value__timestamp')[int(start):int(end)]:
        output['notifications'].append({
            'id':
            notification.id,
            'threshold':
            model_to_dict(notification.threshold),
            'sensor_value':
            model_to_dict(notification.sensor_value),
            'read':
            notification.read,
            'target':
            notification.target,
        })

    return create_json_response(output, request)
예제 #3
0
파일: hooks.py 프로젝트: SEC-i/ecoControl
def list_notifications(request, start, end):
    if not request.user.is_authenticated():
        raise PermissionDenied

    start = 0 if start is None else start
    end = 25 if end is None else end

    if request.user.is_superuser:
        notifications = Notification.objects.all()
    else:
        notifications = Notification.objects.filter(
            threshold__show_manager=True)

    notifications = notifications.select_related()

    output = {
        'total': len(notifications),
        'notifications': []
    }

    for notification in notifications.order_by('-sensor_value__timestamp')[int(start):int(end)]:
        output['notifications'].append({
            'id': notification.id,
            'threshold': model_to_dict(notification.threshold),
            'sensor_value': model_to_dict(notification.sensor_value),
            'read': notification.read,
            'target': notification.target,
        })

    return create_json_response(output, request)
예제 #4
0
def list_settings(request):
    if not request.user.is_authenticated():
        raise PermissionDenied

    output = []
    output += functions.get_configurations()
    output += functions.get_device_configurations()
    return create_json_response(dict(output), request)
예제 #5
0
파일: hooks.py 프로젝트: SEC-i/ecoControl
def list_settings(request):
    if not request.user.is_authenticated():
        raise PermissionDenied

    output = []
    output += functions.get_configurations()
    output += functions.get_device_configurations()
    return create_json_response(dict(output), request)
예제 #6
0
파일: hooks.py 프로젝트: SEC-i/ecoControl
def list_sensors(request):
    if not request.user.is_authenticated():
        raise PermissionDenied

    sensors = Sensor.objects.filter(in_diagram=True).values(
        'id', 'name', 'unit', 'device__name', 'aggregate_sum', 'aggregate_avg')

    # rename device__name to device for convenience
    output = [{'id': x['id'], 'name': x['name'], 'unit': x['unit'], 'device': x['device__name'], 'sum': x['aggregate_sum'], 'avg': x['aggregate_avg']}
              for x in sensors]

    return create_json_response(output, request)
예제 #7
0
def login_user(request):
    if 'username' in request.POST and 'password' in request.POST:
        user = authenticate(username=request.POST['username'],
                            password=request.POST['password'])
        if user is not None:
            if user.is_active:
                login(request, user)
                return create_json_response(
                    {
                        "login": "******",
                        "user": request.user.get_full_name()
                    }, request)
            else:
                return create_json_response(
                    {
                        "login": "******",
                        "user": request.user.get_full_name()
                    }, request)
        else:
            return create_json_response({"login": "******"}, request)
    else:
        return create_json_response({"login": "******"}, request)
예제 #8
0
파일: hooks.py 프로젝트: SEC-i/ecoControl
def status(request):
    output = [
        ("system_status", functions.get_configuration("system_status", False))]
    output.append(
        ("system_mode", functions.get_configuration("system_mode", False)))
    output.append(("login", request.user.is_authenticated()))

    if request.user.is_authenticated():
        output.append(("user", request.user.get_full_name()))
        output.append(("admin", request.user.is_superuser))
        output.append(
            ("auto_optimization", functions.get_configuration("auto_optimization", False)))

    return create_json_response(dict(output), request)
예제 #9
0
def status(request):
    output = [("system_status",
               functions.get_configuration("system_status", False))]
    output.append(
        ("system_mode", functions.get_configuration("system_mode", False)))
    output.append(("login", request.user.is_authenticated()))

    if request.user.is_authenticated():
        output.append(("user", request.user.get_full_name()))
        output.append(("admin", request.user.is_superuser))
        output.append(("auto_optimization",
                       functions.get_configuration("auto_optimization",
                                                   False)))

    return create_json_response(dict(output), request)
예제 #10
0
def list_sensors(request):
    if not request.user.is_authenticated():
        raise PermissionDenied

    sensors = Sensor.objects.filter(in_diagram=True).values(
        'id', 'name', 'unit', 'device__name', 'aggregate_sum', 'aggregate_avg')

    # rename device__name to device for convenience
    output = [{
        'id': x['id'],
        'name': x['name'],
        'unit': x['unit'],
        'device': x['device__name'],
        'sum': x['aggregate_sum'],
        'avg': x['aggregate_avg']
    } for x in sensors]

    return create_json_response(output, request)
예제 #11
0
def logout_user(request):
    logout(request)
    return create_json_response({"logout": "successful"}, request)
예제 #12
0
def api_index(request):
    return create_json_response({'version': 0.2}, request)
예제 #13
0
파일: hooks.py 프로젝트: SEC-i/ecoControl
def logout_user(request):
    logout(request)
    return create_json_response({"logout": "successful"}, request)
예제 #14
0
파일: hooks.py 프로젝트: SEC-i/ecoControl
def api_index(request):
    return create_json_response({'version': 0.2}, request)