@@ -1,390 +1,443 | |||
|
1 | ||
|
1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse | |
|
2 | 2 | from datetime import datetime |
|
3 | 3 | |
|
4 | 4 | from django.db import models |
|
5 | 5 | from polymorphic import PolymorphicModel |
|
6 | 6 | |
|
7 | 7 | from django.core.urlresolvers import reverse |
|
8 | 8 | |
|
9 | 9 | CONF_STATES = ( |
|
10 | 10 | (0, 'Disconnected'), |
|
11 | 11 | (1, 'Connected'), |
|
12 | 12 | (2, 'Running'), |
|
13 | 13 | ) |
|
14 | 14 | |
|
15 | 15 | EXP_STATES = ( |
|
16 | 16 | (0,'Error'), #RED |
|
17 | 17 | (1,'Configurated'), #BLUE |
|
18 | 18 | (2,'Running'), #GREEN |
|
19 | 19 | (3,'Waiting'), #YELLOW |
|
20 | 20 | (4,'Not Configured'), #WHITE |
|
21 | 21 | ) |
|
22 | 22 | |
|
23 | 23 | CONF_TYPES = ( |
|
24 | 24 | (0, 'Active'), |
|
25 | 25 | (1, 'Historical'), |
|
26 | 26 | ) |
|
27 | 27 | |
|
28 | 28 | DEV_STATES = ( |
|
29 | 29 | (0, 'No connected'), |
|
30 | 30 | (1, 'Connected'), |
|
31 | 31 | (2, 'Configured'), |
|
32 | 32 | (3, 'Running'), |
|
33 | 33 | ) |
|
34 | 34 | |
|
35 | 35 | DEV_TYPES = ( |
|
36 | 36 | ('', 'Select a device type'), |
|
37 | 37 | ('rc', 'Radar Controller'), |
|
38 | 38 | ('dds', 'Direct Digital Synthesizer'), |
|
39 | 39 | ('jars', 'Jicamarca Radar Acquisition System'), |
|
40 | 40 | ('usrp', 'Universal Software Radio Peripheral'), |
|
41 | 41 | ('cgs', 'Clock Generator System'), |
|
42 | 42 | ('abs', 'Automatic Beam Switching'), |
|
43 | 43 | ) |
|
44 | 44 | |
|
45 | 45 | DEV_PORTS = { |
|
46 | 46 | 'rc' : 2000, |
|
47 | 47 | 'dds' : 2000, |
|
48 | 48 | 'jars' : 2000, |
|
49 | 49 | 'usrp' : 2000, |
|
50 | 50 | 'cgs' : 8080, |
|
51 | 51 | 'abs' : 8080 |
|
52 | 52 | } |
|
53 | 53 | |
|
54 | 54 | RADAR_STATES = ( |
|
55 | 55 | (0, 'No connected'), |
|
56 | 56 | (1, 'Connected'), |
|
57 | 57 | (2, 'Configured'), |
|
58 | 58 | (3, 'Running'), |
|
59 | 59 | (4, 'Scheduled'), |
|
60 | 60 | ) |
|
61 | 61 | # Create your models here. |
|
62 | 62 | |
|
63 | 63 | class Location(models.Model): |
|
64 | 64 | |
|
65 | 65 | name = models.CharField(max_length = 30) |
|
66 | 66 | description = models.TextField(blank=True, null=True) |
|
67 | 67 | |
|
68 | 68 | class Meta: |
|
69 | 69 | db_table = 'db_location' |
|
70 | 70 | |
|
71 | 71 | def __unicode__(self): |
|
72 | 72 | return u'%s' % self.name |
|
73 | 73 | |
|
74 | 74 | def get_absolute_url(self): |
|
75 | 75 | return reverse('url_device', args=[str(self.id)]) |
|
76 | 76 | |
|
77 | 77 | |
|
78 | 78 | class DeviceType(models.Model): |
|
79 | 79 | |
|
80 | 80 | name = models.CharField(max_length = 10, choices = DEV_TYPES, default = 'rc') |
|
81 | 81 | description = models.TextField(blank=True, null=True) |
|
82 | 82 | |
|
83 | 83 | class Meta: |
|
84 | 84 | db_table = 'db_device_types' |
|
85 | 85 | |
|
86 | 86 | def __unicode__(self): |
|
87 | 87 | return u'%s' % self.get_name_display() |
|
88 | 88 | |
|
89 | 89 | class Device(models.Model): |
|
90 | 90 | |
|
91 | 91 | device_type = models.ForeignKey(DeviceType, on_delete=models.CASCADE) |
|
92 | 92 | location = models.ForeignKey(Location, on_delete=models.CASCADE) |
|
93 | 93 | |
|
94 | 94 | name = models.CharField(max_length=40, default='') |
|
95 | 95 | ip_address = models.GenericIPAddressField(protocol='IPv4', default='0.0.0.0') |
|
96 | 96 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
97 | 97 | description = models.TextField(blank=True, null=True) |
|
98 | 98 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
99 | 99 | |
|
100 | 100 | class Meta: |
|
101 | 101 | db_table = 'db_devices' |
|
102 | 102 | |
|
103 | 103 | def __unicode__(self): |
|
104 | 104 | return u'%s | %s' % (self.name, self.ip_address) |
|
105 | 105 | |
|
106 | 106 | def get_status(self): |
|
107 | 107 | return self.status |
|
108 | 108 | |
|
109 | 109 | def get_absolute_url(self): |
|
110 | 110 | return reverse('url_device', args=[str(self.id)]) |
|
111 | 111 | |
|
112 | 112 | |
|
113 | 113 | class Campaign(models.Model): |
|
114 | 114 | |
|
115 | 115 | template = models.BooleanField(default=False) |
|
116 | 116 | name = models.CharField(max_length=60, unique=True) |
|
117 | 117 | start_date = models.DateTimeField(blank=True, null=True) |
|
118 | 118 | end_date = models.DateTimeField(blank=True, null=True) |
|
119 | 119 | tags = models.CharField(max_length=40) |
|
120 | 120 | description = models.TextField(blank=True, null=True) |
|
121 | 121 | experiments = models.ManyToManyField('Experiment', blank=True) |
|
122 | 122 | |
|
123 | 123 | class Meta: |
|
124 | 124 | db_table = 'db_campaigns' |
|
125 | 125 | ordering = ('name',) |
|
126 | 126 | |
|
127 | 127 | def __unicode__(self): |
|
128 | 128 | return u'%s' % (self.name) |
|
129 | 129 | |
|
130 | 130 | def get_absolute_url(self): |
|
131 | 131 | return reverse('url_campaign', args=[str(self.id)]) |
|
132 | 132 | |
|
133 | def parms_to_dict(self): | |
|
134 | ||
|
135 | import json | |
|
136 | ||
|
137 | parameters = {} | |
|
138 | experiments = Experiment.objects.filter(campaign = campaign) | |
|
139 | ||
|
140 | ||
|
141 | parameters['campaign'] = self.name | |
|
142 | ||
|
143 | #parameters = json.dumps(parameters, indent=2) | |
|
144 | parameters = json.dumps(parameters) | |
|
145 | return parameters | |
|
146 | ||
|
147 | def get_absolute_url_export(self): | |
|
148 | return reverse('url_export_campaign', args=[str(self.id)]) | |
|
149 | ||
|
150 | ||
|
133 | 151 | |
|
134 | 152 | class RunningExperiment(models.Model): |
|
135 | 153 | radar = models.OneToOneField('Location', on_delete=models.CASCADE) |
|
136 | 154 | running_experiment = models.ManyToManyField('Experiment', blank = True) |
|
137 | 155 | status = models.PositiveSmallIntegerField(default=0, choices=RADAR_STATES) |
|
138 | 156 | |
|
139 | 157 | |
|
140 | 158 | class Experiment(models.Model): |
|
141 | 159 | |
|
142 | 160 | template = models.BooleanField(default=False) |
|
143 | 161 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
144 | 162 | name = models.CharField(max_length=40, default='', unique=True) |
|
145 | 163 | location = models.ForeignKey('Location', null=True, blank=True, on_delete=models.CASCADE) |
|
146 | 164 | start_time = models.TimeField(default='00:00:00') |
|
147 | 165 | end_time = models.TimeField(default='23:59:59') |
|
148 | 166 | status = models.PositiveSmallIntegerField(default=0, choices=EXP_STATES) |
|
149 | 167 | |
|
150 | 168 | class Meta: |
|
151 | 169 | db_table = 'db_experiments' |
|
152 | 170 | ordering = ('template', 'name') |
|
153 | 171 | |
|
154 | 172 | def __unicode__(self): |
|
155 | 173 | if self.template: |
|
156 | 174 | return u'%s (template)' % (self.name) |
|
157 | 175 | else: |
|
158 | 176 | return u'%s' % (self.name) |
|
159 | 177 | |
|
160 | 178 | @property |
|
161 | 179 | def radar(self): |
|
162 | 180 | return self.location |
|
163 | 181 | |
|
164 | 182 | def clone(self, **kwargs): |
|
165 | 183 | |
|
166 | 184 | confs = Configuration.objects.filter(experiment=self, type=0) |
|
167 | 185 | self.pk = None |
|
168 | 186 | self.name = '{} [{:%Y/%m/%d}]'.format(self.name, datetime.now()) |
|
169 | 187 | for attr, value in kwargs.items(): |
|
170 | 188 | setattr(self, attr, value) |
|
171 | 189 | |
|
172 | 190 | self.save() |
|
173 | 191 | |
|
174 | 192 | for conf in confs: |
|
175 | 193 | conf.clone(experiment=self, template=False) |
|
176 | 194 | |
|
177 | 195 | return self |
|
178 | 196 | |
|
179 | 197 | def get_status(self): |
|
180 | 198 | configurations = Configuration.objects.filter(experiment=self) |
|
181 | 199 | exp_status=[] |
|
182 | 200 | for conf in configurations: |
|
183 | 201 | print conf.status_device() |
|
184 | 202 | exp_status.append(conf.status_device()) |
|
185 | 203 | |
|
186 | 204 | if not exp_status: #No Configuration |
|
187 | 205 | self.status = 4 |
|
188 | 206 | self.save() |
|
189 | 207 | return |
|
190 | 208 | |
|
191 | 209 | total = 1 |
|
192 | 210 | for e_s in exp_status: |
|
193 | 211 | total = total*e_s |
|
194 | 212 | |
|
195 | 213 | if total == 0: #Error |
|
196 | 214 | status = 0 |
|
197 | 215 | elif total == (3**len(exp_status)): #Running |
|
198 | 216 | status = 2 |
|
199 | 217 | else: |
|
200 | 218 | status = 1 #Configurated |
|
201 | 219 | |
|
202 | 220 | self.status = status |
|
203 | 221 | self.save() |
|
204 | 222 | |
|
205 | 223 | def status_color(self): |
|
206 | 224 | color = 'danger' |
|
207 | 225 | if self.status == 0: |
|
208 | 226 | color = "danger" |
|
209 | 227 | elif self.status == 1: |
|
210 | 228 | color = "info" |
|
211 | 229 | elif self.status == 2: |
|
212 | 230 | color = "success" |
|
213 | 231 | elif self.status == 3: |
|
214 | 232 | color = "warning" |
|
215 | 233 | else: |
|
216 | 234 | color = "muted" |
|
217 | 235 | |
|
218 | 236 | return color |
|
219 | 237 | |
|
220 | 238 | def get_absolute_url(self): |
|
221 | 239 | return reverse('url_experiment', args=[str(self.id)]) |
|
222 | 240 | |
|
241 | def parms_to_dict(self): | |
|
242 | ||
|
243 | import json | |
|
244 | ||
|
245 | configurations = Configuration.objects.filter(experiment=self) | |
|
246 | conf_parameters = {} | |
|
247 | parameters={} | |
|
248 | ||
|
249 | for configuration in configurations: | |
|
250 | if 'cgs' in configuration.device.device_type.name: | |
|
251 | conf_parameters['cgs'] = configuration.parms_to_dict() | |
|
252 | if 'dds' in configuration.device.device_type.name: | |
|
253 | conf_parameters['dds'] = configuration.parms_to_dict() | |
|
254 | if 'rc' in configuration.device.device_type.name: | |
|
255 | conf_parameters['rc'] = configuration.parms_to_dict() | |
|
256 | if 'jars' in configuration.device.device_type.name: | |
|
257 | conf_parameters['jars'] = configuration.parms_to_dict() | |
|
258 | if 'usrp' in configuration.device.device_type.name: | |
|
259 | conf_parameters['usrp'] = configuration.parms_to_dict() | |
|
260 | if 'abs' in configuration.device.device_type.name: | |
|
261 | conf_parameters['abs'] = configuration.parms_to_dict() | |
|
262 | ||
|
263 | parameters['configurations'] = conf_parameters | |
|
264 | parameters['end_time'] = self.end_time.strftime("%Y-%m-%d") | |
|
265 | parameters['start_time'] = self.start_time.strftime("%Y-%m-%d") | |
|
266 | parameters['radar'] = self.radar.name | |
|
267 | parameters['experiment'] = self.name | |
|
268 | parameters = json.dumps(parameters, indent=2) | |
|
269 | #parameters = json.dumps(parameters) | |
|
270 | ||
|
271 | return parameters | |
|
272 | ||
|
273 | def get_absolute_url_export(self): | |
|
274 | return reverse('url_export_experiment', args=[str(self.id)]) | |
|
275 | ||
|
223 | 276 | |
|
224 | 277 | class Configuration(PolymorphicModel): |
|
225 | 278 | |
|
226 | 279 | template = models.BooleanField(default=False) |
|
227 | 280 | |
|
228 | 281 | name = models.CharField(verbose_name="Configuration Name", max_length=40, default='') |
|
229 | 282 | |
|
230 | 283 | experiment = models.ForeignKey('Experiment', null=True, blank=True, on_delete=models.CASCADE) |
|
231 | 284 | device = models.ForeignKey(Device, on_delete=models.CASCADE) |
|
232 | 285 | |
|
233 | 286 | type = models.PositiveSmallIntegerField(default=0, choices=CONF_TYPES) |
|
234 | 287 | |
|
235 | 288 | created_date = models.DateTimeField(auto_now_add=True) |
|
236 | 289 | programmed_date = models.DateTimeField(auto_now=True) |
|
237 | 290 | |
|
238 | 291 | parameters = models.TextField(default='{}') |
|
239 | 292 | |
|
240 | 293 | message = "" |
|
241 | 294 | |
|
242 | 295 | class Meta: |
|
243 | 296 | db_table = 'db_configurations' |
|
244 | 297 | |
|
245 | 298 | def __unicode__(self): |
|
246 | 299 | |
|
247 | 300 | if self.experiment: |
|
248 | 301 | return u'[%s, %s]: %s' % (self.experiment.name, |
|
249 | 302 | self.device.name, |
|
250 | 303 | self.name) |
|
251 | 304 | else: |
|
252 | 305 | return u'%s' % self.device.name |
|
253 | 306 | |
|
254 | 307 | def clone(self, **kwargs): |
|
255 | 308 | |
|
256 | 309 | self.pk = None |
|
257 | 310 | self.id = None |
|
258 | 311 | for attr, value in kwargs.items(): |
|
259 | 312 | setattr(self, attr, value) |
|
260 | 313 | |
|
261 | 314 | self.save() |
|
262 | 315 | |
|
263 | 316 | return self |
|
264 | 317 | |
|
265 | 318 | def parms_to_dict(self): |
|
266 | 319 | |
|
267 | 320 | parameters = {} |
|
268 | 321 | |
|
269 | 322 | for key in self.__dict__.keys(): |
|
270 | 323 | parameters[key] = getattr(self, key) |
|
271 | 324 | |
|
272 | 325 | return parameters |
|
273 | 326 | |
|
274 | 327 | def parms_to_text(self): |
|
275 | 328 | |
|
276 | 329 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
277 | 330 | |
|
278 | 331 | return '' |
|
279 | 332 | |
|
280 | 333 | def parms_to_binary(self): |
|
281 | 334 | |
|
282 | 335 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
283 | 336 | |
|
284 | 337 | return '' |
|
285 | 338 | |
|
286 | 339 | def dict_to_parms(self, parameters): |
|
287 | 340 | |
|
288 | 341 | if type(parameters) != type({}): |
|
289 | 342 | return |
|
290 | 343 | |
|
291 | 344 | for key in parameters.keys(): |
|
292 | 345 | setattr(self, key, parameters[key]) |
|
293 | 346 | |
|
294 | 347 | def export_to_file(self, format="json"): |
|
295 | 348 | |
|
296 | 349 | import json |
|
297 | 350 | |
|
298 | 351 | content_type = '' |
|
299 | 352 | |
|
300 | 353 | if format == 'text': |
|
301 | 354 | content_type = 'text/plain' |
|
302 | 355 | filename = '%s_%s.%s' %(self.device.device_type.name, self.name, self.device.device_type.name) |
|
303 | 356 | content = self.parms_to_text() |
|
304 | 357 | |
|
305 | 358 | if format == 'binary': |
|
306 | 359 | content_type = 'application/octet-stream' |
|
307 | 360 | filename = '%s_%s.bin' %(self.device.device_type.name, self.name) |
|
308 | 361 | content = self.parms_to_binary() |
|
309 | 362 | |
|
310 | 363 | if not content_type: |
|
311 | 364 | content_type = 'application/json' |
|
312 | 365 | filename = '%s_%s.json' %(self.device.device_type.name, self.name) |
|
313 | 366 | content = json.dumps(self.parms_to_dict(), indent=2) |
|
314 | 367 | |
|
315 | 368 | fields = {'content_type':content_type, |
|
316 | 369 | 'filename':filename, |
|
317 | 370 | 'content':content |
|
318 | 371 | } |
|
319 | 372 | |
|
320 | 373 | return fields |
|
321 | 374 | |
|
322 | 375 | def import_from_file(self, fp): |
|
323 | 376 | |
|
324 | 377 | import os, json |
|
325 | 378 | |
|
326 | 379 | parms = {} |
|
327 | 380 | |
|
328 | 381 | path, ext = os.path.splitext(fp.name) |
|
329 | 382 | |
|
330 | 383 | if ext == '.json': |
|
331 | 384 | parms = json.load(fp) |
|
332 | 385 | |
|
333 | 386 | return parms |
|
334 | 387 | |
|
335 | 388 | def status_device(self): |
|
336 | 389 | |
|
337 | 390 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
338 | 391 | |
|
339 | 392 | return None |
|
340 | 393 | |
|
341 | 394 | def stop_device(self): |
|
342 | 395 | |
|
343 | 396 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
344 | 397 | |
|
345 | 398 | return None |
|
346 | 399 | |
|
347 | 400 | def start_device(self): |
|
348 | 401 | |
|
349 | 402 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
350 | 403 | |
|
351 | 404 | return None |
|
352 | 405 | |
|
353 | 406 | def write_device(self, parms): |
|
354 | 407 | |
|
355 | 408 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
356 | 409 | |
|
357 | 410 | return None |
|
358 | 411 | |
|
359 | 412 | def read_device(self): |
|
360 | 413 | |
|
361 | 414 | raise NotImplementedError, "This method should be implemented in %s Configuration model" %str(self.device.device_type.name).upper() |
|
362 | 415 | |
|
363 | 416 | return None |
|
364 | 417 | |
|
365 | 418 | def get_absolute_url(self): |
|
366 | 419 | return reverse('url_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
367 | 420 | |
|
368 | 421 | def get_absolute_url_edit(self): |
|
369 | 422 | return reverse('url_edit_%s_conf' % self.device.device_type.name, args=[str(self.id)]) |
|
370 | 423 | |
|
371 | 424 | def get_absolute_url_import(self): |
|
372 | 425 | return reverse('url_import_dev_conf', args=[str(self.id)]) |
|
373 | 426 | |
|
374 | 427 | def get_absolute_url_export(self): |
|
375 | 428 | return reverse('url_export_dev_conf', args=[str(self.id)]) |
|
376 | 429 | |
|
377 | 430 | def get_absolute_url_write(self): |
|
378 | 431 | return reverse('url_write_dev_conf', args=[str(self.id)]) |
|
379 | 432 | |
|
380 | 433 | def get_absolute_url_read(self): |
|
381 | 434 | return reverse('url_read_dev_conf', args=[str(self.id)]) |
|
382 | 435 | |
|
383 | 436 | def get_absolute_url_start(self): |
|
384 | 437 | return reverse('url_start_dev_conf', args=[str(self.id)]) |
|
385 | 438 | |
|
386 | 439 | def get_absolute_url_stop(self): |
|
387 | 440 | return reverse('url_stop_dev_conf', args=[str(self.id)]) |
|
388 | 441 | |
|
389 | 442 | def get_absolute_url_status(self): |
|
390 | 443 | return reverse('url_status_dev_conf', args=[str(self.id)]) No newline at end of file |
@@ -1,84 +1,108 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block camp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | ||
|
16 | {% block menu-actions %} | |
|
17 | <span class=" dropdown pull-right"> | |
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
|
19 | <ul class="dropdown-menu" role="menu"> | |
|
20 | <li><a href="{% url 'url_edit_campaign' campaign.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
|
21 | <li><a href="{% url 'url_delete_campaign' campaign.id %}"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Delete</a></li> | |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
|
23 | <li><a href="{{ campaign.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
|
24 | {% block extra-menu-actions %} | |
|
25 | {% endblock %} | |
|
26 | <li><a>----------------</a></li> | |
|
27 | <li><a href="#"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Mix Experiments</a></li> | |
|
28 | <!--<li><a href="{{ dev_conf.get_absolute_url_status }}"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Status</a></li> | |
|
29 | {% if not no_play %} | |
|
30 | <li><a href="{{ dev_conf.get_absolute_url_start}}"><span class="glyphicon glyphicon-play" aria-hidden="true"></span> Start</a></li> | |
|
31 | <li><a href="{{ dev_conf.get_absolute_url_stop }}"><span class="glyphicon glyphicon-stop" aria-hidden="true"></span> Stop</a></li> | |
|
32 | {% endif %} | |
|
33 | <li><a href="{{ dev_conf.get_absolute_url_write }}"><span class="glyphicon glyphicon-download" aria-hidden="true"></span> Write</a></li> | |
|
34 | <li><a href="{{ dev_conf.get_absolute_url_read }}"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Read</a></li>--> | |
|
35 | </ul> | |
|
36 | </span> | |
|
37 | {% endblock %} | |
|
38 | ||
|
15 | 39 | <table class="table table-bordered"> |
|
16 | 40 | {% for key in campaign_keys %} |
|
17 | 41 | <tr><th>{{key|title}}</th><td>{{campaign|attr:key}}</td></tr> |
|
18 | 42 | {% endfor %} |
|
19 | 43 | </table> |
|
20 | 44 | |
|
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> | |
|
22 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
|
45 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button>--> | |
|
46 | <!--<button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button>--> | |
|
23 | 47 | |
|
24 | 48 | <br></br> |
|
25 | 49 | <br></br> |
|
26 | 50 | |
|
27 | 51 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
28 | 52 | |
|
29 | 53 | <div class="panel panel-default"> |
|
30 | 54 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
31 | 55 | <h4 class="panel-title"> |
|
32 | 56 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> |
|
33 | 57 | Experiment List |
|
34 | 58 | </a> |
|
35 | 59 | </h4> |
|
36 | 60 | </div> |
|
37 | 61 | |
|
38 | 62 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
39 | 63 | <div class="panel-body"> |
|
40 | 64 | <table class="table table-hover"> |
|
41 | 65 | <tr> |
|
42 | 66 | <th>#</th> |
|
43 | 67 | {% for header in experiment_keys %} |
|
44 | 68 | <th>{{ header|title }}</th> |
|
45 | 69 | {% endfor%} |
|
46 | 70 | </tr> |
|
47 | 71 | {% for item in experiments %} |
|
48 | 72 | <tr class="clickable-row" data-href="{% url 'url_experiment' item.id %}"> |
|
49 | 73 | <td>{{ forloop.counter }}</td> |
|
50 | 74 | {% for key in experiment_keys %} |
|
51 | 75 | <td>{{ item|attr:key }}</td> |
|
52 | 76 | {% endfor %} |
|
53 | 77 | </tr> |
|
54 | 78 | {% endfor %} |
|
55 | 79 | </table> |
|
56 | 80 | </div> |
|
57 | 81 | </div> |
|
58 | 82 | </div> |
|
59 | 83 | </div> |
|
60 | 84 | <br> |
|
61 | 85 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_mix">Mix Experiments</button> |
|
62 | 86 | {% endblock %} |
|
63 | 87 | |
|
64 | 88 | {% block sidebar%} |
|
65 | 89 | {% include "sidebar_devices.html" %} |
|
66 | 90 | {% endblock %} |
|
67 | 91 | |
|
68 | 92 | {% block extra-js%} |
|
69 | 93 | <script type="text/javascript"> |
|
70 | 94 | |
|
71 | 95 | $(".clickable-row").click(function() { |
|
72 | 96 | document.location = $(this).data("href"); |
|
73 | 97 | }); |
|
74 | 98 | |
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
99 | // $("#bt_edit").click(function() { | |
|
100 | // document.location = "{% url 'url_edit_campaign' campaign.id %}"; | |
|
101 | // }); | |
|
78 | 102 | |
|
79 | 103 | $("#bt_mix").click(function() { |
|
80 | document.location = "{% url 'url_mix_campaign' campaign.id %}"; | |
|
104 | ||
|
81 | 105 | }); |
|
82 | 106 | |
|
83 | 107 | </script> |
|
84 | 108 | {% endblock %} No newline at end of file |
@@ -1,80 +1,95 | |||
|
1 | 1 | {% extends "base.html" %} |
|
2 | 2 | {% load bootstrap3 %} |
|
3 | 3 | {% load static %} |
|
4 | 4 | {% load main_tags %} |
|
5 | 5 | {% block extra-head %} |
|
6 | 6 | <link href="{% static 'css/bootstrap-datetimepicker.min.css' %}" media="screen" rel="stylesheet"> |
|
7 | 7 | {% endblock %} |
|
8 | 8 | |
|
9 | 9 | {% block exp-active %}active{% endblock %} |
|
10 | 10 | |
|
11 | 11 | {% block content-title %}{{title}}{% endblock %} |
|
12 | 12 | {% block content-suptitle %}{{suptitle}}{% endblock %} |
|
13 | 13 | |
|
14 | 14 | {% block content %} |
|
15 | ||
|
16 | {% block menu-actions %} | |
|
17 | <span class=" dropdown pull-right"> | |
|
18 | <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger gi-2x" aria-hidden="true"></span></a> | |
|
19 | <ul class="dropdown-menu" role="menu"> | |
|
20 | <li><a href="{% url 'url_edit_experiment' experiment.id %}"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit</a></li> | |
|
21 | <li><a href="{% url 'url_delete_experiment' experiment.id %}"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span> Delete</a></li> | |
|
22 | <li><a href="{{ dev_conf.get_absolute_url_import }}"><span class="glyphicon glyphicon-import" aria-hidden="true"></span> Import </a></li> | |
|
23 | <li><a href="{{ experiment.get_absolute_url_export }}"><span class="glyphicon glyphicon-export" aria-hidden="true"></span> Export </a></li> | |
|
24 | {% block extra-menu-actions %} | |
|
25 | {% endblock %} | |
|
26 | <li><a>----------------</a></li> | |
|
27 | <li><a href="#"><span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> Add Configuration</a></li> | |
|
28 | </ul> | |
|
29 | </span> | |
|
30 | {% endblock %} | |
|
31 | ||
|
15 | 32 | <table class="table table-bordered"> |
|
16 | 33 | {% for key in experiment_keys %} |
|
17 | 34 | <tr><th>{{key|title}}</th><td>{{experiment|attr:key}}</td></tr> |
|
18 | 35 | {% endfor %} |
|
19 | 36 | </table> |
|
20 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_export">Export</button> | |
|
21 | <button class="btn btn-primary pull-right" style="margin-left: 10px" id="bt_edit">Edit</button> | |
|
22 | 37 | <br></br> |
|
23 | 38 | <br></br> |
|
24 | 39 | |
|
25 | 40 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
|
26 | 41 | |
|
27 | 42 | <div class="panel panel-default"> |
|
28 | 43 | <div class="panel-heading" role="tab" id="headingTwo"> |
|
29 | 44 | <h4 class="panel-title"> |
|
30 | 45 | <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseThree"> |
|
31 | 46 | Device Configurations |
|
32 | 47 | </a> |
|
33 | 48 | </h4> |
|
34 | 49 | </div> |
|
35 | 50 | <div id="collapseTwo" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingTwo"> |
|
36 | 51 | <div class="panel-body"> |
|
37 | 52 | <table class="table table-hover"> |
|
38 | 53 | <tr> |
|
39 | 54 | <th>#</th> |
|
40 | 55 | {% for key in configuration_keys %} |
|
41 | 56 | <th>{{ key|title }}</th> |
|
42 | 57 | {% endfor%} |
|
43 | 58 | </tr> |
|
44 | 59 | {% for item in configurations %} |
|
45 | 60 | <tr class="clickable-row" data-href="{{item.get_absolute_url}}"> |
|
46 | 61 | <td>{{ forloop.counter }}</td> |
|
47 | 62 | {% for key in configuration_keys %} |
|
48 | 63 | <td>{{ item|value:key }}</td> |
|
49 | 64 | {% endfor %} |
|
50 | 65 | </tr> |
|
51 | 66 | {% endfor %} |
|
52 | 67 | </table> |
|
53 | 68 | <button class="btn btn-primary pull-right" id="bt_add_conf">{{button}}</button> |
|
54 | 69 | </div> |
|
55 | 70 | </div> |
|
56 | 71 | </div> |
|
57 | 72 | </div> |
|
58 | 73 | {% endblock %} |
|
59 | 74 | |
|
60 | 75 | {% block sidebar%} |
|
61 | 76 | {% include "sidebar_devices.html" %} |
|
62 | 77 | {% endblock %} |
|
63 | 78 | |
|
64 | 79 | {% block extra-js%} |
|
65 | 80 | <script type="text/javascript"> |
|
66 | 81 | |
|
67 | 82 | $(".clickable-row").click(function() { |
|
68 | 83 | document.location = $(this).data("href"); |
|
69 | 84 | }); |
|
70 | 85 | |
|
71 | 86 | $("#bt_edit").click(function() { |
|
72 | 87 | document.location = "{% url 'url_edit_experiment' experiment.id%}"; |
|
73 | 88 | }); |
|
74 | 89 | |
|
75 | 90 | $("#bt_add_conf").click(function() { |
|
76 | 91 | document.location = "{% url 'url_add_dev_conf' experiment.id %}"; |
|
77 | 92 | }); |
|
78 | 93 | |
|
79 | 94 | </script> |
|
80 | 95 | {% endblock %} No newline at end of file |
@@ -1,51 +1,53 | |||
|
1 | 1 | from django.conf.urls import url |
|
2 | 2 | |
|
3 | 3 | urlpatterns = ( |
|
4 | 4 | url(r'^location/new/$', 'apps.main.views.location_new', name='url_add_location'), |
|
5 | 5 | url(r'^location/$', 'apps.main.views.locations', name='url_locations'), |
|
6 | 6 | url(r'^location/(?P<id_loc>-?\d+)/$', 'apps.main.views.location', name='url_location'), |
|
7 | 7 | url(r'^location/(?P<id_loc>-?\d+)/edit/$', 'apps.main.views.location_edit', name='url_edit_location'), |
|
8 | 8 | url(r'^location/(?P<id_loc>-?\d+)/delete/$', 'apps.main.views.location_delete', name='url_delete_location'), |
|
9 | 9 | |
|
10 | 10 | url(r'^device/new/$', 'apps.main.views.device_new', name='url_add_device'), |
|
11 | 11 | url(r'^device/$', 'apps.main.views.devices', name='url_devices'), |
|
12 | 12 | url(r'^device/(?P<id_dev>-?\d+)/$', 'apps.main.views.device', name='url_device'), |
|
13 | 13 | url(r'^device/(?P<id_dev>-?\d+)/edit/$', 'apps.main.views.device_edit', name='url_edit_device'), |
|
14 | 14 | url(r'^device/(?P<id_dev>-?\d+)/delete/$', 'apps.main.views.device_delete', name='url_delete_device'), |
|
15 | 15 | |
|
16 | 16 | url(r'^campaign/new/$', 'apps.main.views.campaign_new', name='url_add_campaign'), |
|
17 | 17 | url(r'^campaign/$', 'apps.main.views.campaigns', name='url_campaigns'), |
|
18 | 18 | url(r'^campaign/(?P<id_camp>-?\d+)/$', 'apps.main.views.campaign', name='url_campaign'), |
|
19 | 19 | url(r'^campaign/(?P<id_camp>-?\d+)/edit/$', 'apps.main.views.campaign_edit', name='url_edit_campaign'), |
|
20 | 20 | url(r'^campaign/(?P<id_camp>-?\d+)/delete/$', 'apps.main.views.campaign_delete', name='url_delete_campaign'), |
|
21 | url(r'^campaign/(?P<id_camp>-?\d+)/export/$', 'apps.main.views.campaign_export', name='url_export_campaign'), | |
|
21 | 22 | |
|
22 | 23 | url(r'^experiment/new/$', 'apps.main.views.experiment_new', name='url_add_experiment'), |
|
23 | 24 | url(r'^experiment/$', 'apps.main.views.experiments', name='url_experiments'), |
|
24 | 25 | url(r'^experiment/(?P<id_exp>-?\d+)/$', 'apps.main.views.experiment', name='url_experiment'), |
|
25 | 26 | url(r'^experiment/(?P<id_exp>-?\d+)/edit/$', 'apps.main.views.experiment_edit', name='url_edit_experiment'), |
|
26 | 27 | url(r'^experiment/(?P<id_exp>-?\d+)/delete/$', 'apps.main.views.experiment_delete', name='url_delete_experiment'), |
|
28 | url(r'^experiment/(?P<id_exp>-?\d+)/export/$', 'apps.main.views.experiment_export', name='url_export_experiment'), | |
|
27 | 29 | |
|
28 | 30 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
29 | 31 | url(r'^experiment/(?P<id_exp>-?\d+)/new_dev_conf/(?P<id_dev>-?\d+)/$', 'apps.main.views.dev_conf_new', name='url_add_dev_conf'), |
|
30 | 32 | url(r'^dev_conf/$', 'apps.main.views.dev_confs', name='url_dev_confs'), |
|
31 | 33 | url(r'^dev_conf/(?P<id_conf>-?\d+)/$', 'apps.main.views.dev_conf', name='url_dev_conf'), |
|
32 | 34 | url(r'^dev_conf/(?P<id_conf>-?\d+)/edit/$', 'apps.main.views.dev_conf_edit', name='url_edit_dev_conf'), |
|
33 | 35 | url(r'^dev_conf/(?P<id_conf>-?\d+)/delete/$', 'apps.main.views.dev_conf_delete', name='url_delete_dev_conf'), |
|
34 | 36 | |
|
35 | 37 | url(r'^dev_conf/(?P<id_conf>-?\d+)/write/$', 'apps.main.views.dev_conf_write', name='url_write_dev_conf'), |
|
36 | 38 | url(r'^dev_conf/(?P<id_conf>-?\d+)/read/$', 'apps.main.views.dev_conf_read', name='url_read_dev_conf'), |
|
37 | 39 | url(r'^dev_conf/(?P<id_conf>-?\d+)/import/$', 'apps.main.views.dev_conf_import', name='url_import_dev_conf'), |
|
38 | 40 | url(r'^dev_conf/(?P<id_conf>-?\d+)/export/$', 'apps.main.views.dev_conf_export', name='url_export_dev_conf'), |
|
39 | 41 | url(r'^dev_conf/(?P<id_conf>-?\d+)/start/$', 'apps.main.views.dev_conf_start', name='url_start_dev_conf'), |
|
40 | 42 | url(r'^dev_conf/(?P<id_conf>-?\d+)/stop/$', 'apps.main.views.dev_conf_stop', name='url_stop_dev_conf'), |
|
41 | 43 | url(r'^dev_conf/(?P<id_conf>-?\d+)/status/$', 'apps.main.views.dev_conf_status', name='url_status_dev_conf'), |
|
42 | 44 | |
|
43 | 45 | url(r'^operation/$', 'apps.main.views.operation', name='url_operation'), |
|
44 | 46 | url(r'^operation/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation', name='url_operation'), |
|
45 | 47 | url(r'^operation/search/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
46 | 48 | url(r'^operation/search/(?P<id_camp>-?\d+)/$', 'apps.main.views.operation_search', name='url_operation_search'), |
|
47 | 49 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/play/$', 'apps.main.views.radar_play', name='url_radar_play'), |
|
48 | 50 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/stop/$', 'apps.main.views.radar_stop', name='url_radar_stop'), |
|
49 | 51 | url(r'^operation/(?P<id_camp>-?\d+)/radar/(?P<id_radar>-?\d+)/refresh/$', 'apps.main.views.radar_refresh', name='url_radar_refresh'), |
|
50 | 52 | |
|
51 | 53 | ) |
@@ -1,1099 +1,1125 | |||
|
1 | 1 | from django.shortcuts import render, redirect, get_object_or_404, HttpResponse |
|
2 | 2 | from django.http import HttpResponseRedirect |
|
3 | 3 | from django.core.urlresolvers import reverse |
|
4 | 4 | from django.contrib import messages |
|
5 | 5 | from datetime import datetime |
|
6 | 6 | |
|
7 | 7 | from .forms import CampaignForm, ExperimentForm, DeviceForm, ConfigurationForm, LocationForm, UploadFileForm, DownloadFileForm, OperationForm, NewForm |
|
8 | 8 | from .forms import OperationSearchForm |
|
9 | 9 | from apps.cgs.forms import CGSConfigurationForm |
|
10 | 10 | from apps.jars.forms import JARSConfigurationForm |
|
11 | 11 | from apps.usrp.forms import USRPConfigurationForm |
|
12 | 12 | from apps.abs.forms import ABSConfigurationForm |
|
13 | 13 | from apps.rc.forms import RCConfigurationForm |
|
14 | 14 | from apps.dds.forms import DDSConfigurationForm |
|
15 | 15 | |
|
16 | 16 | from .models import Campaign, Experiment, Device, Configuration, Location, RunningExperiment |
|
17 | 17 | from apps.cgs.models import CGSConfiguration |
|
18 | 18 | from apps.jars.models import JARSConfiguration |
|
19 | 19 | from apps.usrp.models import USRPConfiguration |
|
20 | 20 | from apps.abs.models import ABSConfiguration |
|
21 | 21 | from apps.rc.models import RCConfiguration |
|
22 | 22 | from apps.dds.models import DDSConfiguration |
|
23 | 23 | |
|
24 | 24 | # Create your views here. |
|
25 | 25 | |
|
26 | 26 | CONF_FORMS = { |
|
27 | 27 | 'rc': RCConfigurationForm, |
|
28 | 28 | 'dds': DDSConfigurationForm, |
|
29 | 29 | 'jars': JARSConfigurationForm, |
|
30 | 30 | 'cgs': CGSConfigurationForm, |
|
31 | 31 | 'abs': ABSConfigurationForm, |
|
32 | 32 | 'usrp': USRPConfigurationForm, |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | CONF_MODELS = { |
|
36 | 36 | 'rc': RCConfiguration, |
|
37 | 37 | 'dds': DDSConfiguration, |
|
38 | 38 | 'jars': JARSConfiguration, |
|
39 | 39 | 'cgs': CGSConfiguration, |
|
40 | 40 | 'abs': ABSConfiguration, |
|
41 | 41 | 'usrp': USRPConfiguration, |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | def index(request): |
|
46 | 46 | kwargs = {} |
|
47 | 47 | |
|
48 | 48 | return render(request, 'index.html', kwargs) |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | def locations(request): |
|
52 | 52 | |
|
53 | 53 | locations = Location.objects.all().order_by('name') |
|
54 | 54 | |
|
55 | 55 | keys = ['id', 'name', 'description'] |
|
56 | 56 | |
|
57 | 57 | kwargs = {} |
|
58 | 58 | kwargs['location_keys'] = keys[1:] |
|
59 | 59 | kwargs['locations'] = locations |
|
60 | 60 | kwargs['title'] = 'Location' |
|
61 | 61 | kwargs['suptitle'] = 'List' |
|
62 | 62 | kwargs['button'] = 'New Location' |
|
63 | 63 | |
|
64 | 64 | return render(request, 'locations.html', kwargs) |
|
65 | 65 | |
|
66 | 66 | |
|
67 | 67 | def location(request, id_loc): |
|
68 | 68 | |
|
69 | 69 | location = get_object_or_404(Location, pk=id_loc) |
|
70 | 70 | |
|
71 | 71 | kwargs = {} |
|
72 | 72 | kwargs['location'] = location |
|
73 | 73 | kwargs['location_keys'] = ['name', 'description'] |
|
74 | 74 | |
|
75 | 75 | kwargs['title'] = 'Location' |
|
76 | 76 | kwargs['suptitle'] = 'Details' |
|
77 | 77 | |
|
78 | 78 | return render(request, 'location.html', kwargs) |
|
79 | 79 | |
|
80 | 80 | |
|
81 | 81 | def location_new(request): |
|
82 | 82 | |
|
83 | 83 | if request.method == 'GET': |
|
84 | 84 | form = LocationForm() |
|
85 | 85 | |
|
86 | 86 | if request.method == 'POST': |
|
87 | 87 | form = LocationForm(request.POST) |
|
88 | 88 | |
|
89 | 89 | if form.is_valid(): |
|
90 | 90 | form.save() |
|
91 | 91 | return redirect('url_locations') |
|
92 | 92 | |
|
93 | 93 | kwargs = {} |
|
94 | 94 | kwargs['form'] = form |
|
95 | 95 | kwargs['title'] = 'Location' |
|
96 | 96 | kwargs['suptitle'] = 'New' |
|
97 | 97 | kwargs['button'] = 'Create' |
|
98 | 98 | |
|
99 | 99 | return render(request, 'location_edit.html', kwargs) |
|
100 | 100 | |
|
101 | 101 | |
|
102 | 102 | def location_edit(request, id_loc): |
|
103 | 103 | |
|
104 | 104 | location = get_object_or_404(Location, pk=id_loc) |
|
105 | 105 | |
|
106 | 106 | if request.method=='GET': |
|
107 | 107 | form = LocationForm(instance=location) |
|
108 | 108 | |
|
109 | 109 | if request.method=='POST': |
|
110 | 110 | form = LocationForm(request.POST, instance=location) |
|
111 | 111 | |
|
112 | 112 | if form.is_valid(): |
|
113 | 113 | form.save() |
|
114 | 114 | return redirect('url_locations') |
|
115 | 115 | |
|
116 | 116 | kwargs = {} |
|
117 | 117 | kwargs['form'] = form |
|
118 | 118 | kwargs['title'] = 'Location' |
|
119 | 119 | kwargs['suptitle'] = 'Edit' |
|
120 | 120 | kwargs['button'] = 'Update' |
|
121 | 121 | |
|
122 | 122 | return render(request, 'location_edit.html', kwargs) |
|
123 | 123 | |
|
124 | 124 | |
|
125 | 125 | def location_delete(request, id_loc): |
|
126 | 126 | |
|
127 | 127 | location = get_object_or_404(Location, pk=id_loc) |
|
128 | 128 | |
|
129 | 129 | if request.method=='POST': |
|
130 | 130 | |
|
131 | 131 | if request.user.is_staff: |
|
132 | 132 | location.delete() |
|
133 | 133 | return redirect('url_locations') |
|
134 | 134 | |
|
135 | 135 | messages.error(request, 'Not enough permission to delete this object') |
|
136 | 136 | return redirect(location.get_absolute_url()) |
|
137 | 137 | |
|
138 | 138 | kwargs = { |
|
139 | 139 | 'title': 'Delete', |
|
140 | 140 | 'suptitle': 'Location', |
|
141 | 141 | 'object': location, |
|
142 | 142 | 'previous': location.get_absolute_url(), |
|
143 | 143 | 'delete': True |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | return render(request, 'confirm.html', kwargs) |
|
147 | 147 | |
|
148 | 148 | |
|
149 | 149 | def devices(request): |
|
150 | 150 | |
|
151 | 151 | devices = Device.objects.all().order_by('device_type__name') |
|
152 | 152 | |
|
153 | 153 | # keys = ['id', 'device_type__name', 'name', 'ip_address'] |
|
154 | 154 | keys = ['id', 'name', 'ip_address', 'port_address', 'device_type'] |
|
155 | 155 | |
|
156 | 156 | kwargs = {} |
|
157 | 157 | kwargs['device_keys'] = keys[1:] |
|
158 | 158 | kwargs['devices'] = devices#.values(*keys) |
|
159 | 159 | kwargs['title'] = 'Device' |
|
160 | 160 | kwargs['suptitle'] = 'List' |
|
161 | 161 | kwargs['button'] = 'New Device' |
|
162 | 162 | |
|
163 | 163 | return render(request, 'devices.html', kwargs) |
|
164 | 164 | |
|
165 | 165 | |
|
166 | 166 | def device(request, id_dev): |
|
167 | 167 | |
|
168 | 168 | device = get_object_or_404(Device, pk=id_dev) |
|
169 | 169 | |
|
170 | 170 | kwargs = {} |
|
171 | 171 | kwargs['device'] = device |
|
172 | 172 | kwargs['device_keys'] = ['device_type', 'name', 'ip_address', 'port_address', 'description'] |
|
173 | 173 | |
|
174 | 174 | kwargs['title'] = 'Device' |
|
175 | 175 | kwargs['suptitle'] = 'Details' |
|
176 | 176 | |
|
177 | 177 | return render(request, 'device.html', kwargs) |
|
178 | 178 | |
|
179 | 179 | |
|
180 | 180 | def device_new(request): |
|
181 | 181 | |
|
182 | 182 | if request.method == 'GET': |
|
183 | 183 | form = DeviceForm() |
|
184 | 184 | |
|
185 | 185 | if request.method == 'POST': |
|
186 | 186 | form = DeviceForm(request.POST) |
|
187 | 187 | |
|
188 | 188 | if form.is_valid(): |
|
189 | 189 | form.save() |
|
190 | 190 | return redirect('url_devices') |
|
191 | 191 | |
|
192 | 192 | kwargs = {} |
|
193 | 193 | kwargs['form'] = form |
|
194 | 194 | kwargs['title'] = 'Device' |
|
195 | 195 | kwargs['suptitle'] = 'New' |
|
196 | 196 | kwargs['button'] = 'Create' |
|
197 | 197 | |
|
198 | 198 | return render(request, 'device_edit.html', kwargs) |
|
199 | 199 | |
|
200 | 200 | |
|
201 | 201 | def device_edit(request, id_dev): |
|
202 | 202 | |
|
203 | 203 | device = get_object_or_404(Device, pk=id_dev) |
|
204 | 204 | |
|
205 | 205 | if request.method=='GET': |
|
206 | 206 | form = DeviceForm(instance=device) |
|
207 | 207 | |
|
208 | 208 | if request.method=='POST': |
|
209 | 209 | form = DeviceForm(request.POST, instance=device) |
|
210 | 210 | |
|
211 | 211 | if form.is_valid(): |
|
212 | 212 | form.save() |
|
213 | 213 | return redirect(device.get_absolute_url()) |
|
214 | 214 | |
|
215 | 215 | kwargs = {} |
|
216 | 216 | kwargs['form'] = form |
|
217 | 217 | kwargs['title'] = 'Device' |
|
218 | 218 | kwargs['suptitle'] = 'Edit' |
|
219 | 219 | kwargs['button'] = 'Update' |
|
220 | 220 | |
|
221 | 221 | return render(request, 'device_edit.html', kwargs) |
|
222 | 222 | |
|
223 | 223 | |
|
224 | 224 | def device_delete(request, id_dev): |
|
225 | 225 | |
|
226 | 226 | device = get_object_or_404(Device, pk=id_dev) |
|
227 | 227 | |
|
228 | 228 | if request.method=='POST': |
|
229 | 229 | |
|
230 | 230 | if request.user.is_staff: |
|
231 | 231 | device.delete() |
|
232 | 232 | return redirect('url_devices') |
|
233 | 233 | |
|
234 | 234 | messages.error(request, 'Not enough permission to delete this object') |
|
235 | 235 | return redirect(device.get_absolute_url()) |
|
236 | 236 | |
|
237 | 237 | kwargs = { |
|
238 | 238 | 'title': 'Delete', |
|
239 | 239 | 'suptitle': 'Device', |
|
240 | 240 | 'object': device, |
|
241 | 241 | 'previous': device.get_absolute_url(), |
|
242 | 242 | 'delete': True |
|
243 | 243 | } |
|
244 | 244 | |
|
245 | 245 | return render(request, 'confirm.html', kwargs) |
|
246 | 246 | |
|
247 | 247 | |
|
248 | 248 | def campaigns(request): |
|
249 | 249 | |
|
250 | 250 | campaigns = Campaign.objects.all().order_by('start_date') |
|
251 | 251 | |
|
252 | 252 | keys = ['id', 'name', 'start_date', 'end_date'] |
|
253 | 253 | |
|
254 | 254 | kwargs = {} |
|
255 | 255 | kwargs['campaign_keys'] = keys[1:] |
|
256 | 256 | kwargs['campaigns'] = campaigns#.values(*keys) |
|
257 | 257 | kwargs['title'] = 'Campaign' |
|
258 | 258 | kwargs['suptitle'] = 'List' |
|
259 | 259 | kwargs['button'] = 'New Campaign' |
|
260 | 260 | |
|
261 | 261 | return render(request, 'campaigns.html', kwargs) |
|
262 | 262 | |
|
263 | 263 | |
|
264 | 264 | def campaign(request, id_camp): |
|
265 | 265 | |
|
266 | 266 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
267 | 267 | experiments = Experiment.objects.filter(campaign=campaign) |
|
268 | 268 | |
|
269 | 269 | form = CampaignForm(instance=campaign) |
|
270 | 270 | |
|
271 | 271 | kwargs = {} |
|
272 | 272 | kwargs['campaign'] = campaign |
|
273 | 273 | kwargs['campaign_keys'] = ['template', 'name', 'start_date', 'end_date', 'tags', 'description'] |
|
274 | 274 | |
|
275 | 275 | kwargs['experiments'] = experiments |
|
276 | 276 | kwargs['experiment_keys'] = ['name', 'radar', 'start_time', 'end_time'] |
|
277 | 277 | |
|
278 | 278 | kwargs['title'] = 'Campaign' |
|
279 | 279 | kwargs['suptitle'] = 'Details' |
|
280 | 280 | |
|
281 | 281 | kwargs['form'] = form |
|
282 | 282 | kwargs['button'] = 'Add Experiment' |
|
283 | 283 | |
|
284 | 284 | return render(request, 'campaign.html', kwargs) |
|
285 | 285 | |
|
286 | 286 | |
|
287 | 287 | def campaign_new(request): |
|
288 | 288 | |
|
289 | 289 | kwargs = {} |
|
290 | 290 | |
|
291 | 291 | if request.method == 'GET': |
|
292 | 292 | |
|
293 | 293 | if 'template' in request.GET: |
|
294 | 294 | if request.GET['template']=='0': |
|
295 | 295 | form = NewForm(initial={'create_from':2}, |
|
296 | 296 | template_choices=Campaign.objects.filter(template=True).values_list('id', 'name')) |
|
297 | 297 | else: |
|
298 | 298 | kwargs['button'] = 'Create' |
|
299 | 299 | kwargs['experiments'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
300 | 300 | kwargs['experiment_keys'] = ['name', 'start_time', 'end_time'] |
|
301 | 301 | camp = Campaign.objects.get(pk=request.GET['template']) |
|
302 | 302 | form = CampaignForm(instance=camp, |
|
303 | 303 | initial={'name':'{} [{:%Y/%m/%d}]'.format(camp.name, datetime.now()), |
|
304 | 304 | 'template':False}) |
|
305 | 305 | elif 'blank' in request.GET: |
|
306 | 306 | kwargs['button'] = 'Create' |
|
307 | 307 | form = CampaignForm() |
|
308 | 308 | else: |
|
309 | 309 | form = NewForm() |
|
310 | 310 | |
|
311 | 311 | if request.method == 'POST': |
|
312 | 312 | kwargs['button'] = 'Create' |
|
313 | 313 | post = request.POST.copy() |
|
314 | 314 | experiments = [] |
|
315 | 315 | |
|
316 | 316 | for id_exp in post.getlist('experiments'): |
|
317 | 317 | exp = Experiment.objects.get(pk=id_exp) |
|
318 | 318 | new_exp = exp.clone(template=False) |
|
319 | 319 | experiments.append(new_exp) |
|
320 | 320 | |
|
321 | 321 | post.setlist('experiments', []) |
|
322 | 322 | |
|
323 | 323 | form = CampaignForm(post) |
|
324 | 324 | |
|
325 | 325 | if form.is_valid(): |
|
326 | 326 | campaign = form.save() |
|
327 | 327 | for exp in experiments: |
|
328 | 328 | campaign.experiments.add(exp) |
|
329 | 329 | campaign.save() |
|
330 | 330 | return redirect('url_campaign', id_camp=campaign.id) |
|
331 | 331 | |
|
332 | 332 | kwargs['form'] = form |
|
333 | 333 | kwargs['title'] = 'Campaign' |
|
334 | 334 | kwargs['suptitle'] = 'New' |
|
335 | 335 | |
|
336 | 336 | return render(request, 'campaign_edit.html', kwargs) |
|
337 | 337 | |
|
338 | 338 | |
|
339 | 339 | def campaign_edit(request, id_camp): |
|
340 | 340 | |
|
341 | 341 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
342 | 342 | |
|
343 | 343 | if request.method=='GET': |
|
344 | 344 | form = CampaignForm(instance=campaign) |
|
345 | 345 | |
|
346 | 346 | if request.method=='POST': |
|
347 | 347 | exps = campaign.experiments.all().values_list('pk', flat=True) |
|
348 | 348 | post = request.POST.copy() |
|
349 | 349 | new_exps = post.getlist('experiments') |
|
350 | 350 | post.setlist('experiments', []) |
|
351 | 351 | form = CampaignForm(post, instance=campaign) |
|
352 | 352 | |
|
353 | 353 | if form.is_valid(): |
|
354 | 354 | camp = form.save() |
|
355 | 355 | for id_exp in new_exps: |
|
356 | 356 | if int(id_exp) in exps: |
|
357 | 357 | exps.pop(id_exp) |
|
358 | 358 | else: |
|
359 | 359 | exp = Experiment.objects.get(pk=id_exp) |
|
360 | 360 | if exp.template: |
|
361 | 361 | camp.experiments.add(exp.clone(template=False)) |
|
362 | 362 | else: |
|
363 | 363 | camp.experiments.add(exp) |
|
364 | 364 | |
|
365 | 365 | for id_exp in exps: |
|
366 | 366 | camp.experiments.remove(Experiment.objects.get(pk=id_exp)) |
|
367 | 367 | |
|
368 | 368 | return redirect('url_campaign', id_camp=id_camp) |
|
369 | 369 | |
|
370 | 370 | kwargs = {} |
|
371 | 371 | kwargs['form'] = form |
|
372 | 372 | kwargs['title'] = 'Campaign' |
|
373 | 373 | kwargs['suptitle'] = 'Edit' |
|
374 | 374 | kwargs['button'] = 'Update' |
|
375 | 375 | |
|
376 | 376 | return render(request, 'campaign_edit.html', kwargs) |
|
377 | 377 | |
|
378 | 378 | |
|
379 | 379 | def campaign_delete(request, id_camp): |
|
380 | 380 | |
|
381 | 381 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
382 | 382 | |
|
383 | 383 | if request.method=='POST': |
|
384 | 384 | if request.user.is_staff: |
|
385 | 385 | |
|
386 | 386 | for exp in campaign.experiments.all(): |
|
387 | 387 | for conf in Configuration.objects.filter(experiment=exp): |
|
388 | 388 | conf.delete() |
|
389 | 389 | exp.delete() |
|
390 | 390 | campaign.delete() |
|
391 | 391 | |
|
392 | 392 | return redirect('url_campaigns') |
|
393 | 393 | |
|
394 | 394 | messages.error(request, 'Not enough permission to delete this object') |
|
395 | 395 | return redirect(campaign.get_absolute_url()) |
|
396 | 396 | |
|
397 | 397 | kwargs = { |
|
398 | 398 | 'title': 'Delete', |
|
399 | 399 | 'suptitle': 'Campaign', |
|
400 | 400 | 'object': campaign, |
|
401 | 401 | 'previous': campaign.get_absolute_url(), |
|
402 | 402 | 'delete': True |
|
403 | 403 | } |
|
404 | 404 | |
|
405 | 405 | return render(request, 'confirm.html', kwargs) |
|
406 | 406 | |
|
407 | def campaign_export(request, id_camp): | |
|
408 | ||
|
409 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
|
410 | content = campaign.parms_to_dict() | |
|
411 | content_type = 'application/json' | |
|
412 | filename = '%s_%s.json' %(campaign.name, campaign.id) | |
|
413 | ||
|
414 | response = HttpResponse(content_type=content_type) | |
|
415 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
|
416 | response.write(content) | |
|
417 | ||
|
418 | return response | |
|
407 | 419 | |
|
408 | 420 | def experiments(request): |
|
409 | 421 | |
|
410 | 422 | experiment_list = Experiment.objects.all() |
|
411 | 423 | |
|
412 | 424 | keys = ['id', 'name', 'start_time', 'end_time'] |
|
413 | 425 | |
|
414 | 426 | kwargs = {} |
|
415 | 427 | |
|
416 | 428 | kwargs['experiment_keys'] = keys[1:] |
|
417 | 429 | kwargs['experiments'] = experiment_list |
|
418 | 430 | |
|
419 | 431 | kwargs['title'] = 'Experiment' |
|
420 | 432 | kwargs['suptitle'] = 'List' |
|
421 | 433 | kwargs['button'] = 'New Experiment' |
|
422 | 434 | |
|
423 | 435 | return render(request, 'experiments.html', kwargs) |
|
424 | 436 | |
|
425 | 437 | |
|
426 | 438 | def experiment(request, id_exp): |
|
427 | 439 | |
|
428 | 440 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
429 | 441 | |
|
430 | 442 | configurations = Configuration.objects.filter(experiment=experiment, type=0) |
|
431 | 443 | |
|
432 | 444 | kwargs = {} |
|
433 | 445 | |
|
434 | 446 | kwargs['experiment_keys'] = ['template', 'radar', 'name', 'start_time', 'end_time'] |
|
435 | 447 | kwargs['experiment'] = experiment |
|
436 | 448 | |
|
437 | 449 | kwargs['configuration_keys'] = ['device__name', 'device__device_type', 'device__ip_address', 'device__port_address'] |
|
438 | 450 | kwargs['configurations'] = configurations |
|
439 | 451 | |
|
440 | 452 | kwargs['title'] = 'Experiment' |
|
441 | 453 | kwargs['suptitle'] = 'Details' |
|
442 | 454 | |
|
443 | 455 | kwargs['button'] = 'Add Configuration' |
|
444 | 456 | |
|
445 | 457 | ###### SIDEBAR ###### |
|
446 | 458 | kwargs.update(sidebar(experiment=experiment)) |
|
447 | 459 | |
|
448 | 460 | return render(request, 'experiment.html', kwargs) |
|
449 | 461 | |
|
450 | 462 | |
|
451 | 463 | def experiment_new(request, id_camp=None): |
|
452 | 464 | |
|
453 | 465 | kwargs = {} |
|
454 | 466 | |
|
455 | 467 | if request.method == 'GET': |
|
456 | 468 | if 'template' in request.GET: |
|
457 | 469 | if request.GET['template']=='0': |
|
458 | 470 | form = NewForm(initial={'create_from':2}, |
|
459 | 471 | template_choices=Experiment.objects.filter(template=True).values_list('id', 'name')) |
|
460 | 472 | else: |
|
461 | 473 | kwargs['button'] = 'Create' |
|
462 | 474 | kwargs['configurations'] = Configuration.objects.filter(experiment=request.GET['template']) |
|
463 | 475 | kwargs['configuration_keys'] = ['name', 'device__name', 'device__ip_address', 'device__port_address'] |
|
464 | 476 | exp=Experiment.objects.get(pk=request.GET['template']) |
|
465 | 477 | form = ExperimentForm(instance=exp, |
|
466 | 478 | initial={'name': '{} [{:%Y/%m/%d}]'.format(exp.name, datetime.now()), |
|
467 | 479 | 'template': False}) |
|
468 | 480 | elif 'blank' in request.GET: |
|
469 | 481 | kwargs['button'] = 'Create' |
|
470 | 482 | form = ExperimentForm() |
|
471 | 483 | else: |
|
472 | 484 | form = NewForm() |
|
473 | 485 | |
|
474 | 486 | if request.method == 'POST': |
|
475 | 487 | form = ExperimentForm(request.POST) |
|
476 | 488 | if form.is_valid(): |
|
477 | 489 | experiment = form.save() |
|
478 | 490 | |
|
479 | 491 | if 'template' in request.GET: |
|
480 | 492 | configurations = Configuration.objects.filter(experiment=request.GET['template'], type=0) |
|
481 | 493 | for conf in configurations: |
|
482 | 494 | conf.clone(experiment=experiment, template=False) |
|
483 | 495 | |
|
484 | 496 | return redirect('url_experiment', id_exp=experiment.id) |
|
485 | 497 | |
|
486 | 498 | kwargs['form'] = form |
|
487 | 499 | kwargs['title'] = 'Experiment' |
|
488 | 500 | kwargs['suptitle'] = 'New' |
|
489 | 501 | |
|
490 | 502 | return render(request, 'experiment_edit.html', kwargs) |
|
491 | 503 | |
|
492 | 504 | |
|
493 | 505 | def experiment_edit(request, id_exp): |
|
494 | 506 | |
|
495 | 507 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
496 | 508 | |
|
497 | 509 | if request.method == 'GET': |
|
498 | 510 | form = ExperimentForm(instance=experiment) |
|
499 | 511 | |
|
500 | 512 | if request.method=='POST': |
|
501 | 513 | form = ExperimentForm(request.POST, instance=experiment) |
|
502 | 514 | |
|
503 | 515 | if form.is_valid(): |
|
504 | 516 | experiment = form.save() |
|
505 | 517 | return redirect('url_experiment', id_exp=experiment.id) |
|
506 | 518 | |
|
507 | 519 | kwargs = {} |
|
508 | 520 | kwargs['form'] = form |
|
509 | 521 | kwargs['title'] = 'Experiment' |
|
510 | 522 | kwargs['suptitle'] = 'Edit' |
|
511 | 523 | kwargs['button'] = 'Update' |
|
512 | 524 | |
|
513 | 525 | return render(request, 'experiment_edit.html', kwargs) |
|
514 | 526 | |
|
515 | 527 | |
|
516 | 528 | def experiment_delete(request, id_exp): |
|
517 | 529 | |
|
518 | 530 | experiment = get_object_or_404(Experiment, pk=id_exp) |
|
519 | 531 | |
|
520 | 532 | if request.method=='POST': |
|
521 | 533 | if request.user.is_staff: |
|
522 | 534 | for conf in Configuration.objects.filter(experiment=experiment): |
|
523 | 535 | conf.delete() |
|
524 | 536 | experiment.delete() |
|
525 | 537 | return redirect('url_experiments') |
|
526 | 538 | |
|
527 | 539 | messages.error(request, 'Not enough permission to delete this object') |
|
528 | 540 | return redirect(experiment.get_absolute_url()) |
|
529 | 541 | |
|
530 | 542 | kwargs = { |
|
531 | 543 | 'title': 'Delete', |
|
532 | 544 | 'suptitle': 'Experiment', |
|
533 | 545 | 'object': experiment, |
|
534 | 546 | 'previous': experiment.get_absolute_url(), |
|
535 | 547 | 'delete': True |
|
536 | 548 | } |
|
537 | 549 | |
|
538 | 550 | return render(request, 'confirm.html', kwargs) |
|
539 | 551 | |
|
540 | 552 | |
|
553 | def experiment_export(request, id_exp): | |
|
554 | ||
|
555 | experiment = get_object_or_404(Experiment, pk=id_exp) | |
|
556 | content = experiment.parms_to_dict() | |
|
557 | content_type = 'application/json' | |
|
558 | filename = '%s_%s.json' %(experiment.name, experiment.id) | |
|
559 | ||
|
560 | response = HttpResponse(content_type=content_type) | |
|
561 | response['Content-Disposition'] = 'attachment; filename="%s"' %filename | |
|
562 | response.write(content) | |
|
563 | ||
|
564 | return response | |
|
565 | ||
|
566 | ||
|
541 | 567 | def dev_confs(request): |
|
542 | 568 | |
|
543 | 569 | configurations = Configuration.objects.all().order_by('type', 'device__device_type', 'experiment') |
|
544 | 570 | |
|
545 | 571 | kwargs = {} |
|
546 | 572 | |
|
547 | 573 | kwargs['configuration_keys'] = ['device', 'experiment', 'type', 'programmed_date'] |
|
548 | 574 | kwargs['configurations'] = configurations |
|
549 | 575 | |
|
550 | 576 | kwargs['title'] = 'Configuration' |
|
551 | 577 | kwargs['suptitle'] = 'List' |
|
552 | 578 | |
|
553 | 579 | return render(request, 'dev_confs.html', kwargs) |
|
554 | 580 | |
|
555 | 581 | |
|
556 | 582 | def dev_conf(request, id_conf): |
|
557 | 583 | |
|
558 | 584 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
559 | 585 | |
|
560 | 586 | return redirect(conf.get_absolute_url()) |
|
561 | 587 | |
|
562 | 588 | |
|
563 | 589 | def dev_conf_new(request, id_exp=0, id_dev=0): |
|
564 | 590 | |
|
565 | 591 | initial = {} |
|
566 | 592 | |
|
567 | 593 | if id_exp<>0: |
|
568 | 594 | initial['experiment'] = id_exp |
|
569 | 595 | |
|
570 | 596 | if id_dev<>0: |
|
571 | 597 | initial['device'] = id_dev |
|
572 | 598 | |
|
573 | 599 | if request.method == 'GET': |
|
574 | 600 | if id_dev==0: |
|
575 | 601 | form = ConfigurationForm(initial=initial) |
|
576 | 602 | else: |
|
577 | 603 | device = Device.objects.get(pk=id_dev) |
|
578 | 604 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
579 | 605 | |
|
580 | 606 | form = DevConfForm(initial=initial) |
|
581 | 607 | |
|
582 | 608 | if request.method == 'POST': |
|
583 | 609 | |
|
584 | 610 | device = Device.objects.get(pk=request.POST['device']) |
|
585 | 611 | DevConfForm = CONF_FORMS[device.device_type.name] |
|
586 | 612 | |
|
587 | 613 | form = DevConfForm(request.POST) |
|
588 | 614 | |
|
589 | 615 | if form.is_valid(): |
|
590 | 616 | dev_conf = form.save() |
|
591 | 617 | |
|
592 | 618 | return redirect('url_dev_confs') |
|
593 | 619 | |
|
594 | 620 | kwargs = {} |
|
595 | 621 | kwargs['id_exp'] = id_exp |
|
596 | 622 | kwargs['form'] = form |
|
597 | 623 | kwargs['title'] = 'Configuration' |
|
598 | 624 | kwargs['suptitle'] = 'New' |
|
599 | 625 | kwargs['button'] = 'Create' |
|
600 | 626 | |
|
601 | 627 | if id_dev != 0: |
|
602 | 628 | device = Device.objects.get(pk=id_dev) |
|
603 | 629 | if 'dds' in device.device_type.name: |
|
604 | 630 | kwargs['dds_device'] = True |
|
605 | 631 | |
|
606 | 632 | return render(request, 'dev_conf_edit.html', kwargs) |
|
607 | 633 | |
|
608 | 634 | |
|
609 | 635 | def dev_conf_edit(request, id_conf): |
|
610 | 636 | |
|
611 | 637 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
612 | 638 | |
|
613 | 639 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
614 | 640 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
615 | 641 | |
|
616 | 642 | dev_conf = DevConfModel.objects.get(pk=id_conf) |
|
617 | 643 | |
|
618 | 644 | if request.method=='GET': |
|
619 | 645 | form = DevConfForm(instance=dev_conf) |
|
620 | 646 | |
|
621 | 647 | if request.method=='POST': |
|
622 | 648 | form = DevConfForm(request.POST, instance=dev_conf) |
|
623 | 649 | |
|
624 | 650 | if form.is_valid(): |
|
625 | 651 | form.save() |
|
626 | 652 | return redirect('url_dev_conf', id_conf=id_conf) |
|
627 | 653 | |
|
628 | 654 | kwargs = {} |
|
629 | 655 | kwargs['form'] = form |
|
630 | 656 | kwargs['title'] = 'Device Configuration' |
|
631 | 657 | kwargs['suptitle'] = 'Edit' |
|
632 | 658 | kwargs['button'] = 'Update' |
|
633 | 659 | |
|
634 | 660 | ###### SIDEBAR ###### |
|
635 | 661 | kwargs.update(sidebar(conf=conf)) |
|
636 | 662 | |
|
637 | 663 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
638 | 664 | |
|
639 | 665 | |
|
640 | 666 | def dev_conf_start(request, id_conf): |
|
641 | 667 | |
|
642 | 668 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
643 | 669 | |
|
644 | 670 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
645 | 671 | |
|
646 | 672 | conf = DevConfModel.objects.get(pk=id_conf) |
|
647 | 673 | |
|
648 | 674 | if conf.start_device(): |
|
649 | 675 | messages.success(request, conf.message) |
|
650 | 676 | else: |
|
651 | 677 | messages.error(request, conf.message) |
|
652 | 678 | |
|
653 | 679 | conf.status_device() |
|
654 | 680 | |
|
655 | 681 | return redirect(conf.get_absolute_url()) |
|
656 | 682 | |
|
657 | 683 | |
|
658 | 684 | def dev_conf_stop(request, id_conf): |
|
659 | 685 | |
|
660 | 686 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
661 | 687 | |
|
662 | 688 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
663 | 689 | |
|
664 | 690 | conf = DevConfModel.objects.get(pk=id_conf) |
|
665 | 691 | |
|
666 | 692 | if conf.stop_device(): |
|
667 | 693 | messages.success(request, conf.message) |
|
668 | 694 | else: |
|
669 | 695 | messages.error(request, conf.message) |
|
670 | 696 | |
|
671 | 697 | conf.status_device() |
|
672 | 698 | |
|
673 | 699 | return redirect(conf.get_absolute_url()) |
|
674 | 700 | |
|
675 | 701 | |
|
676 | 702 | def dev_conf_status(request, id_conf): |
|
677 | 703 | |
|
678 | 704 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
679 | 705 | |
|
680 | 706 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
681 | 707 | |
|
682 | 708 | conf = DevConfModel.objects.get(pk=id_conf) |
|
683 | 709 | |
|
684 | 710 | if conf.status_device(): |
|
685 | 711 | messages.success(request, conf.message) |
|
686 | 712 | else: |
|
687 | 713 | messages.error(request, conf.message) |
|
688 | 714 | |
|
689 | 715 | return redirect(conf.get_absolute_url()) |
|
690 | 716 | |
|
691 | 717 | |
|
692 | 718 | def dev_conf_write(request, id_conf): |
|
693 | 719 | |
|
694 | 720 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
695 | 721 | |
|
696 | 722 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
697 | 723 | |
|
698 | 724 | conf = DevConfModel.objects.get(pk=id_conf) |
|
699 | 725 | |
|
700 | 726 | answer = conf.write_device() |
|
701 | 727 | conf.status_device() |
|
702 | 728 | |
|
703 | 729 | if answer: |
|
704 | 730 | messages.success(request, conf.message) |
|
705 | 731 | |
|
706 | 732 | #Creating a historical configuration |
|
707 | 733 | conf.clone(type=0, template=False) |
|
708 | 734 | |
|
709 | 735 | #Original configuration |
|
710 | 736 | conf = DevConfModel.objects.get(pk=id_conf) |
|
711 | 737 | else: |
|
712 | 738 | messages.error(request, conf.message) |
|
713 | 739 | |
|
714 | 740 | return redirect(conf.get_absolute_url()) |
|
715 | 741 | |
|
716 | 742 | |
|
717 | 743 | def dev_conf_read(request, id_conf): |
|
718 | 744 | |
|
719 | 745 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
720 | 746 | |
|
721 | 747 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
722 | 748 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
723 | 749 | |
|
724 | 750 | conf = DevConfModel.objects.get(pk=id_conf) |
|
725 | 751 | |
|
726 | 752 | if request.method=='GET': |
|
727 | 753 | |
|
728 | 754 | parms = conf.read_device() |
|
729 | 755 | conf.status_device() |
|
730 | 756 | |
|
731 | 757 | if not parms: |
|
732 | 758 | messages.error(request, conf.message) |
|
733 | 759 | return redirect(conf.get_absolute_url()) |
|
734 | 760 | |
|
735 | 761 | form = DevConfForm(initial=parms, instance=conf) |
|
736 | 762 | |
|
737 | 763 | if request.method=='POST': |
|
738 | 764 | form = DevConfForm(request.POST, instance=conf) |
|
739 | 765 | |
|
740 | 766 | if form.is_valid(): |
|
741 | 767 | form.save() |
|
742 | 768 | return redirect(conf.get_absolute_url()) |
|
743 | 769 | |
|
744 | 770 | messages.error(request, "Parameters could not be saved") |
|
745 | 771 | |
|
746 | 772 | kwargs = {} |
|
747 | 773 | kwargs['id_dev'] = conf.id |
|
748 | 774 | kwargs['form'] = form |
|
749 | 775 | kwargs['title'] = 'Device Configuration' |
|
750 | 776 | kwargs['suptitle'] = 'Parameters read from device' |
|
751 | 777 | kwargs['button'] = 'Save' |
|
752 | 778 | |
|
753 | 779 | ###### SIDEBAR ###### |
|
754 | 780 | kwargs.update(sidebar(conf=conf)) |
|
755 | 781 | |
|
756 | 782 | return render(request, '%s_conf_edit.html' %conf.device.device_type.name, kwargs) |
|
757 | 783 | |
|
758 | 784 | |
|
759 | 785 | def dev_conf_import(request, id_conf): |
|
760 | 786 | |
|
761 | 787 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
762 | 788 | |
|
763 | 789 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
764 | 790 | DevConfForm = CONF_FORMS[conf.device.device_type.name] |
|
765 | 791 | conf = DevConfModel.objects.get(pk=id_conf) |
|
766 | 792 | |
|
767 | 793 | if request.method == 'GET': |
|
768 | 794 | file_form = UploadFileForm() |
|
769 | 795 | |
|
770 | 796 | if request.method == 'POST': |
|
771 | 797 | file_form = UploadFileForm(request.POST, request.FILES) |
|
772 | 798 | |
|
773 | 799 | if file_form.is_valid(): |
|
774 | 800 | |
|
775 | 801 | parms = conf.import_from_file(request.FILES['file']) |
|
776 | 802 | |
|
777 | 803 | if parms: |
|
778 | 804 | messages.success(request, "Parameters imported from: '%s'." %request.FILES['file'].name) |
|
779 | 805 | form = DevConfForm(initial=parms, instance=conf) |
|
780 | 806 | |
|
781 | 807 | kwargs = {} |
|
782 | 808 | kwargs['id_dev'] = conf.id |
|
783 | 809 | kwargs['form'] = form |
|
784 | 810 | kwargs['title'] = 'Device Configuration' |
|
785 | 811 | kwargs['suptitle'] = 'Parameters imported' |
|
786 | 812 | kwargs['button'] = 'Save' |
|
787 | 813 | kwargs['action'] = conf.get_absolute_url_edit() |
|
788 | 814 | kwargs['previous'] = conf.get_absolute_url() |
|
789 | 815 | |
|
790 | 816 | ###### SIDEBAR ###### |
|
791 | 817 | kwargs.update(sidebar(conf=conf)) |
|
792 | 818 | |
|
793 | 819 | return render(request, '%s_conf_edit.html' % conf.device.device_type.name, kwargs) |
|
794 | 820 | |
|
795 | 821 | messages.error(request, "Could not import parameters from file") |
|
796 | 822 | |
|
797 | 823 | kwargs = {} |
|
798 | 824 | kwargs['id_dev'] = conf.id |
|
799 | 825 | kwargs['title'] = 'Device Configuration' |
|
800 | 826 | kwargs['form'] = file_form |
|
801 | 827 | kwargs['suptitle'] = 'Importing file' |
|
802 | 828 | kwargs['button'] = 'Import' |
|
803 | 829 | |
|
804 | 830 | kwargs.update(sidebar(conf=conf)) |
|
805 | 831 | |
|
806 | 832 | return render(request, 'dev_conf_import.html', kwargs) |
|
807 | 833 | |
|
808 | 834 | |
|
809 | 835 | def dev_conf_export(request, id_conf): |
|
810 | 836 | |
|
811 | 837 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
812 | 838 | |
|
813 | 839 | DevConfModel = CONF_MODELS[conf.device.device_type.name] |
|
814 | 840 | |
|
815 | 841 | conf = DevConfModel.objects.get(pk=id_conf) |
|
816 | 842 | |
|
817 | 843 | if request.method == 'GET': |
|
818 | 844 | file_form = DownloadFileForm(conf.device.device_type.name) |
|
819 | 845 | |
|
820 | 846 | if request.method == 'POST': |
|
821 | 847 | file_form = DownloadFileForm(conf.device.device_type.name, request.POST) |
|
822 | 848 | |
|
823 | 849 | if file_form.is_valid(): |
|
824 | 850 | fields = conf.export_to_file(format = file_form.cleaned_data['format']) |
|
825 | 851 | |
|
826 | 852 | response = HttpResponse(content_type=fields['content_type']) |
|
827 | 853 | response['Content-Disposition'] = 'attachment; filename="%s"' %fields['filename'] |
|
828 | 854 | response.write(fields['content']) |
|
829 | 855 | |
|
830 | 856 | return response |
|
831 | 857 | |
|
832 | 858 | messages.error(request, "Could not export parameters") |
|
833 | 859 | |
|
834 | 860 | kwargs = {} |
|
835 | 861 | kwargs['id_dev'] = conf.id |
|
836 | 862 | kwargs['title'] = 'Device Configuration' |
|
837 | 863 | kwargs['form'] = file_form |
|
838 | 864 | kwargs['suptitle'] = 'Exporting file' |
|
839 | 865 | kwargs['button'] = 'Export' |
|
840 | 866 | |
|
841 | 867 | return render(request, 'dev_conf_export.html', kwargs) |
|
842 | 868 | |
|
843 | 869 | |
|
844 | 870 | def dev_conf_delete(request, id_conf): |
|
845 | 871 | |
|
846 | 872 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
847 | 873 | |
|
848 | 874 | if request.method=='POST': |
|
849 | 875 | if request.user.is_staff: |
|
850 | 876 | conf.delete() |
|
851 | 877 | return redirect('url_dev_confs') |
|
852 | 878 | |
|
853 | 879 | messages.error(request, 'Not enough permission to delete this object') |
|
854 | 880 | return redirect(conf.get_absolute_url()) |
|
855 | 881 | |
|
856 | 882 | kwargs = { |
|
857 | 883 | 'title': 'Delete', |
|
858 | 884 | 'suptitle': 'Experiment', |
|
859 | 885 | 'object': conf, |
|
860 | 886 | 'previous': conf.get_absolute_url(), |
|
861 | 887 | 'delete': True |
|
862 | 888 | } |
|
863 | 889 | |
|
864 | 890 | return render(request, 'confirm.html', kwargs) |
|
865 | 891 | |
|
866 | 892 | |
|
867 | 893 | def sidebar(**kwargs): |
|
868 | 894 | |
|
869 | 895 | side_data = {} |
|
870 | 896 | |
|
871 | 897 | conf = kwargs.get('conf', None) |
|
872 | 898 | experiment = kwargs.get('experiment', None) |
|
873 | 899 | |
|
874 | 900 | if not experiment: |
|
875 | 901 | experiment = conf.experiment |
|
876 | 902 | |
|
877 | 903 | if experiment: |
|
878 | 904 | side_data['experiment'] = experiment |
|
879 | 905 | campaign = experiment.campaign_set.all() |
|
880 | 906 | if campaign: |
|
881 | 907 | side_data['campaign'] = campaign[0] |
|
882 | 908 | experiments = campaign[0].experiments.all() |
|
883 | 909 | else: |
|
884 | 910 | experiments = [experiment] |
|
885 | 911 | configurations = experiment.configuration_set.filter(type=0) |
|
886 | 912 | side_data['side_experiments'] = experiments |
|
887 | 913 | side_data['side_configurations'] = configurations |
|
888 | 914 | |
|
889 | 915 | return side_data |
|
890 | 916 | |
|
891 | 917 | |
|
892 | 918 | def operation(request, id_camp=None): |
|
893 | 919 | |
|
894 | 920 | if not id_camp: |
|
895 | 921 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
896 | 922 | |
|
897 | 923 | if not campaigns: |
|
898 | 924 | kwargs = {} |
|
899 | 925 | kwargs['title'] = 'No Campaigns' |
|
900 | 926 | kwargs['suptitle'] = 'Empty' |
|
901 | 927 | return render(request, 'operation.html', kwargs) |
|
902 | 928 | |
|
903 | 929 | id_camp = campaigns[0].id |
|
904 | 930 | |
|
905 | 931 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
906 | 932 | |
|
907 | 933 | if request.method=='GET': |
|
908 | 934 | form = OperationForm(initial={'campaign': campaign.id}, length = 5) |
|
909 | 935 | |
|
910 | 936 | if request.method=='POST': |
|
911 | 937 | form = OperationForm(request.POST, initial={'campaign':campaign.id}, length = 5) |
|
912 | 938 | |
|
913 | 939 | if form.is_valid(): |
|
914 | 940 | return redirect('url_operation', id_camp=campaign.id) |
|
915 | 941 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
916 | 942 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
917 | 943 | #for exs in experiments: |
|
918 | 944 | # exs.get_status() |
|
919 | 945 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
920 | 946 | #experiments = [Experiment.objects.filter(location__pk=location.id).filter(campaign__pk=campaign.id) for location in locations] |
|
921 | 947 | kwargs = {} |
|
922 | 948 | #---Campaign |
|
923 | 949 | kwargs['campaign'] = campaign |
|
924 | 950 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
925 | 951 | #---Experiment |
|
926 | 952 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
927 | 953 | kwargs['experiment_keys'] = keys[1:] |
|
928 | 954 | kwargs['experiments'] = experiments |
|
929 | 955 | #---Radar |
|
930 | 956 | kwargs['locations'] = locations |
|
931 | 957 | #---Else |
|
932 | 958 | kwargs['title'] = 'Campaign' |
|
933 | 959 | kwargs['suptitle'] = campaign.name |
|
934 | 960 | kwargs['form'] = form |
|
935 | 961 | kwargs['button'] = 'Search' |
|
936 | 962 | kwargs['details'] = True |
|
937 | 963 | kwargs['search_button'] = True |
|
938 | 964 | |
|
939 | 965 | return render(request, 'operation.html', kwargs) |
|
940 | 966 | |
|
941 | 967 | |
|
942 | 968 | def operation_search(request, id_camp=None): |
|
943 | 969 | |
|
944 | 970 | |
|
945 | 971 | if not id_camp: |
|
946 | 972 | campaigns = Campaign.objects.all().order_by('-start_date') |
|
947 | 973 | |
|
948 | 974 | if not campaigns: |
|
949 | 975 | return render(request, 'operation.html', {}) |
|
950 | 976 | |
|
951 | 977 | id_camp = campaigns[0].id |
|
952 | 978 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
953 | 979 | |
|
954 | 980 | if request.method=='GET': |
|
955 | 981 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
956 | 982 | |
|
957 | 983 | if request.method=='POST': |
|
958 | 984 | form = OperationSearchForm(request.POST, initial={'campaign':campaign.id}) |
|
959 | 985 | |
|
960 | 986 | if form.is_valid(): |
|
961 | 987 | return redirect('url_operation', id_camp=campaign.id) |
|
962 | 988 | |
|
963 | 989 | #locations = Location.objects.filter(experiment__campaign__pk = campaign.id).distinct() |
|
964 | 990 | experiments = Experiment.objects.filter(campaign__pk=campaign.id) |
|
965 | 991 | #for exs in experiments: |
|
966 | 992 | # exs.get_status() |
|
967 | 993 | locations= Location.objects.filter(experiment=experiments).distinct() |
|
968 | 994 | form = OperationSearchForm(initial={'campaign': campaign.id}) |
|
969 | 995 | |
|
970 | 996 | kwargs = {} |
|
971 | 997 | #---Campaign |
|
972 | 998 | kwargs['campaign'] = campaign |
|
973 | 999 | kwargs['campaign_keys'] = ['name', 'start_date', 'end_date', 'tags', 'description'] |
|
974 | 1000 | #---Experiment |
|
975 | 1001 | keys = ['id', 'name', 'start_time', 'end_time', 'status'] |
|
976 | 1002 | kwargs['experiment_keys'] = keys[1:] |
|
977 | 1003 | kwargs['experiments'] = experiments |
|
978 | 1004 | #---Radar |
|
979 | 1005 | kwargs['locations'] = locations |
|
980 | 1006 | #---Else |
|
981 | 1007 | kwargs['title'] = 'Campaign' |
|
982 | 1008 | kwargs['suptitle'] = campaign.name |
|
983 | 1009 | kwargs['form'] = form |
|
984 | 1010 | kwargs['button'] = 'Select' |
|
985 | 1011 | kwargs['details'] = True |
|
986 | 1012 | kwargs['search_button'] = False |
|
987 | 1013 | |
|
988 | 1014 | return render(request, 'operation.html', kwargs) |
|
989 | 1015 | |
|
990 | 1016 | |
|
991 | 1017 | def radar_play(request, id_camp, id_radar): |
|
992 | 1018 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
993 | 1019 | radar = get_object_or_404(Location, pk = id_radar) |
|
994 | 1020 | today = datetime.today() |
|
995 | 1021 | now = today.time() |
|
996 | 1022 | |
|
997 | 1023 | #--Clear Old Experiments From RunningExperiment Object |
|
998 | 1024 | running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
999 | 1025 | if running_experiment: |
|
1000 | 1026 | running_experiment = running_experiment[0] |
|
1001 | 1027 | running_experiment.running_experiment.clear() |
|
1002 | 1028 | running_experiment.save() |
|
1003 | 1029 | |
|
1004 | 1030 | #--If campaign datetime is ok: |
|
1005 | 1031 | if today >= campaign.start_date and today <= campaign.end_date: |
|
1006 | 1032 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1007 | 1033 | for exp in experiments: |
|
1008 | 1034 | #--If experiment time is ok: |
|
1009 | 1035 | if now >= exp.start_time and now <= exp.end_time: |
|
1010 | 1036 | configurations = Configuration.objects.filter(experiment = exp) |
|
1011 | 1037 | for conf in configurations: |
|
1012 | 1038 | if 'cgs' in conf.device.device_type.name: |
|
1013 | 1039 | conf.status_device() |
|
1014 | 1040 | else: |
|
1015 | 1041 | answer = conf.start_device() |
|
1016 | 1042 | conf.status_device() |
|
1017 | 1043 | #--Running Experiment |
|
1018 | 1044 | old_running_experiment = RunningExperiment.objects.filter(radar=radar) |
|
1019 | 1045 | #--If RunningExperiment element exists |
|
1020 | 1046 | if old_running_experiment: |
|
1021 | 1047 | old_running_experiment = old_running_experiment[0] |
|
1022 | 1048 | old_running_experiment.running_experiment.add(exp) |
|
1023 | 1049 | old_running_experiment.status = 3 |
|
1024 | 1050 | old_running_experiment.save() |
|
1025 | 1051 | #--Create a new Running_Experiment Object |
|
1026 | 1052 | else: |
|
1027 | 1053 | new_running_experiment = RunningExperiment( |
|
1028 | 1054 | radar = radar, |
|
1029 | 1055 | status = 3, |
|
1030 | 1056 | ) |
|
1031 | 1057 | new_running_experiment.save() |
|
1032 | 1058 | new_running_experiment.running_experiment.add(exp) |
|
1033 | 1059 | new_running_experiment.save() |
|
1034 | 1060 | |
|
1035 | 1061 | if answer: |
|
1036 | 1062 | messages.success(request, conf.message) |
|
1037 | 1063 | exp.status=2 |
|
1038 | 1064 | exp.save() |
|
1039 | 1065 | else: |
|
1040 | 1066 | messages.error(request, conf.message) |
|
1041 | 1067 | else: |
|
1042 | 1068 | if exp.status == 1 or exp.status == 3: |
|
1043 | 1069 | exp.status=3 |
|
1044 | 1070 | exp.save() |
|
1045 | 1071 | |
|
1046 | 1072 | |
|
1047 | 1073 | route = request.META['HTTP_REFERER'] |
|
1048 | 1074 | route = str(route) |
|
1049 | 1075 | if 'search' in route: |
|
1050 | 1076 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1051 | 1077 | else: |
|
1052 | 1078 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1053 | 1079 | |
|
1054 | 1080 | |
|
1055 | 1081 | def radar_stop(request, id_camp, id_radar): |
|
1056 | 1082 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1057 | 1083 | radar = get_object_or_404(Location, pk = id_radar) |
|
1058 | 1084 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1059 | 1085 | |
|
1060 | 1086 | for exp in experiments: |
|
1061 | 1087 | configurations = Configuration.objects.filter(experiment = exp) |
|
1062 | 1088 | for conf in configurations: |
|
1063 | 1089 | if 'cgs' in conf.device.device_type.name: |
|
1064 | 1090 | conf.status_device() |
|
1065 | 1091 | else: |
|
1066 | 1092 | answer = conf.stop_device() |
|
1067 | 1093 | conf.status_device() |
|
1068 | 1094 | |
|
1069 | 1095 | if answer: |
|
1070 | 1096 | messages.success(request, conf.message) |
|
1071 | 1097 | exp.status=1 |
|
1072 | 1098 | exp.save() |
|
1073 | 1099 | else: |
|
1074 | 1100 | messages.error(request, conf.message) |
|
1075 | 1101 | |
|
1076 | 1102 | |
|
1077 | 1103 | route = request.META['HTTP_REFERER'] |
|
1078 | 1104 | route = str(route) |
|
1079 | 1105 | if 'search' in route: |
|
1080 | 1106 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1081 | 1107 | else: |
|
1082 | 1108 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1083 | 1109 | |
|
1084 | 1110 | |
|
1085 | 1111 | def radar_refresh(request, id_camp, id_radar): |
|
1086 | 1112 | |
|
1087 | 1113 | campaign = get_object_or_404(Campaign, pk = id_camp) |
|
1088 | 1114 | radar = get_object_or_404(Location, pk = id_radar) |
|
1089 | 1115 | experiments = Experiment.objects.filter(campaign=campaign).filter(location=radar) |
|
1090 | 1116 | for exs in experiments: |
|
1091 | 1117 | exs.get_status() |
|
1092 | 1118 | |
|
1093 | 1119 | route = request.META['HTTP_REFERER'] |
|
1094 | 1120 | route = str(route) |
|
1095 | 1121 | if 'search' in route: |
|
1096 | 1122 | return HttpResponseRedirect(reverse('url_operation_search', args=[id_camp])) |
|
1097 | 1123 | else: |
|
1098 | 1124 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1099 | 1125 |
General Comments 0
You need to be logged in to leave comments.
Login now