summaryrefslogtreecommitdiff
path: root/sbhs_server/webcam/views.py
diff options
context:
space:
mode:
authorttt2017-05-13 00:29:47 +0530
committerttt2017-05-13 00:29:47 +0530
commitabf599be33b383a6a5baf9493093b2126a622ac8 (patch)
tree4c5ab6e0d935d5e65fabcf0258e4a00dd20a5afa /sbhs_server/webcam/views.py
downloadSBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.gz
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.bz2
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.zip
added all server files
Diffstat (limited to 'sbhs_server/webcam/views.py')
-rw-r--r--sbhs_server/webcam/views.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/sbhs_server/webcam/views.py b/sbhs_server/webcam/views.py
new file mode 100644
index 0000000..d765730
--- /dev/null
+++ b/sbhs_server/webcam/views.py
@@ -0,0 +1,47 @@
+from django.shortcuts import render
+from django.contrib.auth.decorators import login_required
+import os, requests
+from sbhs_server import settings
+from django.http import HttpResponse
+from sbhs_server.admin.views import checkadmin
+from sbhs_server.tables.models import Board
+# Create your views here.
+#
+
+def load_image(mid):
+# for images on server 15, it will gstream the photos on reload
+ if int(mid) in range(8,17):
+ command = "streamer -q -f jpeg -c /dev/video" + str(mid)
+ command += " -o " + settings.WEBCAM_DIR + "/image" + str(mid) + ".jpeg"
+ os.system(command)
+
+ else:
+ take_snapshot = requests.get("http://10.102.152.16:8080/webcams/%d/take_snapshot" % int(mid))
+ get_image_link = "http://10.102.152.16:8080/webcams/%d/get_image_data" % int(mid)
+
+ command = "curl -s %s > %s/image%d.jpeg" % (get_image_link, str(settings.WEBCAM_DIR), int(mid))
+ os.system(command)
+def reload(req, mid):
+
+ load_image(mid)
+ return HttpResponse("")
+
+@login_required(redirect_field_name=None)
+def show_video(req):
+ board = req.user.board
+
+ image_link = board.image_link()
+ mid = str(board.mid)
+
+# image_link = board.image_link()
+
+ return render(req, "webcam/show_video.html", {"image_link": image_link, "mid": mid})
+
+
+@login_required(redirect_field_name=None)
+def show_video_to_admin(req, mid):
+ checkadmin(req)
+ board = Board.objects.get(mid=int(mid))
+ image_link = board.image_link()
+ mid = str(board.mid)
+ return render(req, "webcam/show_video.html", {"image_link": image_link, "mid": mid})