From 7d210f98eba462d6ca02bc3d53a6afc31d455cd0 2019-03-06 19:10:23 From: Juan C. Espinoza Date: 2019-03-06 19:10:23 Subject: [PATCH] Check for active configuration for status update --- diff --git a/apps/abs/models.py b/apps/abs/models.py index f9d1a14..186d798 100644 --- a/apps/abs/models.py +++ b/apps/abs/models.py @@ -413,9 +413,7 @@ class ABSConfiguration(Configuration): self.device.status = 3 self.module_status = ''.join(status) self.save() - for u in User.objects.all(): - u.profile.abs_active = self - u.save() + return True diff --git a/apps/abs/views.py b/apps/abs/views.py index 87bb72e..89313c8 100644 --- a/apps/abs/views.py +++ b/apps/abs/views.py @@ -250,7 +250,7 @@ def send_beam(request, id_conf, id_beam): conf = get_object_or_404(ABSConfiguration, pk=id_conf) - abs = request.user.profile.abs_active + abs = Configuration.objects.filter(pk=conf.device.conf_active).first() if abs<>conf: url = '#' if abs is None else abs.get_absolute_url() label = 'None' if abs is None else abs.label diff --git a/apps/main/models.py b/apps/main/models.py index f13cbfd..142741e 100644 --- a/apps/main/models.py +++ b/apps/main/models.py @@ -75,10 +75,10 @@ DEV_TYPES = ( EXP_STATES = ( (0,'Error'), #RED - (1,'Configured'), #BLUE + (1,'Cancelled'), #YELLOW (2,'Running'), #GREEN - (3,'Scheduled'), #YELLOW - (4,'Not Configured'), #WHITE + (3,'Scheduled'), #BLUE + (4,'Unknown'), #WHITE ) CONF_TYPES = ( @@ -89,7 +89,6 @@ CONF_TYPES = ( class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) theme = models.CharField(max_length=30, default='spacelab') - abs_active = models.ForeignKey('Configuration', null=True, blank=True, verbose_name='Current ABS') @receiver(post_save, sender=User) @@ -137,6 +136,7 @@ class Device(models.Model): port_address = models.PositiveSmallIntegerField(default=2000) description = models.TextField(blank=True, null=True) status = models.PositiveSmallIntegerField(default=0, choices=DEV_STATES) + conf_active = models.PositiveIntegerField(default=0, verbose_name='Current configuration') class Meta: db_table = 'db_devices' @@ -423,7 +423,6 @@ class Experiment(models.Model): ABS-CGS-DDS-RC-JARS ''' - result = 2 confs = [] allconfs = Configuration.objects.filter(experiment=self, type = 0).order_by('-device__device_type__sequence') 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): confs.append(conf) else: confs = allconfs - #Only Configured Devices. - for conf in confs: - if conf.device.status in (0, 4): - result = 0 - return result - for conf in confs: - conf.stop_device() - conf.write_device() - conf.start_device() - time.sleep(1) - - return result + + try: + for conf in confs: + conf.stop_device() + conf.write_device() + conf.start_device() + time.sleep(0.1) + except: + return 0 + return 2 def stop(self): @@ -454,18 +451,14 @@ class Experiment(models.Model): DDS-JARS-RC-CGS-ABS ''' - result = 1 - confs = Configuration.objects.filter(experiment=self, type = 0).order_by('device__device_type__sequence') confs=confs.exclude(device__device_type__name='cgs') - for conf in confs: - if conf.device.status in (0, 4): - result = 0 - continue - conf.stop_device() - - return result - + try: + for conf in confs: + conf.stop_device() + except: + return 0 + return 1 def get_status(self): @@ -494,11 +487,11 @@ class Experiment(models.Model): if self.status == 0: color = "danger" elif self.status == 1: - color = "info" + color = "warning" elif self.status == 2: color = "success" elif self.status == 3: - color = "warning" + color = "info" return color diff --git a/apps/main/templates/dev_conf.html b/apps/main/templates/dev_conf.html index 9c20ff9..d8ce97d 100644 --- a/apps/main/templates/dev_conf.html +++ b/apps/main/templates/dev_conf.html @@ -36,9 +36,13 @@ {% block content-detail %} - - - + + {% if dev_conf.pk == dev_conf.device.conf_active %} + + {% else %} + + {% endif %} + {% for key in dev_conf_keys %} diff --git a/apps/main/templates/experiment.html b/apps/main/templates/experiment.html index 8078235..2d513cb 100644 --- a/apps/main/templates/experiment.html +++ b/apps/main/templates/experiment.html @@ -67,11 +67,11 @@ {%endif%}

{{item}}
{{item.device.ip_address}} - {%if experiment.status == 3 %} + {%if item.pk != item.device.conf_active %} Configured {%else%} {{item.device.get_status_display}} - {%endif%} + {%endif%}

diff --git a/apps/main/views.py b/apps/main/views.py index 4bce831..1af8a98 100644 --- a/apps/main/views.py +++ b/apps/main/views.py @@ -1452,19 +1452,19 @@ def dev_conf_status(request, id_conf): conf = get_object_or_404(Configuration, pk=id_conf) - if conf.device.device_type.name == 'abs': - abs = request.user.profile.abs_active - if abs<>conf: - url = '#' if abs is None else abs.get_absolute_url() - label = 'None' if abs is None else abs.label - messages.warning( - request, - mark_safe('The current configuration has not been written in the modules, the active configuration is {}'.format( - url, - label - )) - ) - return redirect(conf.get_absolute_url()) + conf_active = Configuration.objects.filter(pk=conf.device.conf_active).first() + if conf_active<>conf: + url = '#' if conf_active is None else conf_active.get_absolute_url() + label = 'None' if conf_active is None else conf_active.label + messages.warning( + request, + mark_safe('The current configuration has not been written to device, the active configuration is {}'.format( + url, + label + )) + ) + + return redirect(conf.get_absolute_url()) if conf.status_device(): messages.success(request, conf.message) @@ -1493,6 +1493,8 @@ def dev_conf_write(request, id_conf): conf = get_object_or_404(Configuration, pk=id_conf) if conf.write_device(): + conf.device.conf_active = conf.pk + conf.device.save() messages.success(request, conf.message) if has_been_modified(conf): conf.clone(type=1, template=False) @@ -1841,9 +1843,20 @@ def radar_refresh(request, id_camp, id_radar): campaign = get_object_or_404(Campaign, pk=id_camp) experiments = campaign.get_experiments_by_radar(id_radar)[0]['experiments'] - for exp in experiments: - exp.get_status() + i = app.control.inspect() + scheduled = i.scheduled().values[0] + revoked = i.revoked().values[0] + for exp in experiments: + if exp.task in revoked: + exp.status = 1 + elif exp.task in [t['request']['id'] for t in scheduled if 'task_start' in t['request']['name']]: + exp.status = 2 + elif exp.task in [t['request']['id'] for t in scheduled if 'task_stop' in t['request']['name']]: + exp.status = 3 + else: + exp.status = 4 + exp.save() return HttpResponseRedirect(reverse('url_operation', args=[id_camp]))
Status {% if dev_conf.device.device_type.name == 'abs' %} {{connected_modules}} {% else %} {{dev_conf.device.get_status_display}}{% endif %}
Status {% if dev_conf.device.device_type.name == 'abs' %} {{connected_modules}} {% else %} {{dev_conf.device.get_status_display}}{% endif %} Connected