Example #1
0
 def handle(self, request, data):
     try:
         filter_id = self.initial['id']
         # print "\n#################\n", request, "\n#################\n", data, "\n#################\n"
         response = api.fil_update_filter_metadata(request, filter_id, data)
         if 200 <= response.status_code < 300:
             messages.success(request, _('Filter successfully updated.'))
             return data
         else:
             raise sdsexception.SdsException(response.text)
     except Exception as ex:
         redirect = reverse("horizon:sdscontroller:administration:index")
         error_message = "Unable to update filter.\t %s" % ex.message
         exceptions.handle(request, _(error_message), redirect=redirect)
Example #2
0
    def update_cell(self, request, datum, id, cell_name, new_cell_value):
        try:
            # updating changed value by new value
            response = api.fil_get_filter_metadata(request, 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 'filter_name' in data:
                del data['filter_name']
            if 'etag' in data:  # PUT does not allow this key
                del data['etag']
            if 'content_length' in data:  # PUT does not allow this key
                del data['content_length']
            if 'path' in data:  # PUT does not allow this key
                del data['path']
            if 'filter_type' in data:  # PUT does not allow this key
                if data['filter_type'] == 'native' or data['filter_type'] == 'storlet':
                    if 'execution_order' in data:
                        del data['execution_order']
                    if 'enabled' in data:
                        del data['enabled']
                del data['filter_type']

            api.fil_update_filter_metadata(request, id, data)
        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