Example #1
0
 def _get_object(self, *args, **kwargs):
     metric_module_id = self.kwargs['metric_module_id']
     try:
         metric_module = api.mtr_get_metric_module(self.request, metric_module_id)
         return metric_module
     except Exception:
         redirect = self.success_url
         msg = _('Unable to retrieve metric modules details.')
         exceptions.handle(self.request, msg, redirect=redirect)
Example #2
0
    def update_cell(self, request, datum, metric_module_id, cell_name, new_cell_value):
        try:
            # updating changed value by new value
            response = api.mtr_get_metric_module(request, metric_module_id)
            data = json.loads(response.text)
            data[cell_name] = new_cell_value

            # TODO: Check only the valid keys, delete the rest
            if 'id' in data:  # PUT does not allow this key
                del data['id']
            if 'path' in data:  # PUT does not allow this key
                del data['path']

            api.mtr_update_metric_module(request, metric_module_id, data)
        except Conflict:
            # Returning a nice error message about name conflict. The message
            # from exception is not that clear for the user
            message = _("Cant change value")
            raise ValidationError(message)
        except Exception:
            exceptions.handle(request, ignore=True)
            return False
        return True
Example #3
0
 def get_data(self, request, metric_module_id):
     response = api.mtr_get_metric_module(request, metric_module_id)
     data = json.loads(response.text)
     filter = MetricModule(data['id'], data['metric_name'], data['class_name'], data['out_flow'],
                           data['in_flow'], data['execution_server'], data['enabled'])
     return filter