summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsriyasainath2017-06-09 23:59:01 +0530
committersriyasainath2017-06-10 00:16:55 +0530
commitd0f304e4efba4b2006ce76898e566392aa8f5501 (patch)
tree7150fb779c16ece3dc2e562236d8eb19c95461ae
parent362fec85e066bc7d5ab5d48a0c18f88b96197f74 (diff)
downloadSBHS-2018-Rpi-d0f304e4efba4b2006ce76898e566392aa8f5501.tar.gz
SBHS-2018-Rpi-d0f304e4efba4b2006ce76898e566392aa8f5501.tar.bz2
SBHS-2018-Rpi-d0f304e4efba4b2006ce76898e566392aa8f5501.zip
Add a method and url to toggle device status
-rw-r--r--myadmin/urls.py1
-rw-r--r--myadmin/views.py22
2 files changed, 23 insertions, 0 deletions
diff --git a/myadmin/urls.py b/myadmin/urls.py
index 68e7485..20e6311 100644
--- a/myadmin/urls.py
+++ b/myadmin/urls.py
@@ -16,6 +16,7 @@ urlpatterns = [
url(r'^admin/updatemid/?$', views.update_allocated_mid, name='admin_updatemid'),
url(r'^admin/changemid/?$', views.get_allocated_mids, name='admin_getmids'),
url(r'^admin/getusers/?$', views.get_users, name='admin_users'),
+ url(r'^admin/toggledevice', views.toggle_device_status, name='toggle_status'),
url(r'^admin/toggle_allotment_mode/?$', views.toggle_allotment_mode, name='admin_toggle_allotment_mode'),
] \ No newline at end of file
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)