|
18 | 18 | import gitlab |
19 | 19 | from gitlab import base |
20 | 20 | from gitlab import cli |
| 21 | +from gitlab import types as g_types |
21 | 22 | from gitlab import exceptions as exc |
22 | 23 |
|
23 | 24 |
|
@@ -171,21 +172,29 @@ def create(self, data, **kwargs): |
171 | 172 | GitlabCreateError: If the server cannot perform the request |
172 | 173 | """ |
173 | 174 | self._check_missing_create_attrs(data) |
| 175 | + files = {} |
174 | 176 |
|
175 | 177 | # We get the attributes that need some special transformation |
176 | 178 | types = getattr(self, '_types', {}) |
177 | | - |
178 | 179 | if types: |
179 | 180 | # Duplicate data to avoid messing with what the user sent us |
180 | 181 | data = data.copy() |
181 | 182 | for attr_name, type_cls in types.items(): |
182 | 183 | if attr_name in data.keys(): |
183 | 184 | type_obj = type_cls(data[attr_name]) |
184 | | - data[attr_name] = type_obj.get_for_api() |
| 185 | + |
| 186 | + # if the type if FileAttribute we need to pass the data as |
| 187 | + # file |
| 188 | + if issubclass(type_cls, g_types.FileAttribute): |
| 189 | + k = type_obj.get_file_name(attr_name) |
| 190 | + files[attr_name] = (k, data.pop(attr_name)) |
| 191 | + else: |
| 192 | + data[attr_name] = type_obj.get_for_api() |
185 | 193 |
|
186 | 194 | # Handle specific URL for creation |
187 | 195 | path = kwargs.pop('path', self.path) |
188 | | - server_data = self.gitlab.http_post(path, post_data=data, **kwargs) |
| 196 | + server_data = self.gitlab.http_post(path, post_data=data, files=files, |
| 197 | + **kwargs) |
189 | 198 | return self._obj_cls(self, server_data) |
190 | 199 |
|
191 | 200 |
|
@@ -232,15 +241,27 @@ def update(self, id=None, new_data={}, **kwargs): |
232 | 241 | path = '%s/%s' % (self.path, id) |
233 | 242 |
|
234 | 243 | self._check_missing_update_attrs(new_data) |
| 244 | + files = {} |
235 | 245 |
|
236 | 246 | # We get the attributes that need some special transformation |
237 | 247 | types = getattr(self, '_types', {}) |
238 | | - for attr_name, type_cls in types.items(): |
239 | | - if attr_name in new_data.keys(): |
240 | | - type_obj = type_cls(new_data[attr_name]) |
241 | | - new_data[attr_name] = type_obj.get_for_api() |
242 | | - |
243 | | - return self.gitlab.http_put(path, post_data=new_data, **kwargs) |
| 248 | + if types: |
| 249 | + # Duplicate data to avoid messing with what the user sent us |
| 250 | + new_data = new_data.copy() |
| 251 | + for attr_name, type_cls in types.items(): |
| 252 | + if attr_name in new_data.keys(): |
| 253 | + type_obj = type_cls(new_data[attr_name]) |
| 254 | + |
| 255 | + # if the type if FileAttribute we need to pass the data as |
| 256 | + # file |
| 257 | + if issubclass(type_cls, g_types.FileAttribute): |
| 258 | + k = type_obj.get_file_name(attr_name) |
| 259 | + files[attr_name] = (k, new_data.pop(attr_name)) |
| 260 | + else: |
| 261 | + new_data[attr_name] = type_obj.get_for_api() |
| 262 | + |
| 263 | + return self.gitlab.http_put(path, post_data=new_data, files=files, |
| 264 | + **kwargs) |
244 | 265 |
|
245 | 266 |
|
246 | 267 | class SetMixin(object): |
|
0 commit comments