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
def handle(self, request, data): try: metric_module_id = self.initial['id'] # print "\n#################\n", request, "\n#################\n", data, "\n#################\n" response = api.mtr_update_metric_module(request, metric_module_id, data) if 200 <= response.status_code < 300: messages.success(request, _('Successfully metric module updated.')) return data else: raise sdsexception.SdsException(response.text) except Exception as ex: redirect = reverse("horizon:sdscontroller:administration:index") error_message = "Unable to update metric module.\t %s" % ex.message exceptions.handle(request, _(error_message), redirect=redirect)