@@ -0,0 +1,18 | |||
|
1 | {% extends "dev_conf_edit.html" %} | |
|
2 | ||
|
3 | {% block content %} | |
|
4 | <form class="form" method="post" action=""> | |
|
5 | {% csrf_token %} | |
|
6 | ||
|
7 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> | |
|
8 | {% include "rc_lines.html" %} | |
|
9 | </div> | |
|
10 | ||
|
11 | <div style="clear: both;"></div> | |
|
12 | <br> | |
|
13 | <div class="pull-right"> | |
|
14 | <button type="button" class="btn btn-primary" onclick="{% if previous %}window.location.replace('{{ previous }}');{% else %}history.go(-1);{% endif %}">Cancel</button> | |
|
15 | <button type="submit" class="btn btn-primary">{{button}}</button> | |
|
16 | </div> | |
|
17 | </form> | |
|
18 | {% endblock %} No newline at end of file |
@@ -0,0 +1,21 | |||
|
1 | {% load bootstrap3 %} | |
|
2 | ||
|
3 | {% for line in rc_lines %} | |
|
4 | <div class="panel panel-default" id="panel-{{line.id}}"> | |
|
5 | <div class="panel-heading" role="tab" id="heading{{line.id}}"> | |
|
6 | <h4 class="panel-title"> | |
|
7 | <a role="button" data-toggle="collapse" data-parent="#div_lines" href="#collapse{{line.id}}" aria-expanded="true" aria-controls="collapse{{line.id}}"> | |
|
8 | CH{{line.channel}} - {{line.get_name}} | |
|
9 | </a> | |
|
10 | {% if not edit %} | |
|
11 | <button class="btn-xs btn-default pull-right" name="bt_remove_line" value="{{line.pk}}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button> | |
|
12 | {% endif %} | |
|
13 | </h4> | |
|
14 | </div> | |
|
15 | <div id="collapse{{line.id}}" class="panel-collapse collapse{% if edit %} in{% endif %}" role="tabpanel" aria-labelledby="heading{{line.id}}"> | |
|
16 | <div class="panel-body"> | |
|
17 | {% bootstrap_form line.form layout='horizontal' size='small' %} | |
|
18 | </div> | |
|
19 | </div> | |
|
20 | </div> | |
|
21 | {% endfor%} |
@@ -1,457 +1,474 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | 2 | |
|
3 | 3 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm |
|
4 | 4 | from apps.cgs.forms import CGSConfigurationForm |
|
5 | 5 | from apps.jars.forms import JARSConfigurationForm |
|
6 | 6 | from apps.usrp.forms import USRPConfigurationForm |
|
7 | 7 | from apps.abs.forms import ABSConfigurationForm |
|
8 | 8 | from apps.rc.forms import RCConfigurationForm |
|
9 | 9 | from apps.dds.forms import DDSConfigurationForm |
|
10 | 10 | |
|
11 | 11 | from .models import Campaign, Experiment, Device, Configuration |
|
12 | 12 | from apps.cgs.models import CGSConfiguration |
|
13 | 13 | from apps.jars.models import JARSConfiguration |
|
14 | 14 | from apps.usrp.models import USRPConfiguration |
|
15 | 15 | from apps.abs.models import ABSConfiguration |
|
16 | 16 | from apps.rc.models import RCConfiguration |
|
17 | 17 | from apps.dds.models import DDSConfiguration |
|
18 | 18 | |
|
19 | 19 | # Create your views here. |
|
20 | 20 | |
|
21 | 21 | CONF_FORMS = { |
|
22 | 22 | 'rc': RCConfigurationForm, |
|
23 | 23 | 'dds': DDSConfigurationForm, |
|
24 | 24 | 'jars': JARSConfigurationForm, |
|
25 | 25 | 'cgs': CGSConfigurationForm, |
|
26 | 26 | 'abs': ABSConfigurationForm, |
|
27 | 27 | 'usrp': USRPConfigurationForm, |
|
28 | 28 | } |
|
29 | 29 | |
|
30 | 30 | CONF_MODELS = { |
|
31 | 31 | 'rc': RCConfiguration, |
|
32 | 32 | 'dds': DDSConfiguration, |
|
33 | 33 | 'jars': JARSConfiguration, |
|
34 | 34 | 'cgs': CGSConfiguration, |
|
35 | 35 | 'abs': ABSConfiguration, |
|
36 | 36 | 'usrp': USRPConfiguration, |
|
37 | 37 | } |
|
38 | 38 | |
|
39 | 39 | def index(request): |
|
40 | 40 | kwargs = {} |
|
41 | 41 | |
|
42 | 42 | return render(request, 'index.html', kwargs) |
|
43 | 43 | |
|
44 | 44 | def devices(request): |
|
45 | 45 | |
|
46 | 46 | devices = Device.objects.all().order_by('device_type__name') |
|
47 | 47 | |
|
48 | 48 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
49 | 49 | keys = ['id', 'name', 'ip_address', 'device_type'] |
|
50 | 50 | |
|
51 | 51 | kwargs = {} |
|
52 | 52 | kwargs['device_keys'] = keys[1:] |
|
53 | 53 | kwargs['devices'] = devices#.values(*keys) |
|
54 | 54 | kwargs['title'] = 'Device' |
|
55 | 55 | kwargs['suptitle'] = 'List' |
|
56 | 56 | kwargs['button'] = 'New Device' |
|
57 | 57 | |
|
58 | 58 | return render(request, 'devices.html', kwargs) |
|
59 | 59 | |
|
60 | 60 | def device(request, id_dev): |
|
61 | 61 | |
|
62 | 62 | device = get_object_or_404(Device, pk=id_dev) |
|
63 | 63 | |
|
64 | 64 | kwargs = {} |
|
65 | 65 | kwargs['device'] = device |
|
66 | 66 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
67 | 67 | |
|
68 | 68 | kwargs['title'] = 'Device' |
|
69 | 69 | kwargs['suptitle'] = 'Details' |
|
70 | 70 | |
|
71 | 71 | kwargs['button'] = 'Add Device' |
|
72 | 72 | |
|
73 | 73 | return render(request, 'device.html', kwargs) |
|
74 | 74 | |
|
75 | 75 | def device_new(request): |
|
76 | 76 | |
|
77 | 77 | if request.method == 'GET': |
|
78 | 78 | form = DeviceForm() |
|
79 | 79 | |
|
80 | 80 | if request.method == 'POST': |
|
81 | 81 | form = DeviceForm(request.POST) |
|
82 | 82 | |
|
83 | 83 | if form.is_valid(): |
|
84 | 84 | form.save() |
|
85 | 85 | return redirect('url_devices') |
|
86 | 86 | |
|
87 | 87 | kwargs = {} |
|
88 | 88 | kwargs['form'] = form |
|
89 | 89 | kwargs['title'] = 'Device' |
|
90 | 90 | kwargs['suptitle'] = 'New' |
|
91 | 91 | kwargs['button'] = 'Create' |
|
92 | 92 | |
|
93 | 93 | return render(request, 'device_edit.html', kwargs) |
|
94 | 94 | |
|
95 | 95 | def device_edit(request, id_dev): |
|
96 | 96 | |
|
97 | 97 | device = get_object_or_404(Device, pk=id_dev) |
|
98 | 98 | |
|
99 | 99 | if request.method=='GET': |
|
100 | 100 | form = DeviceForm(instance=device) |
|
101 | 101 | |
|
102 | 102 | if request.method=='POST': |
|
103 | 103 | form = DeviceForm(request.POST, instance=device) |
|
104 | 104 | |
|
105 | 105 | if form.is_valid(): |
|
106 | 106 | form.save() |
|
107 | 107 | return redirect('url_devices') |
|
108 | 108 | |
|
109 | 109 | kwargs = {} |
|
110 | 110 | kwargs['form'] = form |
|
111 | 111 | kwargs['title'] = 'Device' |
|
112 | 112 | kwargs['suptitle'] = 'Edit' |
|
113 | 113 | kwargs['button'] = 'Update' |
|
114 | 114 | |
|
115 | 115 | return render(request, 'device_edit.html', kwargs) |
|
116 | 116 | |
|
117 | 117 | def device_delete(request, id_dev): |
|
118 | 118 | |
|
119 | 119 | device = get_object_or_404(Device, pk=id_dev) |
|
120 | 120 | |
|
121 | 121 | if request.method=='POST': |
|
122 | 122 | |
|
123 | 123 | if request.user.is_staff: |
|
124 | 124 | device.delete() |
|
125 | 125 | return redirect('url_devices') |
|
126 | 126 | |
|
127 | 127 | return HttpResponse("Not enough permission to delete this object") |
|
128 | 128 | |
|
129 | 129 | kwargs = {'object':device, 'dev_active':'active', |
|
130 | 130 | 'url_cancel':'url_device', 'id_item':id_dev} |
|
131 | 131 | |
|
132 | 132 | return render(request, 'item_delete.html', kwargs) |
|
133 | 133 | |
|
134 | 134 | def campaigns(request): |
|
135 | 135 | |
|
136 | 136 | campaigns = Campaign.objects.all().order_by('start_date') |
|
137 | 137 | |
|
138 | 138 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
139 | 139 | |
|
140 | 140 | kwargs = {} |
|
141 | 141 | kwargs['campaign_keys'] = keys[1:] |
|
142 | 142 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
143 | 143 | kwargs['title'] = 'Campaign' |
|
144 | 144 | kwargs['suptitle'] = 'List' |
|
145 | 145 | kwargs['button'] = 'New Campaign' |
|
146 | 146 | |
|
147 | 147 | return render(request, 'campaigns.html', kwargs) |
|
148 | 148 | |
|
149 | 149 | def campaign(request, id_camp): |
|
150 | 150 | |
|
151 | 151 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
152 | 152 | experiments = Experiment.objects.filter(campaign=campaign) |
|
153 | 153 | |
|
154 | 154 | form = CampaignForm(instance=campaign) |
|
155 | 155 | |
|
156 | 156 | kwargs = {} |
|
157 | 157 | kwargs['campaign'] = campaign |
|
158 | 158 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
159 | 159 | |
|
160 | 160 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
161 | 161 | |
|
162 | 162 | kwargs['experiment_keys'] = keys[1:] |
|
163 | 163 | kwargs['experiments'] = experiments.values(*keys) |
|
164 | 164 | |
|
165 | 165 | kwargs['title'] = 'Campaign' |
|
166 | 166 | kwargs['suptitle'] = 'Details' |
|
167 | 167 | |
|
168 | 168 | kwargs['form'] = form |
|
169 | 169 | kwargs['button'] = 'Add Experiment' |
|
170 | 170 | |
|
171 | 171 | return render(request, 'campaign.html', kwargs) |
|
172 | 172 | |
|
173 | 173 | def campaign_new(request): |
|
174 | 174 | |
|
175 | 175 | if request.method == 'GET': |
|
176 | 176 | form = CampaignForm() |
|
177 | 177 | |
|
178 | 178 | if request.method == 'POST': |
|
179 | 179 | form = CampaignForm(request.POST) |
|
180 | 180 | |
|
181 | 181 | if form.is_valid(): |
|
182 | 182 | campaign = form.save() |
|
183 | 183 | return redirect('url_campaign', id_camp=campaign.id) |
|
184 | 184 | |
|
185 | 185 | kwargs = {} |
|
186 | 186 | kwargs['form'] = form |
|
187 | 187 | kwargs['title'] = 'Campaign' |
|
188 | 188 | kwargs['suptitle'] = 'New' |
|
189 | 189 | kwargs['button'] = 'Create' |
|
190 | 190 | |
|
191 | 191 | return render(request, 'campaign_edit.html', kwargs) |
|
192 | 192 | |
|
193 | 193 | def campaign_edit(request, id_camp): |
|
194 | 194 | |
|
195 | 195 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
196 | 196 | |
|
197 | 197 | if request.method=='GET': |
|
198 | 198 | form = CampaignForm(instance=campaign) |
|
199 | 199 | |
|
200 | 200 | if request.method=='POST': |
|
201 | 201 | form = CampaignForm(request.POST, instance=campaign) |
|
202 | 202 | |
|
203 | 203 | if form.is_valid(): |
|
204 | 204 | form.save() |
|
205 | 205 | return redirect('url_campaign', id_camp=id_camp) |
|
206 | 206 | |
|
207 | 207 | kwargs = {} |
|
208 | 208 | kwargs['form'] = form |
|
209 | 209 | kwargs['title'] = 'Campaign' |
|
210 | 210 | kwargs['suptitle'] = 'Edit' |
|
211 | 211 | kwargs['button'] = 'Update' |
|
212 | 212 | |
|
213 | 213 | return render(request, 'campaign_edit.html', kwargs) |
|
214 | 214 | |
|
215 | 215 | def campaign_delete(request, id_camp): |
|
216 | 216 | |
|
217 | 217 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
218 | 218 | |
|
219 | 219 | if request.method=='POST': |
|
220 | 220 | if request.user.is_staff: |
|
221 | 221 | campaign.delete() |
|
222 | 222 | return redirect('url_campaigns') |
|
223 | 223 | |
|
224 | 224 | return HttpResponse("Not enough permission to delete this object") |
|
225 | 225 | |
|
226 | 226 | kwargs = {'object':campaign, 'camp_active':'active', |
|
227 | 227 | 'url_cancel':'url_campaign', 'id_item':id_camp} |
|
228 | 228 | |
|
229 | 229 | return render(request, 'item_delete.html', kwargs) |
|
230 | 230 | |
|
231 | 231 | def experiments(request): |
|
232 | 232 | |
|
233 | 233 | experiment_list = Experiment.objects.all().order_by('campaign') |
|
234 | 234 | |
|
235 | 235 | keys = ['id', 'name', 'start_time', 'end_time', 'campaign'] |
|
236 | 236 | |
|
237 | 237 | kwargs = {} |
|
238 | 238 | |
|
239 | 239 | kwargs['experiment_keys'] = keys[1:] |
|
240 | 240 | kwargs['experiments'] = experiment_list#.values(*keys) |
|
241 | 241 | |
|
242 | 242 | kwargs['title'] = 'Experiment' |
|
243 | 243 | kwargs['suptitle'] = 'List' |
|
244 | 244 | kwargs['button'] = 'New Experiment' |
|
245 | 245 | |
|
246 | 246 | return render(request, 'experiments.html', kwargs) |
|
247 | 247 | |
|
248 | 248 | def experiment(request, id_exp): |
|
249 | 249 | |
|
250 | 250 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
251 | 251 | |
|
252 | 252 | experiments = Experiment.objects.filter(campaign=experiment.campaign) |
|
253 | 253 | configurations = Configuration.objects.filter(experiment=experiment) |
|
254 | 254 | |
|
255 | 255 | kwargs = {} |
|
256 | 256 | |
|
257 | 257 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
258 | 258 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
259 | 259 | |
|
260 | 260 | |
|
261 | 261 | kwargs['experiment_keys'] = exp_keys[1:] |
|
262 | 262 | kwargs['experiment'] = experiment |
|
263 | 263 | |
|
264 | 264 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
265 | 265 | |
|
266 | 266 | kwargs['configuration_keys'] = conf_keys[1:] |
|
267 | 267 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
268 | 268 | |
|
269 | 269 | kwargs['title'] = 'Experiment' |
|
270 | 270 | kwargs['suptitle'] = 'Details' |
|
271 | 271 | |
|
272 | 272 | kwargs['button'] = 'Add Device' |
|
273 | 273 | |
|
274 | 274 | return render(request, 'experiment.html', kwargs) |
|
275 | 275 | |
|
276 | 276 | def experiment_new(request, id_camp=0): |
|
277 | 277 | |
|
278 | 278 | if request.method == 'GET': |
|
279 | 279 | form = ExperimentForm(initial={'campaign':id_camp}) |
|
280 | 280 | |
|
281 | 281 | if request.method == 'POST': |
|
282 | 282 | form = ExperimentForm(request.POST, initial={'campaign':id_camp}) |
|
283 | 283 | |
|
284 | 284 | if form.is_valid(): |
|
285 | 285 | experiment = form.save() |
|
286 | 286 | return redirect('url_experiment', id_exp=experiment.id) |
|
287 | 287 | |
|
288 | 288 | kwargs = {} |
|
289 | 289 | kwargs['form'] = form |
|
290 | 290 | kwargs['title'] = 'Experiment' |
|
291 | 291 | kwargs['suptitle'] = 'New' |
|
292 | 292 | kwargs['button'] = 'Create' |
|
293 | 293 | |
|
294 | 294 | return render(request, 'experiment_edit.html', kwargs) |
|
295 | 295 | |
|
296 | 296 | def experiment_edit(request, id_exp): |
|
297 | 297 | |
|
298 | 298 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
299 | 299 | |
|
300 | 300 | if request.method == 'GET': |
|
301 | 301 | form = ExperimentForm(instance=experiment) |
|
302 | 302 | |
|
303 | 303 | if request.method=='POST': |
|
304 | 304 | form = ExperimentForm(request.POST, instance=experiment) |
|
305 | 305 | |
|
306 | 306 | if form.is_valid(): |
|
307 | 307 | experiment = form.save() |
|
308 | 308 | return redirect('url_experiment', id_exp=experiment.id) |
|
309 | 309 | |
|
310 | 310 | kwargs = {} |
|
311 | 311 | kwargs['form'] = form |
|
312 | 312 | kwargs['title'] = 'Experiment' |
|
313 | 313 | kwargs['suptitle'] = 'Edit' |
|
314 | 314 | kwargs['button'] = 'Update' |
|
315 | 315 | |
|
316 | 316 | return render(request, 'experiment_edit.html', kwargs) |
|
317 | 317 | |
|
318 | 318 | def experiment_delete(request, id_exp): |
|
319 | 319 | |
|
320 | 320 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
321 | 321 | |
|
322 | 322 | if request.method=='POST': |
|
323 | 323 | if request.user.is_staff: |
|
324 | 324 | id_camp = experiment.campaign.id |
|
325 | 325 | experiment.delete() |
|
326 | 326 | return redirect('url_campaign', id_camp=id_camp) |
|
327 | 327 | |
|
328 | 328 | return HttpResponse("Not enough permission to delete this object") |
|
329 | 329 | |
|
330 | 330 | kwargs = {'object':experiment, 'exp_active':'active', |
|
331 | 331 | 'url_cancel':'url_experiment', 'id_item':id_exp} |
|
332 | 332 | |
|
333 | 333 | return render(request, 'item_delete.html', kwargs) |
|
334 | 334 | |
|
335 | 335 | def dev_confs(request): |
|
336 | 336 | |
|
337 | 337 | configurations = Configuration.objects.all().order_by('experiment') |
|
338 | 338 | |
|
339 | 339 | # keys = ['id', 'device__device_type__name', 'device__name', 'experiment__campaign__name', 'experiment__name'] |
|
340 | 340 | |
|
341 | 341 | keys = ['id', 'device', 'experiment'] |
|
342 | 342 | |
|
343 | 343 | kwargs = {} |
|
344 | 344 | |
|
345 | 345 | kwargs['configuration_keys'] = keys[1:] |
|
346 | 346 | kwargs['configurations'] = configurations#.values(*keys) |
|
347 | 347 | |
|
348 | 348 | kwargs['title'] = 'Configuration' |
|
349 | 349 | kwargs['suptitle'] = 'List' |
|
350 | 350 | kwargs['button'] = 'New Configuration' |
|
351 | 351 | |
|
352 | 352 | return render(request, 'dev_confs.html', kwargs) |
|
353 | 353 | |
|
354 | 354 | def dev_conf(request, id_conf): |
|
355 | 355 | |
|
356 | 356 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
357 | 357 | |
|
358 | 358 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
359 | 359 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
360 | 360 | |
|
361 | 361 | kwargs = {} |
|
362 | 362 | kwargs['dev_conf'] = dev_conf |
|
363 | 363 | kwargs['dev_conf_keys'] = ['experiment', 'device'] |
|
364 | 364 | |
|
365 | 365 | kwargs['title'] = 'Configuration' |
|
366 | 366 | kwargs['suptitle'] = 'Details' |
|
367 | 367 | |
|
368 | 368 | kwargs['button'] = 'Edit Configuration' |
|
369 | 369 | |
|
370 | 370 | ###### SIDEBAR ###### |
|
371 | 371 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) |
|
372 | 372 | configurations = Configuration.objects.filter(experiment=conf.experiment) |
|
373 | 373 | |
|
374 | 374 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] |
|
375 | 375 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] |
|
376 | 376 | |
|
377 | 377 | kwargs['experiment_keys'] = exp_keys[1:] |
|
378 | 378 | kwargs['experiments'] = experiments.values(*exp_keys) |
|
379 | 379 | |
|
380 | 380 | kwargs['configuration_keys'] = conf_keys[1:] |
|
381 | 381 | kwargs['configurations'] = configurations.values(*conf_keys) |
|
382 | 382 | |
|
383 | 383 | return render(request, 'dev_conf.html', kwargs) |
|
384 | 384 | |
|
385 | 385 | def dev_conf_new(request, id_exp=0): |
|
386 | 386 | |
|
387 | 387 | if request.method == 'GET': |
|
388 | 388 | form = ConfigurationForm(initial={'experiment':id_exp}) |
|
389 | 389 | |
|
390 | 390 | if request.method == 'POST': |
|
391 | 391 | form = ConfigurationForm(request.POST) |
|
392 | 392 | |
|
393 | 393 | if form.is_valid(): |
|
394 | 394 | experiment = Experiment.objects.get(pk=request.POST['experiment']) |
|
395 | 395 | device = Device.objects.get(pk=request.POST['device']) |
|
396 | 396 | |
|
397 | 397 | exp_devices = Device.objects.filter(configuration__experiment=experiment) |
|
398 | 398 | |
|
399 | 399 | if device.id not in exp_devices.values('id',): |
|
400 | 400 | |
|
401 | 401 | DevConfModel = CONF_MODELS[device.device_type.name] |
|
402 | 402 | conf = DevConfModel(experiment=experiment, device=device) |
|
403 | 403 | conf.save() |
|
404 | 404 | |
|
405 | 405 | return redirect('url_experiment', id_exp=experiment.id) |
|
406 | 406 | |
|
407 | 407 | kwargs = {} |
|
408 | 408 | kwargs['form'] = form |
|
409 | 409 | kwargs['title'] = 'Configuration' |
|
410 | 410 | kwargs['suptitle'] = 'New' |
|
411 | 411 | kwargs['button'] = 'Create' |
|
412 | 412 | |
|
413 | 413 | return render(request, 'dev_conf_edit.html', kwargs) |
|
414 | 414 | |
|
415 | 415 | def dev_conf_edit(request, id_conf): |
|
416 | 416 | |
|
417 | 417 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
418 | 418 | |
|
419 | 419 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
420 | 420 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
421 | 421 | |
|
422 | 422 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
423 | 423 | |
|
424 | 424 | if request.method=='GET': |
|
425 | 425 | form = DevConfForm(instance=dev_conf) |
|
426 | 426 | |
|
427 | 427 | if request.method=='POST': |
|
428 | 428 | form = DevConfForm(request.POST, instance=dev_conf) |
|
429 | 429 | |
|
430 | 430 | if form.is_valid(): |
|
431 | 431 | form.save() |
|
432 | 432 | return redirect('url_dev_conf', id_conf=id_conf) |
|
433 | 433 | |
|
434 | 434 | kwargs = {} |
|
435 | 435 | kwargs['form'] = form |
|
436 | 436 | kwargs['title'] = 'Device Configuration' |
|
437 | 437 | kwargs['suptitle'] = 'Edit' |
|
438 | 438 | kwargs['button'] = 'Update' |
|
439 | 439 | |
|
440 | 440 | return render(request, 'dev_conf_edit.html', kwargs) |
|
441 | 441 | |
|
442 | 442 | def dev_conf_delete(request, id_conf): |
|
443 | 443 | |
|
444 | 444 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
445 | 445 | |
|
446 | 446 | if request.method=='POST': |
|
447 | 447 | if request.user.is_staff: |
|
448 | 448 | id_exp = conf.experiment.id |
|
449 | 449 | conf.delete() |
|
450 | 450 | return redirect('url_experiment', id_exp=id_exp) |
|
451 | 451 | |
|
452 | 452 | return HttpResponse("Not enough permission to delete this object") |
|
453 | 453 | |
|
454 | 454 | kwargs = {'object':conf, 'conf_active':'active', |
|
455 | 455 | 'url_cancel':'url_dev_conf', 'id_item':id_conf} |
|
456 | 456 | |
|
457 | return render(request, 'item_delete.html', kwargs) No newline at end of file | |
|
457 | return render(request, 'item_delete.html', kwargs) | |
|
458 | ||
|
459 | def sidebar(conf): | |
|
460 | ||
|
461 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
|
462 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |
|
463 | ||
|
464 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
|
465 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
466 | ||
|
467 | kwargs = {} | |
|
468 | kwargs['experiment_keys'] = exp_keys[1:] | |
|
469 | kwargs['experiments'] = experiments.values(*exp_keys) | |
|
470 | ||
|
471 | kwargs['configuration_keys'] = conf_keys[1:] | |
|
472 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
473 | ||
|
474 | return kwargs No newline at end of file |
@@ -1,8 +1,9 | |||
|
1 | 1 | from django.contrib import admin |
|
2 | from .models import RCConfiguration, RCLine, RCLineType | |
|
2 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode | |
|
3 | 3 | |
|
4 | 4 | # Register your models here. |
|
5 | 5 | |
|
6 | 6 | admin.site.register(RCConfiguration) |
|
7 | 7 | admin.site.register(RCLine) |
|
8 | 8 | admin.site.register(RCLineType) |
|
9 | admin.site.register(RCLineCode) |
@@ -1,43 +1,87 | |||
|
1 | 1 | import json |
|
2 | 2 | |
|
3 | 3 | from django import forms |
|
4 | from .models import RCConfiguration, RCLine, RCLineType | |
|
4 | from .models import RCConfiguration, RCLine, RCLineType, RCLineCode | |
|
5 | ||
|
6 | def create_choices_from_model(model, conf_id): | |
|
7 | ||
|
8 | if model=='RCLine': | |
|
9 | instance = RCConfiguration.objects.get(pk=conf_id) | |
|
10 | return instance.get_refs_lines() | |
|
11 | else: | |
|
12 | instance = globals()[model] | |
|
13 | return instance.objects.all().values_list('pk', 'name') | |
|
5 | 14 | |
|
6 | 15 | class RCConfigurationForm(forms.ModelForm): |
|
7 | 16 | |
|
8 | 17 | class Meta: |
|
9 | 18 | model = RCConfiguration |
|
10 | 19 | exclude = ('clock', 'ipp', 'ntx', 'clock_divider') |
|
11 | 20 | |
|
12 | 21 | |
|
13 | 22 | class RCLineForm(forms.ModelForm): |
|
14 | 23 | |
|
24 | def __init__(self, *args, **kwargs): | |
|
25 | self.extra_fields = kwargs.pop('extra_fields', []) | |
|
26 | super(RCLineForm, self).__init__(*args, **kwargs) | |
|
27 | if 'initial'in kwargs: | |
|
28 | for item in self.extra_fields: | |
|
29 | if 'model' in item: | |
|
30 | self.fields[item['name']] = forms.ChoiceField(choices=create_choices_from_model(item['model'], | |
|
31 | kwargs['initial']['rc_configuration'])) | |
|
32 | else: | |
|
33 | self.fields[item['name']] = forms.CharField(initial=item['value']) | |
|
34 | ||
|
15 | 35 | class Meta: |
|
16 | 36 | model = RCLine |
|
17 | 37 | fields = ('rc_configuration', 'line_type', 'channel') |
|
18 | 38 | widgets = { |
|
19 | 39 | 'channel': forms.HiddenInput(), |
|
20 | 40 | } |
|
21 | 41 | |
|
22 | 42 | def save(self): |
|
23 | 43 | line = super(RCLineForm, self).save() |
|
44 | ||
|
24 | 45 | #auto add channel |
|
25 | 46 | line.channel = RCLine.objects.filter(rc_configuration=line.rc_configuration).count()-1 |
|
47 | ||
|
26 | 48 | #auto add position for TX, TR & CODE |
|
27 | if line.line_type.name in ('tx', 'tr', 'code'): | |
|
49 | if line.line_type.name in ('tx', 'tr', 'codes', 'windows'): | |
|
28 | 50 | line.position = RCLine.objects.filter(rc_configuration=line.rc_configuration, line_type=line.line_type).count()-1 |
|
29 | #add default params | |
|
51 | ||
|
52 | #save extra fields in params | |
|
30 | 53 | params = {} |
|
31 | for field in json.loads(line.line_type.params): | |
|
32 |
params[ |
|
|
54 | for item in self.extra_fields: | |
|
55 | params[item['name']] = self.data[item['name']] | |
|
33 | 56 | line.params = json.dumps(params) |
|
34 | 57 | line.save() |
|
35 | 58 | return |
|
36 | 59 | |
|
37 | 60 | class RCLineViewForm(forms.Form): |
|
38 | 61 | |
|
39 | 62 | def __init__(self, *args, **kwargs): |
|
40 | 63 | extra_fields = kwargs.pop('extra_fields') |
|
41 | 64 | super(RCLineViewForm, self).__init__(*args, **kwargs) |
|
42 | 65 | for label, value in extra_fields.items(): |
|
43 | self.fields[label] = forms.CharField(initial=value) No newline at end of file | |
|
66 | if 'ref' in label: | |
|
67 | value = RCLine.objects.get(pk=value).get_name() | |
|
68 | elif 'code' in label: | |
|
69 | value = RCLineCode.objects.get(pk=value).name | |
|
70 | self.fields[label] = forms.CharField(initial=value) | |
|
71 | ||
|
72 | class RCLineEditForm(forms.Form): | |
|
73 | ||
|
74 | def __init__(self, *args, **kwargs): | |
|
75 | self.extra_fields = kwargs.pop('extra_fields', []) | |
|
76 | super(RCLineEditForm, self).__init__(*args, **kwargs) | |
|
77 | if 'initial'in kwargs: | |
|
78 | for item in self.extra_fields: | |
|
79 | if 'model' in item: | |
|
80 | self.fields[item['name']] = forms.ChoiceField(choices=create_choices_from_model(item['model'], | |
|
81 | kwargs['initial']['rc_configuration']), | |
|
82 | initial=item['value'], | |
|
83 | widget=forms.Select(attrs={'name':'%s|%s' % (kwargs['initial']['line'], item['name'])})) | |
|
84 | else: | |
|
85 | self.fields[item['name']] = forms.CharField(initial=item['value'], | |
|
86 | widget=forms.TextInput(attrs={'name':'%s|%s' % (kwargs['initial']['line'], item['name'])})) | |
|
87 | No newline at end of file |
@@ -1,95 +1,107 | |||
|
1 | 1 | |
|
2 | import json | |
|
3 | ||
|
2 | 4 | from polymorphic import PolymorphicModel |
|
3 | 5 | |
|
4 | 6 | from django.db import models |
|
5 | 7 | from django.core.validators import MinValueValidator, MaxValueValidator |
|
6 | 8 | |
|
7 | 9 | from apps.main.models import Configuration |
|
8 | 10 | # Create your models here. |
|
9 | 11 | |
|
10 | 12 | LINE_TYPES = ( |
|
11 | 13 | ('tr', 'Transmission/reception selector signal'), |
|
12 | 14 | ('tx', 'A modulating signal (Transmission pulse)'), |
|
13 | 15 | ('codes', 'BPSK modulating signal'), |
|
14 | 16 | ('windows', 'Sample window signal'), |
|
15 | 17 | ('sync', 'Synchronizing signal'), |
|
16 | 18 | ('flip', 'IPP related periodic signal'), |
|
17 | 19 | ('prog_pulses', 'Programmable pulse'), |
|
18 | 20 | ) |
|
19 | 21 | |
|
20 | 22 | LINE_PARAMS = { |
|
21 | 23 | "tr": [{"name":"time_after", "value": 0}], |
|
22 | 24 | "tx": [{"name": "pulse_width", "value": 0},{"name":"delays", "value":""}], |
|
23 | 25 | "codes": [{"name":"tx_ref", "value": ""},{"name":"code", "value": "", "choices":"RCLineCode"}], |
|
24 | 26 | "windows": [{"name":"tx_ref","value":""}, {"name":"first_height", "value":0}, {"name":"number_of_samples","value":0}, {"name":"resolution","value":0}, {"name":"last_height","value":0}], |
|
25 | 27 | "sync": [{"name": "delay", "value": 0}], |
|
26 | 28 | "flip": [{"name":"number_of_flips", "value": 0}], |
|
27 | 29 | "prog_pulses": [{"name": "begin", "value": 0}, {"name": "end","value": 0}], |
|
28 | 30 | } |
|
29 | 31 | |
|
30 | 32 | |
|
31 | 33 | class RCConfiguration(Configuration): |
|
32 | 34 | |
|
33 | 35 | clock = models.FloatField(verbose_name='Clock Master (MHz)', validators=[MinValueValidator(0), MaxValueValidator(80)], blank=True, null=True) |
|
34 | 36 | clock_divider = models.PositiveIntegerField(verbose_name='Clock divider', validators=[MinValueValidator(0), MaxValueValidator(256)], blank=True, null=True) |
|
35 | 37 | ipp = models.PositiveIntegerField(verbose_name='Inter pulse period (Km)', default=10) |
|
36 | 38 | ntx = models.PositiveIntegerField(verbose_name='Number of pulse of transmit', default=1) |
|
37 | 39 | time_before = models.PositiveIntegerField(verbose_name='Number of pulse of transmit', default=0) |
|
38 | 40 | |
|
39 | 41 | class Meta: |
|
40 | 42 | db_table = 'rc_configurations' |
|
41 | 43 | |
|
42 | 44 | def get_number_position(self): |
|
43 | 45 | |
|
44 | 46 | lines = RCLine.objects.filter(rc_configuration=self.rc_configuration) |
|
45 | 47 | if lines: |
|
46 | 48 | return max([line.position for line in lines]) |
|
47 | 49 | |
|
50 | def get_refs_lines(self): | |
|
51 | ||
|
52 | lines = RCLine.objects.filter(rc_configuration=self.pk, line_type__name='tx') | |
|
53 | return [(line.pk, line.get_name()) for line in lines] | |
|
54 | ||
|
48 | 55 | class RCLineCode(models.Model): |
|
49 | 56 | |
|
50 |
name = models.CharField( |
|
|
57 | name = models.CharField(max_length=40) | |
|
51 | 58 | bits_per_code = models.PositiveIntegerField(default=0) |
|
52 | 59 | number_of_codes = models.PositiveIntegerField(default=0) |
|
53 | 60 | codes = models.TextField(blank=True, null=True) |
|
54 | 61 | |
|
55 | 62 | class Meta: |
|
56 | 63 | db_table = 'rc_line_codes' |
|
57 | ||
|
64 | ordering = ('name',) | |
|
65 | ||
|
66 | def __unicode__(self): | |
|
67 | return u'%s' % self.name | |
|
58 | 68 | |
|
59 | 69 | class RCLineType(models.Model): |
|
60 | 70 | |
|
61 | 71 | name = models.CharField(choices=LINE_TYPES, max_length=40) |
|
62 | 72 | description = models.TextField(blank=True, null=True) |
|
63 | 73 | params = models.TextField(default='[]') |
|
64 | 74 | |
|
65 | 75 | class Meta: |
|
66 | 76 | db_table = 'rc_line_types' |
|
67 | 77 | |
|
68 | 78 | def __unicode__(self): |
|
69 | 79 | return u'%s - %s' % (self.name.upper(), self.get_name_display()) |
|
70 | 80 | |
|
71 | 81 | |
|
72 | 82 | class RCLine(models.Model): |
|
73 | 83 | |
|
74 | 84 | rc_configuration = models.ForeignKey(RCConfiguration) |
|
75 | 85 | line_type = models.ForeignKey(RCLineType) |
|
76 | 86 | channel = models.PositiveIntegerField(default=0) |
|
77 | 87 | position = models.PositiveIntegerField(default=0) |
|
78 | 88 | params = models.TextField(default='{}') |
|
79 | 89 | |
|
80 | 90 | class Meta: |
|
81 | 91 | db_table = 'rc_lines' |
|
82 | 92 | |
|
83 | 93 | def __unicode__(self): |
|
84 | 94 | return u'%s - %s' % (self.rc_configuration, self.get_name()) |
|
85 | 95 | |
|
86 | 96 | def get_name(self): |
|
87 | 97 | |
|
88 | 98 | chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|
89 | 99 | |
|
90 |
if self.line_type.name in ('tx', ' |
|
|
91 | return '%s%s' % (self.line_type.name.upper(), chars[self.position]) | |
|
92 | ||
|
93 | return self.line_type.name.upper() | |
|
94 | ||
|
95 | ||
|
100 | if self.line_type.name in ('tx', 'tr',): | |
|
101 | return '%s %s' % (self.line_type.name.upper(), chars[self.position]) | |
|
102 | elif self.line_type.name in ('codes', 'windows',): | |
|
103 | pk = json.loads(self.params)['TX_ref'] | |
|
104 | ref = RCLine.objects.get(pk=pk) | |
|
105 | return '%s %s' % (self.line_type.name.upper(), chars[ref.position]) | |
|
106 | else: | |
|
107 | return self.line_type.name.upper() |
@@ -1,1 +1,13 | |||
|
1 | {% extends "dev_conf_edit.html" %} No newline at end of file | |
|
1 | {% extends "dev_conf_edit.html" %} | |
|
2 | ||
|
3 | {% block extra-js%} | |
|
4 | ||
|
5 | <script type="text/javascript"> | |
|
6 | ||
|
7 | $("#id_line_type").change(function() { | |
|
8 | var url = "{% url 'url_add_rc_line' dev_conf.id %}"; | |
|
9 | document.location = url + $(this).val()+"/"; | |
|
10 | }); | |
|
11 | ||
|
12 | </script> | |
|
13 | {% endblock %} No newline at end of file |
@@ -1,82 +1,71 | |||
|
1 | 1 | {% extends "dev_conf.html" %} |
|
2 | 2 | {% load static %} |
|
3 | 3 | {% load bootstrap3 %} |
|
4 | {% load main_tags %}s | |
|
5 | ||
|
4 | 6 | {% block extra-head %} |
|
5 | 7 | <style type="text/css"> |
|
6 | 8 | /* show the move cursor as the user moves the mouse over the panel header.*/ |
|
7 | 9 | .panel-default { cursor: move; } |
|
8 | 10 | </style> |
|
9 | 11 | {% endblock %} |
|
10 | 12 | {% block content %} |
|
11 | 13 | <table class="table table-bordered"> |
|
12 | 14 | {% for key in dev_conf_keys %} |
|
13 | 15 | <tr><th>{{key|title}}</th><td>{{dev_conf|attr:key}}</td></tr> |
|
14 | 16 | {% endfor %} |
|
15 | 17 | </table> |
|
16 | 18 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_send">Send</button> |
|
17 | 19 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> |
|
18 | 20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> |
|
19 | 21 | <br> |
|
20 | 22 | <h2>RC Lines</h2><hr> |
|
21 | 23 | |
|
22 |
<div class="panel-group" id=" |
|
|
23 |
{% |
|
|
24 | <div class="panel panel-default" > | |
|
25 | <div class="panel-heading" role="tab" id="headingOne"> | |
|
26 | <h4 class="panel-title"> | |
|
27 | <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{line.id}}" aria-expanded="true" aria-controls="collapseOne"> | |
|
28 | CH{{line.channel}} - {{line.get_name}} | |
|
29 | </a> | |
|
30 | <button class="btn-xs btn-danger pull-right" name="bt_remove_line" value="{{line.pk}}"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button> | |
|
31 | <button class="btn-xs btn-info pull-right" name="bt_line_down" value="{{line.pk}}"><span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span></button> | |
|
32 | <button class="btn-xs btn-info pull-right" name="bt_line_up" value="{{line.pk}}"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span></button> | |
|
33 | </h4> | |
|
34 | </div> | |
|
35 | <div id="collapse{{line.id}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne"> | |
|
36 | <div class="panel-body"> | |
|
37 | {% bootstrap_form line.form layout='horizontal' size='small' %} | |
|
38 | </div> | |
|
39 | </div> | |
|
40 | </div> | |
|
41 | {% endfor%} | |
|
24 | <div class="panel-group" id="div_lines" role="tablist" aria-multiselectable="true"> | |
|
25 | {% include "rc_lines.html" %} | |
|
42 | 26 | </div> |
|
27 | ||
|
43 | 28 | <br> |
|
44 | 29 | <div class="pull-right"> |
|
45 | 30 | <button class="btn btn-primary" id="bt_add_line">Add Line</button> |
|
46 |
<button class="btn btn-primary" id="bt_ |
|
|
31 | <button class="btn btn-primary" id="bt_edit_lines"> Edit </button> | |
|
47 | 32 | <button class="btn btn-primary" id="bt_pulses">Pulses</button> |
|
48 | 33 | </div> |
|
49 | 34 | {% endblock %} |
|
50 | 35 | |
|
51 | 36 | |
|
52 | 37 | {% block extra-js%} |
|
53 | 38 | |
|
54 | 39 | <script type="text/javascript"> |
|
55 | $(document).ready(function() { | |
|
40 | ||
|
56 | 41 | $("#bt_edit").click(function() { |
|
57 | document.location = "{% url 'url_edit_rc_conf' dev_conf.id%}"; | |
|
58 | }); | |
|
59 | ||
|
60 | $("#bt_add_line").click(function() { | |
|
61 | document.location = "{% url 'url_add_rc_line' dev_conf.id%}"; | |
|
42 | document.location = "{% url 'url_edit_rc_conf' dev_conf.id %}"; | |
|
62 | 43 | }); |
|
63 | 44 | |
|
64 |
$(" |
|
|
45 | $("#div_lines").on("click", "button[name=bt_remove_line]", function(){ | |
|
65 | 46 | document.location = "line/"+$(this).val()+"/delete/"; |
|
66 |
}); |
|
|
67 | ||
|
68 | $("button[name=bt_line_up]").click(function(){ | |
|
69 | document.location = "line/"+$(this).val()+"/up/"; | |
|
70 | }); | |
|
47 | }); | |
|
71 | 48 | |
|
72 | $("button[name=bt_line_down]").click(function(){ | |
|
73 | document.location = "line/"+$(this).val()+"/down/"; | |
|
74 | }); | |
|
49 | $(".panel-group").sortable({ | |
|
50 | //placeholder: "ui-state-highlight", | |
|
51 | update: function( event, ui ) { | |
|
52 | var sorted = $( ".panel-group" ).sortable( "serialize", { key: "item" } ); | |
|
53 | var url = "{% url 'url_update_rc_lines' dev_conf.id %}"; | |
|
54 | var csrf_token = "{{csrf_token}}"; | |
|
55 | $.post( url, { 'items': sorted, 'csrfmiddlewaretoken': csrf_token }, function(data){ | |
|
56 | $("#div_lines").html(data.html); | |
|
57 | }); | |
|
58 | } | |
|
59 | }); | |
|
75 | 60 | |
|
76 | ||
|
61 | ||
|
62 | $("#bt_add_line").click(function() { | |
|
63 | document.location = "{% url 'url_add_rc_line' dev_conf.id%}"; | |
|
64 | }); | |
|
77 | 65 | |
|
78 | $(".panel-group").sortable(); | |
|
66 | $("#bt_edit_lines").click(function() { | |
|
67 | document.location = "{% url 'url_edit_rc_lines' dev_conf.id %}"; | |
|
68 | }); | |
|
79 | 69 | |
|
80 | }); | |
|
81 | 70 | </script> |
|
82 | 71 | {% endblock %} No newline at end of file |
@@ -1,10 +1,11 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^(?P<id>-?\d+)/$', 'apps.rc.views.conf', name='url_rc_conf'), |
|
5 | 5 | url(r'^(?P<id>-?\d+)/edit/$', 'apps.rc.views.conf_edit', name='url_edit_rc_conf'), |
|
6 | url(r'^(?P<id>-?\d+)/add_line/$', 'apps.rc.views.add_line', name='url_add_rc_line'), | |
|
6 | url(r'^(?P<conf_id>-?\d+)/add_line/$', 'apps.rc.views.add_line', name='url_add_rc_line'), | |
|
7 | url(r'^(?P<conf_id>-?\d+)/update_lines/$', 'apps.rc.views.update_lines', name='url_update_rc_lines'), | |
|
8 | url(r'^(?P<conf_id>-?\d+)/edit_lines/$', 'apps.rc.views.edit_lines', name='url_edit_rc_lines'), | |
|
9 | url(r'^(?P<conf_id>-?\d+)/add_line/(?P<line_type_id>-?\d+)/$', 'apps.rc.views.add_line', name='url_add_rc_line'), | |
|
7 | 10 | url(r'^(?P<conf_id>-?\d+)/line/(?P<line_id>-?\d+)/delete/$', 'apps.rc.views.remove_line', name='url_remove_rc_line'), |
|
8 | url(r'^(?P<conf_id>-?\d+)/line/(?P<line_id>-?\d+)/up/$', 'apps.rc.views.line_up', name='url_rc_line_up'), | |
|
9 | url(r'^(?P<conf_id>-?\d+)/line/(?P<line_id>-?\d+)/down/$', 'apps.rc.views.line_down', name='url_rc_line_down'), | |
|
10 | 11 | ) |
@@ -1,154 +1,200 | |||
|
1 | 1 | import json |
|
2 | 2 | |
|
3 | 3 | from django.contrib import messages |
|
4 | from django.shortcuts import render, redirect, get_object_or_404 | |
|
4 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
|
5 | 5 | |
|
6 | 6 | from apps.main.models import Configuration, Experiment |
|
7 | from apps.main.views import sidebar | |
|
7 | 8 | |
|
8 | from .models import RCConfiguration, RCLine | |
|
9 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm | |
|
9 | from .models import RCConfiguration, RCLine, RCLineType | |
|
10 | from .forms import RCConfigurationForm, RCLineForm, RCLineViewForm, RCLineEditForm | |
|
10 | 11 | |
|
11 | 12 | |
|
12 | 13 | def conf(request, id): |
|
13 | 14 | |
|
14 | 15 | conf = get_object_or_404(RCConfiguration, pk=id) |
|
15 | 16 | |
|
16 | 17 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') |
|
17 | 18 | |
|
18 | 19 | for line in lines: |
|
19 | 20 | line.form = RCLineViewForm(extra_fields=json.loads(line.params)) |
|
20 | 21 | |
|
21 | 22 | kwargs = {} |
|
22 | 23 | kwargs['dev_conf'] = conf |
|
23 | 24 | kwargs['rc_lines'] = lines |
|
24 | 25 | kwargs['dev_conf_keys'] = ['clock', 'ipp', 'ntx','clock_divider'] |
|
25 | 26 | |
|
26 | 27 | kwargs['title'] = 'RC Configuration' |
|
27 | 28 | kwargs['suptitle'] = 'Details' |
|
28 | 29 | |
|
29 | 30 | kwargs['button'] = 'Edit Configuration' |
|
30 | 31 | |
|
31 | 32 | ###### SIDEBAR ###### |
|
32 | experiments = Experiment.objects.filter(campaign=conf.experiment.campaign) | |
|
33 | configurations = Configuration.objects.filter(experiment=conf.experiment) | |
|
34 | ||
|
35 | exp_keys = ['id', 'campaign', 'name', 'start_time', 'end_time'] | |
|
36 | conf_keys = ['id', 'device__name', 'device__device_type__name', 'device__ip_address'] | |
|
37 | ||
|
38 | kwargs['experiment_keys'] = exp_keys[1:] | |
|
39 | kwargs['experiments'] = experiments.values(*exp_keys) | |
|
40 | ||
|
41 | kwargs['configuration_keys'] = conf_keys[1:] | |
|
42 | kwargs['configurations'] = configurations.values(*conf_keys) | |
|
33 | kwargs.update(sidebar(conf)) | |
|
43 | 34 | |
|
44 | 35 | return render(request, 'rc_conf.html', kwargs) |
|
45 | 36 | |
|
46 | 37 | |
|
47 | 38 | def conf_edit(request, id): |
|
48 | 39 | |
|
49 | 40 | conf = get_object_or_404(RCConfiguration, pk=id) |
|
50 | 41 | |
|
51 | 42 | if request.method=='GET': |
|
52 | 43 | form = RCConfigurationForm(instance=conf) |
|
53 | 44 | |
|
54 | 45 | if request.method=='POST': |
|
55 | 46 | form = RCConfigurationForm(request.POST, instance=conf) |
|
56 | 47 | |
|
57 | 48 | if form.is_valid(): |
|
58 | 49 | form.save() |
|
59 |
return redirect('url_ |
|
|
50 | return redirect('url_dev_conf', id=id) | |
|
60 | 51 | |
|
61 | 52 | kwargs = {} |
|
53 | kwargs['dev_conf'] = conf | |
|
62 | 54 | kwargs['form'] = form |
|
63 | 55 | kwargs['title'] = 'Device Configuration' |
|
64 | 56 | kwargs['suptitle'] = 'Edit' |
|
65 | 57 | kwargs['button'] = 'Update' |
|
66 | 58 | kwargs['previous'] = conf.get_absolute_url() |
|
59 | ||
|
60 | kwargs.update(sidebar(conf)) | |
|
61 | ||
|
67 | 62 | return render(request, 'rc_conf_edit.html', kwargs) |
|
68 | 63 | |
|
69 | 64 | |
|
70 | def add_line(request, id): | |
|
65 | def add_line(request, conf_id, line_type_id=None): | |
|
71 | 66 | |
|
72 | conf = get_object_or_404(RCConfiguration, pk=id) | |
|
67 | conf = get_object_or_404(RCConfiguration, pk=conf_id) | |
|
73 | 68 | |
|
74 | 69 | if request.method=='GET': |
|
75 | form = RCLineForm(initial={'rc_configuration':conf.id}) | |
|
70 | if line_type_id: | |
|
71 | line_type = get_object_or_404(RCLineType, pk=line_type_id) | |
|
72 | form = RCLineForm(initial={'rc_configuration':conf_id, 'line_type': line_type_id}, | |
|
73 | extra_fields=json.loads(line_type.params)) | |
|
74 | else: | |
|
75 | form = RCLineForm(initial={'rc_configuration':conf_id}) | |
|
76 | 76 | |
|
77 | 77 | if request.method=='POST': |
|
78 | form = RCLineForm(request.POST) | |
|
78 | line_type = get_object_or_404(RCLineType, pk=line_type_id) | |
|
79 | form = RCLineForm(request.POST, extra_fields=json.loads(line_type.params)) | |
|
79 | 80 | |
|
80 | 81 | if form.is_valid(): |
|
81 | 82 | form.save() |
|
82 |
return redirect( |
|
|
83 | return redirect(conf.get_absolute_url()) | |
|
83 | 84 | |
|
84 | 85 | kwargs = {} |
|
85 | 86 | kwargs['form'] = form |
|
86 | 87 | kwargs['title'] = 'RC Configuration' |
|
87 | 88 | kwargs['suptitle'] = 'Add Line' |
|
88 | 89 | kwargs['button'] = 'Add' |
|
89 | 90 | kwargs['previous'] = conf.get_absolute_url() |
|
91 | kwargs['dev_conf'] = conf | |
|
92 | ||
|
93 | kwargs.update(sidebar(conf)) | |
|
94 | ||
|
90 | 95 | return render(request, 'rc_add_line.html', kwargs) |
|
91 | 96 | |
|
92 | 97 | |
|
93 | 98 | def remove_line(request, conf_id, line_id): |
|
94 | 99 | |
|
95 | 100 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
96 | 101 | line = get_object_or_404(RCLine, pk=line_id) |
|
97 | 102 | |
|
98 | 103 | if request.method == 'POST': |
|
99 | 104 | if line: |
|
100 | 105 | try: |
|
101 | 106 | channel = line.channel |
|
102 | 107 | line.delete() |
|
103 | 108 | for ch in range(channel+1, RCLine.objects.filter(rc_configuration=conf).count()+1): |
|
104 | 109 | l = RCLine.objects.get(rc_configuration=conf, channel=ch) |
|
105 | 110 | l.channel = l.channel-1 |
|
106 | 111 | l.save() |
|
107 | 112 | messages.success(request, 'Line: "%s" has been deleted.' % line) |
|
108 | 113 | except: |
|
109 | 114 | messages.error(request, 'Unable to delete line: "%s".' % line) |
|
110 | 115 | |
|
111 | 116 | return redirect(conf.get_absolute_url()) |
|
112 | 117 | |
|
113 | 118 | kwargs = {} |
|
114 | 119 | |
|
115 | 120 | kwargs['object'] = line |
|
116 | 121 | kwargs['delete_view'] = True |
|
117 | 122 | kwargs['title'] = 'Confirm delete' |
|
118 | 123 | kwargs['previous'] = conf.get_absolute_url() |
|
119 | 124 | return render(request, 'confirm.html', kwargs) |
|
120 | 125 | |
|
121 | 126 | |
|
122 |
def |
|
|
127 | def edit_lines(request, conf_id): | |
|
123 | 128 | |
|
124 | 129 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
125 | line = get_object_or_404(RCLine, pk=line_id) | |
|
126 | 130 | |
|
127 | if line: | |
|
128 | ch = line.channel | |
|
129 | if ch-1>=0: | |
|
130 | line0 = RCLine.objects.get(rc_configuration=conf, channel=ch-1) | |
|
131 | line0.channel = ch | |
|
132 | line0.save() | |
|
133 | line.channel = ch-1 | |
|
134 | line.save() | |
|
131 | if request.method=='GET': | |
|
132 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
|
133 | for line in lines: | |
|
134 | line_type = get_object_or_404(RCLineType, pk=line.line_type.id) | |
|
135 | extra_fields = json.loads(line_type.params) | |
|
136 | for item in extra_fields: | |
|
137 | params = json.loads(line.params) | |
|
138 | item['value'] = params[item['name']] | |
|
139 | line.form = RCLineEditForm(initial={'rc_configuration':conf_id, 'line_type': line.line_type.id, 'line': line.id}, | |
|
140 | extra_fields=extra_fields) | |
|
141 | ||
|
142 | elif request.method=='POST': | |
|
143 | data = {} | |
|
144 | for label,value in request.POST.items(): | |
|
145 | if '|' not in label: | |
|
146 | continue | |
|
147 | id, name = label.split('|') | |
|
148 | if id in data: | |
|
149 | data[id][name]=value | |
|
150 | else: | |
|
151 | data[id] = {name:value} | |
|
152 | ||
|
153 | for id, params in data.items(): | |
|
154 | line = RCLine.objects.get(pk=id) | |
|
155 | line.params = json.dumps(params) | |
|
156 | line.save() | |
|
157 | ||
|
158 | return redirect(conf.get_absolute_url()) | |
|
135 | 159 | |
|
136 | return redirect(conf.get_absolute_url()) | |
|
160 | kwargs = {} | |
|
161 | kwargs['dev_conf'] = conf | |
|
162 | kwargs['rc_lines'] = lines | |
|
163 | kwargs['edit'] = True | |
|
164 | ||
|
165 | kwargs['title'] = 'RC Configuration' | |
|
166 | kwargs['suptitle'] = 'Edit Lines' | |
|
167 | kwargs['button'] = 'Update' | |
|
168 | kwargs['previous'] = conf.get_absolute_url() | |
|
137 | 169 | |
|
170 | ||
|
171 | kwargs.update(sidebar(conf)) | |
|
172 | ||
|
173 | return render(request, 'rc_edit_lines.html', kwargs) | |
|
174 | ||
|
138 | 175 | |
|
139 |
def |
|
|
176 | def update_lines(request, conf_id): | |
|
140 | 177 | |
|
141 | 178 | conf = get_object_or_404(RCConfiguration, pk=conf_id) |
|
142 | line = get_object_or_404(RCLine, pk=line_id) | |
|
143 | ||
|
144 | if line: | |
|
145 | ch = line.channel | |
|
146 | if ch+1<RCLine.objects.filter(rc_configuration=conf).count(): | |
|
147 | line1 = RCLine.objects.get(rc_configuration=conf, channel=ch+1) | |
|
148 | line1.channel = ch | |
|
149 | line1.save() | |
|
150 | line.channel = ch+1 | |
|
179 | ||
|
180 | if request.method=='POST': | |
|
181 | ch = 0 | |
|
182 | for item in request.POST['items'].split('&'): | |
|
183 | line = RCLine.objects.get(pk=item.split('=')[-1]) | |
|
184 | line.channel = ch | |
|
151 | 185 | line.save() |
|
152 | ||
|
186 | ch += 1 | |
|
187 | ||
|
188 | lines = RCLine.objects.filter(rc_configuration=conf).order_by('channel') | |
|
189 | ||
|
190 | for line in lines: | |
|
191 | line.form = RCLineViewForm(extra_fields=json.loads(line.params)) | |
|
192 | ||
|
193 | html = render(request, 'rc_lines.html', {'rc_lines':lines}) | |
|
194 | data = {'html': html.content} | |
|
195 | ||
|
196 | return HttpResponse(json.dumps(data), content_type="application/json") | |
|
153 | 197 | return redirect(conf.get_absolute_url()) |
|
198 | ||
|
199 | ||
|
154 | 200 |
General Comments 0
You need to be logged in to leave comments.
Login now