def view_beamer_off(request): if request.method == 'GET': if request.user.is_staff: snippets = Snippet( classname= 'Beamer(usb, baudrate, bytesize, parity, stopbits, timeout)', code='off(input_off)') serializer = SnippetSerializer(snippets) return JsonResponse(serializer.data, safe=False) else: return render(request, 'index_api.html', {}) elif request.method == 'POST': data = JSONParser().parse(request) serializer = SnippetSerializer(data=data) if serializer.is_valid(): parsed_data = encode_api_json(data) name = parsed_data[0] device = parsed_data[1].split(",") method = parsed_data[2] input_off = parsed_data[3] if name == "Beamer": if method == "off": Beamer(device[0], int(device[1]), int(device[2]), device[3], int(device[4]), int(device[5])).off(bytes.fromhex(input_off)) return JsonResponse(data, status=201) return JsonResponse(serializer.errors, status=400) return JsonResponse(serializer.errors, status=400)
def view_usb_switch(request): if request.user.is_staff: if request.method == 'GET': snippets = Snippet( classname='USBSwitch()', code= 'change_hub(), change_to_previous_hub(), change_to_number(hub), set_number_switch(), check_usb(), find_usb_switch()' ) serializer = SnippetSerializer(snippets) return JsonResponse(serializer.data, safe=False) else: return render(request, 'index_api.html', {})
def view_usb_switch_check_usb(request): if request.method == 'GET': if request.user.is_staff: snippets = Snippet(classname='USBSwitch()', code='check_usb()') serializer = SnippetSerializer(snippets) return JsonResponse(serializer.data, safe=False) else: return render(request, 'index_api.html', {}) elif request.method == 'POST': data = JSONParser().parse(request) serializer = SnippetSerializer(data=data) if serializer.is_valid(): parsed_data = encode_api_json(data) name = parsed_data[0] method = parsed_data[2] if name == "USBSwitch": if method == "check_usb": USBSwitch().check_usb() return JsonResponse(data, status=201) return JsonResponse(serializer.errors, status=400) return JsonResponse(serializer.errors, status=400)
def view_hdmi_switch(request): if request.user.is_staff: if request.method == 'GET': snippets = Snippet( classname='HdmiSwitch()', code= 'status(), output_connections(output), get_connection(connection_feedback), status_in(), status_out(), get_in_out_devices(status), connect(inputs, output), switch_off(output), switch_on(output)' ) serializer = SnippetSerializer(snippets) return JsonResponse(serializer.data, safe=False) else: return render(request, 'index_api.html', {})
def view_powerstrip(request): if request.user.is_staff: if request.method == 'GET': snippets = Snippet( classname='Powerstrip(device_room)', code= 'switch_on(socket), switch_off(socket), switch_all_on(), switch_all_off(), status(socket), status_all()' ) serializer = SnippetSerializer(snippets) return JsonResponse(serializer.data, safe=False) else: return render(request, 'index_api.html', {})
def view_beamer(request): if request.user.is_staff: if request.method == 'GET': snippets = Snippet( classname= 'Beamer(usb, baudrate, bytesize, parity, stopbits, timeout)', code= 'on(input_on), off(input_off), changeState(input_change_state, input_on, input_off)' ) serializer = SnippetSerializer(snippets) return JsonResponse(serializer.data, safe=False) else: return render(request, 'index_api.html', {})
def view_hdmi_switch_on(request): if request.method == 'GET': if request.user.is_staff: snippets = Snippet(classname='HdmiSwitch()', code='switch_on(output)') serializer = SnippetSerializer(snippets) return JsonResponse(serializer.data, safe=False) else: return render(request, 'index_api.html', {}) elif request.method == 'POST': data = JSONParser().parse(request) serializer = SnippetSerializer(data=data) if serializer.is_valid(): parsed_data = encode_api_json(data) name = parsed_data[0] method = parsed_data[2] output = parsed_data[3] if name == "HdmiSwitch": if method == "switch_on": HdmiSwitch().switch_on(output) return JsonResponse(data, status=201) return JsonResponse(serializer.errors, status=400) return JsonResponse(serializer.errors, status=400)
def view_powerstrip_status_all(request): if request.method == 'GET': if request.user.is_staff: snippets = Snippet(classname='Powerstrip(device_room)', code='status_all()') serializer = SnippetSerializer(snippets) return JsonResponse(serializer.data, safe=False) else: return render(request, 'index_api.html', {}) elif request.method == 'POST': data = JSONParser().parse(request) serializer = SnippetSerializer(data=data) if serializer.is_valid(): parsed_data = encode_api_json(data) name = parsed_data[0] device_room = parsed_data[1] method = parsed_data[2] if name == "Powerstrip": if method == "status_all": Powerstrip(int(device_room)).status_all() return JsonResponse(data, status=201) return JsonResponse(serializer.errors, status=400) return JsonResponse(serializer.errors, status=400)