root/ossiedev/branches/jsnyder/trunk/tools/cornetApps/HtmlPages/views.py @ 10948

Revision 10948, 4.8 KB (checked in by edent, 2 years ago)

paramiko

Line 
1#Create your views here
2
3from django.http import HttpResponse, Http404, HttpResponseRedirect
4from django.template import Context, loader, RequestContext
5from django.shortcuts import render_to_response
6from django.contrib.auth import logout
7from wavedash.src.WavedashController import Controller
8import wavedash.src.WaveformModel
9from django.contrib.auth.decorators import login_required
10from HtmlPages.models import *
11from HtmlPages.forms import *
12from paramiko.client import SSHClient
13
14def main_page(request):
15        head_title = "Main Page"
16        #ctrlr = Controller(False)
17        #ctrlr.createWidgetContainer()
18        #ctrlr.CORBAutils.init_CORBA(False)
19        #ctrlr.buildModel()
20
21        #availableList = ctrlr.model.getSystemWaveforms()
22        return render_to_response("HtmlPages/main_page.html", locals(), context_instance=RequestContext(request))
23
24def account_page(request, username):
25        try:
26                user = User.objects.get(username=username)
27        except User.DoesNotExist:
28                raise Http404(u'Requested user not found.')
29        return render_to_response("HtmlPages/account_page.html", locals(), context_instance=RequestContext(request))
30
31def logout_page(request):
32        logout(request)
33        return HttpResponseRedirect('http://cornet.wireless.vt.edu/~webdemo/django/')
34
35def setFloorNodes():
36        floorBuffer = 10 #used to calculate the ip address of the node
37        floor1_usrp_status=[0,0,0,1,0,0,0,0,0,1,0,0]
38        floor2_usrp_status=[1,1,0,1,0,1,0,1,0,0,1,0]
39        floor3_usrp_status=[1,1,1,1,1,1,1,0,1,0,0,1]
40        floor4_usrp_status=[1,0,0,1,0,0,1,0,0,1,0,0]
41        floor_list=[floor1_usrp_status, floor2_usrp_status, floor3_usrp_status, floor4_usrp_status]
42        for floor in floor_list:
43                for index in range(len(floor)):
44                        floor[index] = floor[index]*(index+1+floorBuffer)
45                floorBuffer += 12
46        return floor_list
47       
48@login_required
49def ossie_view(request):
50        return render_to_response("HtmlPages/ossie.html", locals(), context_instance=RequestContext(request))
51
52@login_required
53def map_view(request, floor_num):
54        floor=floor_num
55        node_position_1 = ((169,711),(170,651),(170,597),(211,576),(170,512),(170,449),(190,394),(170,334),(194,298),(170,247),(192,210),(158,145))
56        node_position_2 = ((168,708),(168,639),(168,590),(200,542),(168,508),(204,431),(229,400),(168,338),(204,324),(204,273),(204,228),(204,193))
57        node_position_3 = ((175,705),(175,653),(175,598),(206,558),(175,518),(209,452),(236,404),(158,377),(209,333),(210,285),(209,250),(207,206))
58        node_position_4 = ((184,712),(184,666),(184,613),(219,557),(184,517),(222,437),(248,405),(168,372),(221,335),(220,275),(214,226),(219,190))
59        floor_list = setFloorNodes()
60        return render_to_response("HtmlPages/map.html", locals(), context_instance=RequestContext(request))
61
62@login_required
63def grid_view(request):
64        number_of_nodes=range(1,13)
65        floor_list = setFloorNodes()
66        return render_to_response("HtmlPages/grid.html", locals(), context_instance=RequestContext(request))
67
68@login_required
69def node_menu(request):
70        nodes=[Node(id=3-1, ip=33),
71                Node(id=3-2, ip=34),
72                Node(id=3-3, ip=35),
73                Node(id=3-4, ip=36),
74                Node(id=3-5, ip=37),
75                Node(id=3-6, ip=38)]
76        return render_to_response("HtmlPages/node_menu.html", locals(), context_instance=RequestContext(request))
77
78@login_required
79def loadNode(request, node_num):
80        return render_to_response("HtmlPages/nodes.html", locals(), context_instance=RequestContext(request))
81
82def register_page(request):
83        if request.method == 'POST':
84                form = RegistrationForm(request.POST)
85                if form.is_valid():
86                        user = User.objects.create_user(
87                                username=form.cleaned_data['username'],
88                                password=form.cleaned_data['password1'],
89                                email=form.cleaned_data['email']
90                        )
91                        return HttpResponseRedirect('/')
92        else:
93                form = RegistrationForm()
94        variables = RequestContext(request, {'form':form})
95        return render_to_response('registration/register.html', variables)     
96       
97@login_required
98def console_page(request, ip):
99        client = SSHClient()
100        client.connect(ip)
101        message = client.exec_command('cd /sdr; nodeBooter -D -d dev/nodes/default_GPP_node/DeviceManager.dcd.xml')
102        return render_to_response('HtmlPages/console.html', locals(), context_instance=RequestContext(request))
103
104@login_required
105def properties_page(request):
106        return render_to_response('HtmlPages/properties.html', locals(), context_instance=RequestContext(request))
107
108@login_required
109def tasks_page(request):
110        return render_to_response('HtmlPages/tasks.html', locals(), context_instance=RequestContext(request))
111
112@login_required
113def workspace_page(request):
114        return render_to_response('HtmlPages/workspace.html', locals(), context_instance=RequestContext(request))
115
116#@login_required
117#def views_page(request, view_type):
118#       view = view_type
119#       floor_list = setFloorNodes()
120#       grid=range(1,13)
121#       node_positions_floor_1 = ((169,711),(170,651),(170,597),(211,576),(170,512),(170,449),(190,394),(170,334),(194,298),(170,247),(192,210),(158,145))
122#       return render_to_response('HtmlPages/views.html', locals(), context_instance=RequestContext(request))
Note: See TracBrowser for help on using the browser.