def update_cell(self, request, datum, policy_id, cell_name, new_cell_value): try: # Updating changed value by new value # response = api.dsl_get_static_policy(request, policy_id) # data = json.loads(response.text) # data[cell_name] = new_cell_value api.dsl_update_static_policy(request, policy_id, {cell_name: new_cell_value}) except Conflict: # Returning a nice error message about name conflict. The message # from exception is not that clear for the user message = _("Can't change value") raise ValidationError(message) except Exception: exceptions.handle(request, ignore=True) return False return True
def handle(self, request, data): try: policy_id = self.initial['target_id'] + ':' + self.initial['id'] response = api.dsl_update_static_policy(request, policy_id, data) if 200 <= response.status_code < 300: messages.success(request, _('Policy successfully updated.')) return data else: raise sdsexception.SdsException(response.text) except Exception as ex: redirect = reverse("horizon:sdscontroller:storagepolicies:index") error_message = "Unable to update policy.\t %s" % ex.message exceptions.handle(request, _(error_message), redirect=redirect)