def save(self, inplace=True, silent=False): """ Saves all modification to the file on the server. By default this method raises an error if you are trying to save an instance that was not changed. Set check_if_modified param to False to disable this behaviour. :param inplace: Apply edits to the current instance or get a new one. :param silent: If Raises exception if file wasn't modified. :raise ResourceNotModified :return: File instance. """ modified_data = self._modified_data() if silent or bool(modified_data): # If metadata is to be set if 'metadata' in modified_data: if hasattr(self, '_method'): self._api.put(url=self._URL['metadata'].format(id=self.id), data=modified_data['metadata']) else: self._api.patch( url=self._URL['metadata'].format(id=self.id), data=modified_data['metadata']) modified_data.pop('metadata') if 'tags' in modified_data: self._api.put(url=self._URL['tags'].format(id=self.id), data=modified_data['tags']) modified_data.pop('tags') # Change everything else if bool(modified_data): self._api.patch(url=self._URL['get'].format(id=self.id), data=modified_data) else: raise ResourceNotModified() return self.reload()
def save(self, inplace=True): """ Saves modification to the api server. """ data = self._modified_data() data = data['permissions'] if bool(data): url = six.text_type(self.href) + self._URL['permissions'] self._api.patch(url=url, data=data, append_base=False) else: raise ResourceNotModified()
def save(self, inplace=True): """ Saves all modification to the volume on the server. """ modified_data = self._modified_data() if bool(modified_data): data = self._api.patch(url=self._URL['get'].format(id=self.id), data=modified_data).json() volume = Volume(api=self._api, **data) return volume else: raise ResourceNotModified()
def save(self, inplace=True): """ Saves modification to the api server. """ modified = self._modified_data() if modified: new_data = self.permissions.copy() new_data.update(modified['permissions']) data = {'permissions': new_data} url = self.href self._api.patch(url=url, data=data, append_base=False) else: raise ResourceNotModified()
def save(self, inplace=True): """ Saves modification to the api server. """ data = self._modified_data() data = data['permissions'] if bool(data): url = six.text_type(self.href) + self._URL['permissions'] extra = {'resource': self.__class__.__name__, 'query': data} logger.info('Modifying permissions', extra=extra) self._api.patch(url=url, data=data, append_base=False) else: raise ResourceNotModified()
def save(self, inplace=True): """ Saves all modification to the project on the server. :param inplace Apply edits on the current instance or get a new one. :return: Project instance. """ if bool(self._modified_data()): data = self._api.patch(url=self._URL['get'].format(id=self.id), data=self._modified_data()).json() project = Project(api=self._api, **data) return project else: raise ResourceNotModified()
def save(self, inplace=True, silent=False): """ Saves all modification to the file on the server. By default this method raises an error if you are trying to save an instance that was not changed. Set check_if_modified param to False to disable this behaviour. :param inplace: Apply edits to the current instance or get a new one. :param silent: If Raises exception if file wasn't modified. :raise ResourceNotModified :return: File instance. """ reload = False modified_data = self._modified_data() if not (silent or modified_data): raise ResourceNotModified() # Update metadata if 'metadata' in modified_data: if hasattr(self, '_overwrite_metadata'): self.metadata = self._api.put( url=self._URL['metadata'].format(id=self.id), data=modified_data['metadata']).json() delattr(self, '_overwrite_metadata') else: self.metadata = self._api.patch( url=self._URL['metadata'].format(id=self.id), data=modified_data['metadata']).json() reload = True modified_data.pop('metadata') # Update tags if 'tags' in modified_data: self.tags = self._api.put(url=self._URL['tags'].format(id=self.id), data=modified_data['tags']).json() reload = True modified_data.pop('tags') # Update everything else if modified_data: data = self._api.patch(url=self._URL['get'].format(id=self.id), data=modified_data).json() self._update_read_only(data) return self if not reload else self.reload()
def save(self, inplace=True): """ Saves all modification to the volume on the server. """ modified_data = self._modified_data() if modified_data: extra = { 'resource': type(self).__name__, 'query': { 'id': self.id, 'modified_data': modified_data } } logger.info('Saving volume', extra=extra) data = self._api.patch(url=self._URL['get'].format(id=self.id), data=modified_data).json() volume = Volume(api=self._api, **data) return volume else: raise ResourceNotModified()
def save(self, inplace=True): """ Saves all modification to the file on the server. :param inplace Apply edits to the current instance or get a new one. :return: File instance. """ modified_data = self._modified_data() if bool(modified_data): if 'metadata' in modified_data: self._api.patch(url=self._URL['metadata'].format(id=self.id), data=modified_data['metadata']) return self.get(id=self.id, api=self._api) else: data = self._api.patch(url=self._URL['get'].format(id=self.id), data=modified_data).json() file = File(api=self._api, **data) return file else: raise ResourceNotModified()
def save(self, inplace=True): """ Saves all modification to the automation run on the server. :param inplace Apply edits on the current instance or get a new one. :return: Automation run instance. """ modified_data = self._modified_data() if modified_data: extra = { 'resource': type(self).__name__, 'query': { 'id': self.id, 'modified_data': modified_data } } logger.info('Saving automation run', extra=extra) data = self._api.patch(url=self._URL['get'].format(id=self.id), data=modified_data).json() return AutomationRun(api=self._api, **data) else: raise ResourceNotModified()
def save(self, inplace=True): """ Saves all modification to the project on the server. :param inplace Apply edits on the current instance or get a new one. :return: Project instance. """ modified_data = self._modified_data() if bool(modified_data): extra = { 'resource': self.__class__.__name__, 'query': { 'id': self.id, 'modified_data': modified_data } } logger.info('Saving project', extra=extra) data = self._api.patch(url=self._URL['get'].format(id=self.id), data=modified_data).json() project = Project(api=self._api, **data) return project else: raise ResourceNotModified()
def save(self, inplace=True): """ Saves all modification to the file on the server. :param inplace Apply edits to the current instance or get a new one. :return: File instance. """ modified_data = self._modified_data() if bool(modified_data): # If metadata is to be set if 'metadata' in modified_data: try: _ = self._method self._api.put( url=self._URL['metadata'].format(id=self.id), data=modified_data['metadata'] ) except AttributeError: self._api.patch( url=self._URL['metadata'].format(id=self.id), data=modified_data['metadata'] ) modified_data.pop('metadata') if 'tags' in modified_data: self._api.put( url=self._URL['tags'].format(id=self.id), data=modified_data['tags'] ) modified_data.pop('tags') # Change everything else if bool(modified_data): self._api.patch( url=self._URL['get'].format(id=self.id), data=modified_data ) else: raise ResourceNotModified() return self.reload()