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