root/ossiedev/trunk/tools/cornetApps/WebDash/views.py @ 10863

Revision 10863, 6.1 KB (checked in by Snyder.Jason, 21 months ago)

changes for connecting to remote naming services

Line 
1# Create your views here.
2
3from django.http import HttpResponse
4from django.core.context_processors import csrf
5from django.shortcuts import render_to_response
6from django.template import RequestContext
7from wavedash.src.WavedashController import Controller
8from BaseHTTPServer import HTTPServer
9import wavedash.src.WaveformModel
10
11def buildController(request, address=None):
12        ctrlr = Controller(False)
13        ctrlr.createWidgetContainer() 
14        if address is not None:
15                print 'here'
16                request.session['namingService'] = address
17                ctrlr.CORBAutils.setNamingService(str(address))
18        else:
19                print 'there'
20                namingService = request.session.get('namingService')
21                if namingService:
22                        ctrlr.CORBAutils.setNamingService(str(namingService))
23
24        print 'naming service: ' + ctrlr.CORBAutils.getNamingService()
25        ctrlr.CORBAutils.init_CORBA(False)
26        ctrlr.buildModel()
27        return ctrlr
28
29def waveforms(request):
30        ctrlr = buildController(request)
31        availableList = ctrlr.model.getSystemWaveforms()
32        return render_to_response("WebDash/waveforms.html", locals(), context_instance=RequestContext(request))
33       
34def index(request):     
35        ctrlr = buildController(request)
36
37        availableList = ctrlr.model.getSystemWaveforms()
38        instancesList = []     
39        instances = []
40        for waveform in availableList:
41                instances = ctrlr.model.getInstanceWaveforms(waveform.getName())
42                if instances:
43                        for instance in instances:
44                                instancesList.append(instance)
45
46       
47        return render_to_response('WebDash/index.html',
48                                                          {'availableList' : availableList, 'instancesList' : instancesList})
49       
50def index2(request, address):
51        print address
52        ctrlr = buildController(request, address)
53       
54        availableList = ctrlr.model.getSystemWaveforms()
55        instancesList = []     
56        instances = []
57        for waveform in availableList:
58                instances = ctrlr.model.getInstanceWaveforms(waveform.getName())
59                if instances:
60                        for instance in instances:
61                                instancesList.append(instance)
62
63       
64        return render_to_response('WebDash/index.html',
65                                                          {'availableList' : availableList, 'instancesList' : instancesList})
66
67def running_page(request):
68        ctrlr = buildController(request)
69
70        availableList = ctrlr.model.getSystemWaveforms()
71        instancesList = []     
72        instances = []
73        for waveform in availableList:
74                instances = ctrlr.model.getInstanceWaveforms(waveform.getName())
75                if instances:
76                        for instance in instances:
77                                instancesList.append(instance)
78       
79        return render_to_response('WebDash/running.html', {'instancesList' : instancesList})
80
81def install(request, waveform_to_install):
82        ctrlr = buildController(request)
83
84        instance = ctrlr.installWaveform(waveform_to_install, True)
85        if instance:   
86                message = 'Install Successful'
87        else:   
88                message = 'Install Unsuccessful'
89
90        #link = '/WebDash/'
91        #return render_to_response('WebDash/message.html', {'message' : message, 'link' : link})
92        return running_page(request)
93
94
95def display(request, instance):
96        print 'in display: '
97        print '         request: ' + str(request)
98        print '         instance: ' + str(instance)
99        ctrlr = buildController(request)
100       
101        instance = ctrlr.model.getWaveform(instance, wavedash.src.WaveformModel.INSTANCE_WAVEFORM)
102
103        map = getControlMap(request)
104        propMap = {}
105        components = instance.components
106        for comp in components:
107                properties = comp.properties
108                for prop in properties:
109                        print prop.name + ": " + str(prop.type)
110                        for widget in ctrlr.getOptionalWidgets(prop.type):
111                                print widget.type
112                        propMap[prop.name] = ctrlr.getOptionalWidgets(prop.type)
113               
114       
115       
116
117        return render_to_response('WebDash/display.html',
118                                                          {'instance' : instance, 'map' : map, 'propMap' : propMap}, context_instance=RequestContext(request)) 
119
120def uninstall(request, instance_to_uninstall):
121        ctrlr = buildController(request)
122
123        uninstall = ctrlr.uninstallWaveform(instance_to_uninstall)
124        if uninstall:
125                message = 'Uninstall Successful'
126        else:
127                message = 'Uninstall Not Successful'
128
129        #link = '/WebDash/'
130        #return render_to_response('WebDash/message.html', {'message' : message, 'link' : link})
131        return running_page(request)
132
133def configure(request):
134        ctrlr = buildController(request)
135        if request.method == 'POST':
136                waveName = request.POST['waveform']
137                compName = request.POST['component']
138                propName = request.POST['property']
139                newValue = request.POST['propValue']
140               
141               
142                wave = ctrlr.model.getWaveform(waveName, wavedash.src.WaveformModel.INSTANCE_WAVEFORM)
143                comp = wave.getComponent(compName)
144                prop = comp.findPropertyByName(propName)
145           
146                propType = prop.getType()[1]
147                if propType in ['short', 'ushort', 'int', 'uint'] :
148                        ctrlr.model.configure(waveName, compName, propName, int(newValue))
149                elif propType in ['long', 'ulong']:
150                        ctrlr.model.configure(waveName, compName, propName, long(newValue))
151                elif propType in ['double', 'float']:
152                        ctrlr.model.configure(waveName, compName, propName, float(newValue))
153                elif propType in ['char', 'string']:
154                        ctrlr.model.configure(waveName, compName, propName, str(newValue))
155                elif propType in ['boolean']:
156                        if str(newValue).lower() in trueValues:
157                                ctrlr.model.configure(waveName, compName, propName, True)
158                        else:
159                                ctrlr.model.configure(waveName, compName, propName, False)
160       
161                message = "Configure successful!"
162                link = '/WebDash/' + waveName + '/display/'
163        return render_to_response('WebDash/message.html',
164                                                                {'message' : message, 'link' : link}, context_instance=RequestContext(request))
165
166       
167       
168def updateControls(request):
169        ctrlr = buildController(request)
170        if request.method == 'POST':
171                waveName = request.POST['waveform']
172                compName = request.POST['component']
173                propName = request.POST['property']
174       
175                widgetType = request.POST['control']
176               
177                wave = ctrlr.model.getWaveform(waveName, wavedash.src.WaveformModel.INSTANCE_WAVEFORM)
178                comp = wave.getComponent(compName)
179                prop = comp.findPropertyByName(propName)
180                map = getControlMap(request)
181                key = wave.getName() +  comp.getName() + prop.getName()
182                map[key] = widgetType
183                request.session['controlMap'] = map
184                print map
185               
186               
187                message = "Update successful!"
188                link = '/WebDash/' + waveName + '/display/'
189                return render_to_response('WebDash/message.html',
190                                                                {'message' : message, 'link' : link}, context_instance=RequestContext(request))
191               
192       
193def getControlMap(request):
194        map = request.session.get('controlMap')
195        if map:
196                return map
197        else:
198                map = {}
199                return map
200
Note: See TracBrowser for help on using the browser.