summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain@pocentek.net>2016-05-12 17:33:45 +0200
committerGauvain Pocentek <gauvain@pocentek.net>2016-05-12 17:42:40 +0200
commit0a1bb94b58bfcf837f846be7bd4d4075ab16eea6 (patch)
tree227c15d46c99cbbe5aa3335ee420d8442b1c247c
parentc3f5b3ac14c1767a5b65e7771496990f5ce6b9f0 (diff)
downloadgitlab-0a1bb94b58bfcf837f846be7bd4d4075ab16eea6.tar.gz
Rework the Gitlab.delete method
Fixes #107
-rw-r--r--gitlab/__init__.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 5009e13..bdee4aa 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -471,16 +471,18 @@ class Gitlab(object):
if inspect.isclass(obj):
if not issubclass(obj, GitlabObject):
raise GitlabError("Invalid class: %s" % obj)
- params = {}
- params[obj.idAttr] = id
- else:
- params = obj.__dict__.copy()
+
+ params = {obj.idAttr: id if id else getattr(obj, obj.idAttr)}
params.update(kwargs)
+
missing = []
for k in itertools.chain(obj.requiredUrlAttrs,
obj.requiredDeleteAttrs):
if k not in params:
- missing.append(k)
+ try:
+ params[k] = getattr(obj, k)
+ except KeyError:
+ missing.append(k)
if missing:
raise GitlabDeleteError('Missing attribute(s): %s' %
", ".join(missing))
@@ -493,6 +495,10 @@ class Gitlab(object):
# url-parameters left
for attribute in obj.requiredUrlAttrs:
del params[attribute]
+ if obj._id_in_delete_url:
+ # The ID is already built, no need to add it as extra key in query
+ # string
+ params.pop(obj.idAttr)
try:
r = self.session.delete(url,