From d0f304e4efba4b2006ce76898e566392aa8f5501 Mon Sep 17 00:00:00 2001 From: sriyasainath Date: Fri, 9 Jun 2017 23:59:01 +0530 Subject: Add a method and url to toggle device status --- myadmin/views.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'myadmin/views.py') diff --git a/myadmin/views.py b/myadmin/views.py index 9054524..bbbb2f9 100644 --- a/myadmin/views.py +++ b/myadmin/views.py @@ -154,6 +154,28 @@ def get_users(req): except Exception as e: return HttpResponse(json.dumps({"status_code":500, "message":str(e)}), content_type="application/json") + +@csrf_exempt +def toggle_device_status(req): + checkadmin(req) + + try : + mid = req.POST.get('mid') + except Exception as e: + return HttpResponse(json.dumps({"status_code":400, "message":"Invalid parameters"}), content_type="application/json") + + try: + brd = Board.objects.get(mid = mid) + + brd.temp_offline = not brd.temp_offline + + brd.save() + + return HttpResponse(json.dumps({"status_code":200, "message":"Toggle successful"}), content_type="application/json") + except Exception as e: + return HttpResponse(json.dumps({"status_code":400, "message":"Unsuccessful"}), content_type="application/json") + + def user_exists(username): try: user = Account.objects.get(username=username) -- cgit