summaryrefslogtreecommitdiff
path: root/sbhs_server/admin
diff options
context:
space:
mode:
Diffstat (limited to 'sbhs_server/admin')
-rw-r--r--sbhs_server/admin/__init__.py0
-rw-r--r--sbhs_server/admin/__init__.pycbin0 -> 144 bytes
-rw-r--r--sbhs_server/admin/admin.py3
-rw-r--r--sbhs_server/admin/models.py3
-rw-r--r--sbhs_server/admin/models.pycbin0 -> 198 bytes
-rw-r--r--sbhs_server/admin/tests.py3
-rw-r--r--sbhs_server/admin/views.py75
7 files changed, 84 insertions, 0 deletions
diff --git a/sbhs_server/admin/__init__.py b/sbhs_server/admin/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/sbhs_server/admin/__init__.py
diff --git a/sbhs_server/admin/__init__.pyc b/sbhs_server/admin/__init__.pyc
new file mode 100644
index 0000000..95dd17b
--- /dev/null
+++ b/sbhs_server/admin/__init__.pyc
Binary files differ
diff --git a/sbhs_server/admin/admin.py b/sbhs_server/admin/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/sbhs_server/admin/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/sbhs_server/admin/models.py b/sbhs_server/admin/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/sbhs_server/admin/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/sbhs_server/admin/models.pyc b/sbhs_server/admin/models.pyc
new file mode 100644
index 0000000..2d2a7de
--- /dev/null
+++ b/sbhs_server/admin/models.pyc
Binary files differ
diff --git a/sbhs_server/admin/tests.py b/sbhs_server/admin/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/sbhs_server/admin/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/sbhs_server/admin/views.py b/sbhs_server/admin/views.py
new file mode 100644
index 0000000..8289cfa
--- /dev/null
+++ b/sbhs_server/admin/views.py
@@ -0,0 +1,75 @@
+from django.shortcuts import render, redirect
+from django.http import Http404
+from django.contrib.auth.decorators import login_required
+from sbhs_server.tables.models import Board, Booking
+from sbhs_server import settings
+import subprocess
+# Create your views here.
+
+def checkadmin(req):
+ if not req.user.is_admin:
+ raise Http404
+
+@login_required(redirect_field_name=None)
+def index(req):
+ checkadmin(req)
+ boards = Board.objects.order_by('online').all()
+ allotment_mode = "Random" if Board.can_do_random_allotment() else "Workshop"
+ return render(req, 'admin/index.html', {"boards": boards, "allotment_mode": allotment_mode})
+
+@login_required(redirect_field_name=None)
+def toggle_allotment_mode(req):
+ checkadmin(req)
+ Board.toggle_random_allotment()
+ return redirect(index)
+
+@login_required(redirect_field_name=None)
+def booking_index(req):
+ checkadmin(req)
+ bookings = Booking.objects.order_by('-booking_date').select_related()[:50]
+ return render(req, 'admin/booking_index.html', {"bookings": bookings})
+
+@login_required(redirect_field_name=None)
+def webcam_index(req):
+ checkadmin(req)
+ boards = Board.objects.all()
+ return render(req, 'admin/webcam_index.html', {"boards": boards})
+
+@login_required(redirect_field_name=None)
+def profile(req, mid):
+ checkadmin(req)
+ try:
+ filename = settings.SBHS_GLOBAL_LOG_DIR + "/" + mid + ".log"
+ f = open(filename, "r")
+ f.close()
+ except:
+ raise Http404
+
+ delta_T = 1000
+ data = subprocess.check_output("tail -n %d %s" % (delta_T, filename), shell=True)
+ data = data.split("\n")
+ plot = []
+ heatcsv = ""
+ fancsv = ""
+ tempcsv = ""
+
+ for t in xrange(len(data)):
+ line = data[t]
+ entry = line.strip().split(" ")
+ try:
+ plot.append([int(i) for i in entry[0:-1] + [float(entry[-1])]])
+ heatcsv += "%d,%s\\n" % (t+1, entry[1])
+ fancsv += "%d,%s\\n" % (t+1, entry[2])
+ tempcsv += "%d,%s\\n" % (t+1, entry[3])
+ except:
+ continue
+
+ plot = zip(*plot) # transpose
+
+ return render(req, "admin/profile.html", {
+ "mid": mid,
+ "delta_T": delta_T,
+ "heat": heatcsv,
+ "fan": fancsv,
+ "temp": tempcsv
+ }) \ No newline at end of file