summaryrefslogtreecommitdiff
path: root/webcam/views.py
blob: f6a1a819c93814a32f80b97c82e8299af41a7a9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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


def load_image(mid):
    """ Displays the image of the SBHS onto the user screen.
    
        Input: mid: machine-id of the concerned SBHS.
    """
# 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):
    """ Refreshes the image of the SBHS
    
        Input: req:request object, mid: machine-id of the concerned SBHS.
        Output: HttpResponse object.
    """
    load_image(mid)
    return HttpResponse("")

@login_required(redirect_field_name=None)
def show_video(req):
    """ Shows the video of the SBHS.
    
        Input: req:request object.
        Output: HttpResponse object.
    """
    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):
    """ Shows the video of the SBHS to the admin.
    
        Input: req:request object.
        Output: HttpResponse object.
    """
    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})