diff options
Diffstat (limited to 'myadmin')
-rw-r--r-- | myadmin/urls.py | 1 | ||||
-rw-r--r-- | myadmin/views.py | 22 |
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) |