summaryrefslogtreecommitdiff
path: root/sbhs_server
diff options
context:
space:
mode:
authorcoderick142017-06-18 17:53:30 +0530
committercoderick142017-06-18 17:53:30 +0530
commite022e2814603e135509759bd38410e5b3c4bbafe (patch)
tree3b1e7aafb0d4e7a99baa1ad75dc09d879f21bd4a /sbhs_server
parent0d491a1b346e4027863e584c2c70d036af1ae7af (diff)
downloadSBHS-2018-Rpi-e022e2814603e135509759bd38410e5b3c4bbafe.tar.gz
SBHS-2018-Rpi-e022e2814603e135509759bd38410e5b3c4bbafe.tar.bz2
SBHS-2018-Rpi-e022e2814603e135509759bd38410e5b3c4bbafe.zip
Fix logical bug to find actual offlines
Diffstat (limited to 'sbhs_server')
-rw-r--r--sbhs_server/tables/management/commands/send_report.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/sbhs_server/tables/management/commands/send_report.py b/sbhs_server/tables/management/commands/send_report.py
index 0780da1..00b279b 100644
--- a/sbhs_server/tables/management/commands/send_report.py
+++ b/sbhs_server/tables/management/commands/send_report.py
@@ -1,5 +1,6 @@
from django.core.management.base import BaseCommand, CommandError
from sbhs_server import settings, helpers
+from sbhs_server.tables.models import Board
import os, json
class Command(BaseCommand):
@@ -26,9 +27,19 @@ class Command(BaseCommand):
with open(os.path.join(settings.BASE_DIR, filename), "r") as filehandler:
data = filehandler.read()
data = json.loads(data)
- new_offlines += data["new_offlines"]
+ new_offlines.append(set(data["new_offlines"]))
faulty_boards.update(data["faulty_boards"])
+ # Find intersection of offline boards from all RPi's
+ new_offlines = list(set.intersection(*new_offlines))
+
+ # Update database
+ if len(new_offlines) > 0:
+ Board.objects.filter(mid__in=new_offlines).update(online=False)
+ if len(faulty_boards.keys()) > 0:
+ Board.objects.filter(mid__in=faulty_boards.keys()).update(online=True,temp_offline=True)
+
+
# Compose body for the email
message = "SBHS Administrator,\n\n"
message += "Following issue requires immidiate attention.\n\n"
@@ -52,4 +63,4 @@ class Command(BaseCommand):
# Send email
if len(new_offlines) > 0 or len(faulty_boards)>0:
for admin in settings.SBHS_ADMINS:
- helpers.mailer.email(admin[2], subject, message) \ No newline at end of file
+ helpers.mailer.email(admin[2], subject, message)