summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcoderick142017-06-25 19:58:09 +0530
committercoderick142017-06-25 19:58:09 +0530
commit3ad34f590ed22d59694c6831142ffc850472cefa (patch)
treeeb787c4b841ce7cbc93027abab2c5ebfc800d4ea
parent616886d5075802d043a8a0a6f141dd537d76c8b3 (diff)
downloadSBHS-2018-Rpi-3ad34f590ed22d59694c6831142ffc850472cefa.tar.gz
SBHS-2018-Rpi-3ad34f590ed22d59694c6831142ffc850472cefa.tar.bz2
SBHS-2018-Rpi-3ad34f590ed22d59694c6831142ffc850472cefa.zip
Allow temp_offline only when board is NOT in use
-rw-r--r--myadmin/views.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/myadmin/views.py b/myadmin/views.py
index b0dbe24..c720038 100644
--- a/myadmin/views.py
+++ b/myadmin/views.py
@@ -177,10 +177,25 @@ def toggle_device_status(req):
return HttpResponse(json.dumps({"status_code":400, "message":"Invalid parameters"}), content_type="application/json")
try:
- brd = Board.objects.get(mid = mid)
+ now = datetime.datetime.now()
+ current_slot_id = Slot.objects.filter(start_hour=now.hour,
+ start_minute__lt=now.minute,
+ end_minute__gt=now.minute)
- brd.temp_offline = not brd.temp_offline
+ current_slot_id = -1 if not current_slot_id else current_slot_id[0].id
+
+ current_bookings = Booking.objects.filter(slot_id=current_slot_id,
+ booking_date=datetime.date.today()).select_related()
+ current_mids = list([-1]) if not current_bookings else [current_booking.account.board.mid for current_booking in current_bookings]
+ except Exception as e:
+ return HttpResponse(json.dumps({"status_code":400, "message":"Unsuccessful"}), content_type="application/json")
+ if int(mid) in current_mids:
+ return HttpResponse(json.dumps({"status_code":400, "message":"Board is in use."}), 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")