diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2017-05-28 22:10:27 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2017-06-02 15:42:32 +0200 |
commit | f418767ec94c430aabd132d189d1c5e9e2370e68 (patch) | |
tree | a015a30cf17ae755f35a6d1618b2d2a1cccb4472 /gitlab/base.py | |
parent | 0467f779eb1d2649f3626e3817531511d3397038 (diff) | |
download | gitlab-f418767ec94c430aabd132d189d1c5e9e2370e68.tar.gz |
Migrate all v4 objects to new API
Some things are probably broken. Next step is writting unit and
functional tests.
And fix.
Diffstat (limited to 'gitlab/base.py')
-rw-r--r-- | gitlab/base.py | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/gitlab/base.py b/gitlab/base.py index afbcd38..8949554 100644 --- a/gitlab/base.py +++ b/gitlab/base.py @@ -533,31 +533,6 @@ class GitlabObject(object): return not self.__eq__(other) -class SaveMixin(object): - """Mixin for RESTObject's that can be updated.""" - def save(self, **kwargs): - """Saves the changes made to the object to the server. - - Args: - **kwargs: Extra option to send to the server (e.g. sudo) - - The object is updated to match what the server returns. - """ - updated_data = {} - required, optional = self.manager.get_update_attrs() - for attr in required: - # Get everything required, no matter if it's been updated - updated_data[attr] = getattr(self, attr) - # Add the updated attributes - updated_data.update(self._updated_attrs) - - # class the manager - obj_id = self.get_id() - server_data = self.manager.update(obj_id, updated_data, **kwargs) - self._updated_attrs = {} - self._attrs.update(server_data) - - class RESTObject(object): """Represents an object built from server data. @@ -618,6 +593,10 @@ class RESTObject(object): manager = cls(self.manager.gitlab, parent=self) self.__dict__[attr] = manager + def _update_attrs(self, new_attrs): + self._updated_attrs = {} + self._attrs.update(new_attrs) + def get_id(self): if self._id_attr is None: return None @@ -674,13 +653,15 @@ class RESTManager(object): self._parent = parent # for nested managers self._computed_path = self._compute_path() - def _compute_path(self): + def _compute_path(self, path=None): + if path is None: + path = self._path if self._parent is None or not hasattr(self, '_from_parent_attrs'): - return self._path + return path data = {self_attr: getattr(self._parent, parent_attr) for self_attr, parent_attr in self._from_parent_attrs.items()} - return self._path % data + return path % data @property def path(self): |