@@ -413,9 +413,7 class ABSConfiguration(Configuration): | |||||
413 | self.device.status = 3 |
|
413 | self.device.status = 3 | |
414 | self.module_status = ''.join(status) |
|
414 | self.module_status = ''.join(status) | |
415 | self.save() |
|
415 | self.save() | |
416 | for u in User.objects.all(): |
|
416 | ||
417 | u.profile.abs_active = self |
|
|||
418 | u.save() |
|
|||
419 | return True |
|
417 | return True | |
420 |
|
418 | |||
421 |
|
419 |
@@ -250,7 +250,7 def send_beam(request, id_conf, id_beam): | |||||
250 |
|
250 | |||
251 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) |
|
251 | conf = get_object_or_404(ABSConfiguration, pk=id_conf) | |
252 |
|
252 | |||
253 | abs = request.user.profile.abs_active |
|
253 | abs = Configuration.objects.filter(pk=conf.device.conf_active).first() | |
254 | if abs<>conf: |
|
254 | if abs<>conf: | |
255 | url = '#' if abs is None else abs.get_absolute_url() |
|
255 | url = '#' if abs is None else abs.get_absolute_url() | |
256 | label = 'None' if abs is None else abs.label |
|
256 | label = 'None' if abs is None else abs.label |
@@ -75,10 +75,10 DEV_TYPES = ( | |||||
75 |
|
75 | |||
76 | EXP_STATES = ( |
|
76 | EXP_STATES = ( | |
77 | (0,'Error'), #RED |
|
77 | (0,'Error'), #RED | |
78 |
(1,'C |
|
78 | (1,'Cancelled'), #YELLOW | |
79 | (2,'Running'), #GREEN |
|
79 | (2,'Running'), #GREEN | |
80 |
(3,'Scheduled'), # |
|
80 | (3,'Scheduled'), #BLUE | |
81 |
(4,' |
|
81 | (4,'Unknown'), #WHITE | |
82 | ) |
|
82 | ) | |
83 |
|
83 | |||
84 | CONF_TYPES = ( |
|
84 | CONF_TYPES = ( | |
@@ -89,7 +89,6 CONF_TYPES = ( | |||||
89 | class Profile(models.Model): |
|
89 | class Profile(models.Model): | |
90 | user = models.OneToOneField(User, on_delete=models.CASCADE) |
|
90 | user = models.OneToOneField(User, on_delete=models.CASCADE) | |
91 | theme = models.CharField(max_length=30, default='spacelab') |
|
91 | theme = models.CharField(max_length=30, default='spacelab') | |
92 | abs_active = models.ForeignKey('Configuration', null=True, blank=True, verbose_name='Current ABS') |
|
|||
93 |
|
92 | |||
94 |
|
93 | |||
95 | @receiver(post_save, sender=User) |
|
94 | @receiver(post_save, sender=User) | |
@@ -137,6 +136,7 class Device(models.Model): | |||||
137 | port_address = models.PositiveSmallIntegerField(default=2000) |
|
136 | port_address = models.PositiveSmallIntegerField(default=2000) | |
138 | description = models.TextField(blank=True, null=True) |
|
137 | description = models.TextField(blank=True, null=True) | |
139 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) |
|
138 | status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) | |
|
139 | conf_active = models.PositiveIntegerField(default=0, verbose_name='Current configuration') | |||
140 |
|
140 | |||
141 | class Meta: |
|
141 | class Meta: | |
142 | db_table = 'db_devices' |
|
142 | db_table = 'db_devices' | |
@@ -423,7 +423,6 class Experiment(models.Model): | |||||
423 | ABS-CGS-DDS-RC-JARS |
|
423 | ABS-CGS-DDS-RC-JARS | |
424 | ''' |
|
424 | ''' | |
425 |
|
425 | |||
426 | result = 2 |
|
|||
427 | confs = [] |
|
426 | confs = [] | |
428 | allconfs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') |
|
427 | allconfs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') | |
429 | rc_mix = [conf for conf in allconfs if conf.device.device_type.name=='rc' and conf.mix] |
|
428 | rc_mix = [conf for conf in allconfs if conf.device.device_type.name=='rc' and conf.mix] | |
@@ -434,18 +433,16 class Experiment(models.Model): | |||||
434 | confs.append(conf) |
|
433 | confs.append(conf) | |
435 | else: |
|
434 | else: | |
436 | confs = allconfs |
|
435 | confs = allconfs | |
437 | #Only Configured Devices. |
|
436 | ||
438 | for conf in confs: |
|
437 | try: | |
439 |
|
|
438 | for conf in confs: | |
440 | result = 0 |
|
439 | conf.stop_device() | |
441 | return result |
|
440 | conf.write_device() | |
442 | for conf in confs: |
|
441 | conf.start_device() | |
443 | conf.stop_device() |
|
442 | time.sleep(0.1) | |
444 | conf.write_device() |
|
443 | except: | |
445 | conf.start_device() |
|
444 | return 0 | |
446 | time.sleep(1) |
|
445 | return 2 | |
447 |
|
||||
448 | return result |
|
|||
449 |
|
446 | |||
450 |
|
447 | |||
451 | def stop(self): |
|
448 | def stop(self): | |
@@ -454,18 +451,14 class Experiment(models.Model): | |||||
454 | DDS-JARS-RC-CGS-ABS |
|
451 | DDS-JARS-RC-CGS-ABS | |
455 | ''' |
|
452 | ''' | |
456 |
|
453 | |||
457 | result = 1 |
|
|||
458 |
|
||||
459 | confs = Configuration.objects.filter(experiment=self, type = 0).order_by('device__device_type__sequence') |
|
454 | confs = Configuration.objects.filter(experiment=self, type = 0).order_by('device__device_type__sequence') | |
460 | confs=confs.exclude(device__device_type__name='cgs') |
|
455 | confs=confs.exclude(device__device_type__name='cgs') | |
461 | for conf in confs: |
|
456 | try: | |
462 |
|
|
457 | for conf in confs: | |
463 | result = 0 |
|
458 | conf.stop_device() | |
464 | continue |
|
459 | except: | |
465 | conf.stop_device() |
|
460 | return 0 | |
466 |
|
461 | return 1 | ||
467 | return result |
|
|||
468 |
|
||||
469 |
|
462 | |||
470 | def get_status(self): |
|
463 | def get_status(self): | |
471 |
|
464 | |||
@@ -494,11 +487,11 class Experiment(models.Model): | |||||
494 | if self.status == 0: |
|
487 | if self.status == 0: | |
495 | color = "danger" |
|
488 | color = "danger" | |
496 | elif self.status == 1: |
|
489 | elif self.status == 1: | |
497 |
color = " |
|
490 | color = "warning" | |
498 | elif self.status == 2: |
|
491 | elif self.status == 2: | |
499 | color = "success" |
|
492 | color = "success" | |
500 | elif self.status == 3: |
|
493 | elif self.status == 3: | |
501 |
color = " |
|
494 | color = "info" | |
502 |
|
495 | |||
503 | return color |
|
496 | return color | |
504 |
|
497 |
@@ -36,9 +36,13 | |||||
36 | {% block content-detail %} |
|
36 | {% block content-detail %} | |
37 | <table class="table table-bordered"> |
|
37 | <table class="table table-bordered"> | |
38 | <tr> |
|
38 | <tr> | |
39 |
|
|
39 | <th>Status</th> | |
40 | <td class="text-{{dev_conf.device.status_color}}"><strong> {% if dev_conf.device.device_type.name == 'abs' %} {{connected_modules}} {% else %} {{dev_conf.device.get_status_display}}{% endif %}</strong></td> |
|
40 | {% if dev_conf.pk == dev_conf.device.conf_active %} | |
41 | </tr> |
|
41 | <td class="text-{{dev_conf.device.status_color}}"><strong> {% if dev_conf.device.device_type.name == 'abs' %} {{connected_modules}} {% else %} {{dev_conf.device.get_status_display}}{% endif %}</strong></td> | |
|
42 | {% else %} | |||
|
43 | <td class="text-info"><strong> Connected </strong></td> | |||
|
44 | {% endif %} | |||
|
45 | </tr> | |||
42 |
|
46 | |||
43 | {% for key in dev_conf_keys %} |
|
47 | {% for key in dev_conf_keys %} | |
44 | <tr> |
|
48 | <tr> |
@@ -67,11 +67,11 | |||||
67 | <i class="fa fa-3x fa-puzzle-piece"></i> |
|
67 | <i class="fa fa-3x fa-puzzle-piece"></i> | |
68 | {%endif%} |
|
68 | {%endif%} | |
69 | <h4>{{item}}<br><small>{{item.device.ip_address}}</small> |
|
69 | <h4>{{item}}<br><small>{{item.device.ip_address}}</small> | |
70 | {%if experiment.status == 3 %} |
|
70 | {%if item.pk != item.device.conf_active %} | |
71 | <span class="label label-info">Configured</span> |
|
71 | <span class="label label-info">Configured</span> | |
72 | {%else%} |
|
72 | {%else%} | |
73 | <span class="label label-{{item.device.status_color}}">{{item.device.get_status_display}}</span> |
|
73 | <span class="label label-{{item.device.status_color}}">{{item.device.get_status_display}}</span> | |
74 |
|
|
74 | {%endif%} | |
75 | </h4> |
|
75 | </h4> | |
76 | </a> |
|
76 | </a> | |
77 | </div> |
|
77 | </div> |
@@ -1452,19 +1452,19 def dev_conf_status(request, id_conf): | |||||
1452 |
|
1452 | |||
1453 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1453 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1454 |
|
1454 | |||
1455 | if conf.device.device_type.name == 'abs': |
|
1455 | conf_active = Configuration.objects.filter(pk=conf.device.conf_active).first() | |
1456 | abs = request.user.profile.abs_active |
|
1456 | if conf_active<>conf: | |
1457 | if abs<>conf: |
|
1457 | url = '#' if conf_active is None else conf_active.get_absolute_url() | |
1458 | url = '#' if abs is None else abs.get_absolute_url() |
|
1458 | label = 'None' if conf_active is None else conf_active.label | |
1459 | label = 'None' if abs is None else abs.label |
|
1459 | messages.warning( | |
1460 | messages.warning( |
|
1460 | request, | |
1461 | request, |
|
1461 | mark_safe('The current configuration has not been written to device, the active configuration is <a href="{}">{}</a>'.format( | |
1462 | mark_safe('The current configuration has not been written in the modules, the active configuration is <a href="{}">{}</a>'.format( |
|
1462 | url, | |
1463 |
|
|
1463 | label | |
1464 |
|
|
1464 | )) | |
1465 |
|
|
1465 | ) | |
1466 |
|
|
1466 | ||
1467 |
|
|
1467 | return redirect(conf.get_absolute_url()) | |
1468 |
|
1468 | |||
1469 | if conf.status_device(): |
|
1469 | if conf.status_device(): | |
1470 | messages.success(request, conf.message) |
|
1470 | messages.success(request, conf.message) | |
@@ -1493,6 +1493,8 def dev_conf_write(request, id_conf): | |||||
1493 | conf = get_object_or_404(Configuration, pk=id_conf) |
|
1493 | conf = get_object_or_404(Configuration, pk=id_conf) | |
1494 |
|
1494 | |||
1495 | if conf.write_device(): |
|
1495 | if conf.write_device(): | |
|
1496 | conf.device.conf_active = conf.pk | |||
|
1497 | conf.device.save() | |||
1496 | messages.success(request, conf.message) |
|
1498 | messages.success(request, conf.message) | |
1497 | if has_been_modified(conf): |
|
1499 | if has_been_modified(conf): | |
1498 | conf.clone(type=1, template=False) |
|
1500 | conf.clone(type=1, template=False) | |
@@ -1841,9 +1843,20 def radar_refresh(request, id_camp, id_radar): | |||||
1841 | campaign = get_object_or_404(Campaign, pk=id_camp) |
|
1843 | campaign = get_object_or_404(Campaign, pk=id_camp) | |
1842 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] |
|
1844 | experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] | |
1843 |
|
1845 | |||
1844 | for exp in experiments: |
|
1846 | i = app.control.inspect() | |
1845 | exp.get_status() |
|
1847 | scheduled = i.scheduled().values[0] | |
|
1848 | revoked = i.revoked().values[0] | |||
1846 |
|
1849 | |||
|
1850 | for exp in experiments: | |||
|
1851 | if exp.task in revoked: | |||
|
1852 | exp.status = 1 | |||
|
1853 | elif exp.task in [t['request']['id'] for t in scheduled if 'task_start' in t['request']['name']]: | |||
|
1854 | exp.status = 2 | |||
|
1855 | elif exp.task in [t['request']['id'] for t in scheduled if 'task_stop' in t['request']['name']]: | |||
|
1856 | exp.status = 3 | |||
|
1857 | else: | |||
|
1858 | exp.status = 4 | |||
|
1859 | exp.save() | |||
1847 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) |
|
1860 | return HttpResponseRedirect(reverse('url_operation', args=[id_camp])) | |
1848 |
|
1861 | |||
1849 |
|
1862 |
General Comments 0
You need to be logged in to leave comments.
Login now