summaryrefslogtreecommitdiff
path: root/webcam
diff options
context:
space:
mode:
authorcoderick142017-05-17 15:40:18 +0530
committercoderick142017-05-17 15:41:00 +0530
commita1e0a5502f04da68b6a9ca8508dda3f9d7e1d055 (patch)
tree20181e6b1936f50ad48d8e35720d64a37566f558 /webcam
parent6f4a84c1e58ff4d54aab94cbee26e995328b05b8 (diff)
downloadSBHS-2018-Rpi-a1e0a5502f04da68b6a9ca8508dda3f9d7e1d055.tar.gz
SBHS-2018-Rpi-a1e0a5502f04da68b6a9ca8508dda3f9d7e1d055.tar.bz2
SBHS-2018-Rpi-a1e0a5502f04da68b6a9ca8508dda3f9d7e1d055.zip
Upgrade to Django 1.11
- Database integration yet to be tested
Diffstat (limited to 'webcam')
-rw-r--r--webcam/__init__.py0
-rw-r--r--webcam/admin.py3
-rw-r--r--webcam/management/__init__.py0
-rw-r--r--webcam/management/commands/__init__.py0
-rw-r--r--webcam/management/commands/reload_images.py12
-rw-r--r--webcam/models.py3
-rw-r--r--webcam/tests.py3
-rw-r--r--webcam/urls.py9
-rw-r--r--webcam/views.py47
-rw-r--r--webcam/views.py-bkup47
10 files changed, 124 insertions, 0 deletions
diff --git a/webcam/__init__.py b/webcam/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/webcam/__init__.py
diff --git a/webcam/admin.py b/webcam/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/webcam/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/webcam/management/__init__.py b/webcam/management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/webcam/management/__init__.py
diff --git a/webcam/management/commands/__init__.py b/webcam/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/webcam/management/commands/__init__.py
diff --git a/webcam/management/commands/reload_images.py b/webcam/management/commands/reload_images.py
new file mode 100644
index 0000000..5b735cb
--- /dev/null
+++ b/webcam/management/commands/reload_images.py
@@ -0,0 +1,12 @@
+from django.core.management.base import BaseCommand
+from sbhs_server.tables.models import Board
+from sbhs_server.webcam.views import load_image
+
+class Command(BaseCommand):
+ args = ''
+ help = 'Reloads images for all SBHS machines'
+
+ def handle(self, *args, **options):
+ boards = Board.objects.all()
+ for b in boards:
+ load_image(b.mid)
diff --git a/webcam/models.py b/webcam/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/webcam/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/webcam/tests.py b/webcam/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/webcam/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/webcam/urls.py b/webcam/urls.py
new file mode 100644
index 0000000..4bcaa89
--- /dev/null
+++ b/webcam/urls.py
@@ -0,0 +1,9 @@
+from django.conf.urls import url
+
+from . import views
+
+urlpatterns = [
+ url(r'^show_video/?$', views.show_video, name='webcam_show_video'),
+ url(r'^reload_image/(.*)/?$', views.reload, name='webcam_reload_image'),
+ url(r'^admin/webcam/([0-9]+)/?$', views.show_video_to_admin, name='webcam_show_video_to_admin'),
+] \ No newline at end of file
diff --git a/webcam/views.py b/webcam/views.py
new file mode 100644
index 0000000..18f82f5
--- /dev/null
+++ b/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 myadmin.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})
diff --git a/webcam/views.py-bkup b/webcam/views.py-bkup
new file mode 100644
index 0000000..d765730
--- /dev/null
+++ b/webcam/views.py-bkup
@@ -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})