summaryrefslogtreecommitdiff
path: root/sbhs_server/tables/management
diff options
context:
space:
mode:
Diffstat (limited to 'sbhs_server/tables/management')
-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)