Skip to content

Commit

Permalink
added kwargs in parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochem Berends committed Sep 1, 2017
1 parent 59d4631 commit 00418a4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pykechain/models/part.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,16 @@ def delete(self):
if r.status_code != requests.codes.no_content: # pragma: no cover
raise APIError("Could not delete part: {} with id {}".format(self.name, self.id))

def edit(self, name=None, description=None):
def edit(self, name=None, description=None, **kwargs):
# type: (AnyStr, AnyStr) -> None
"""
Edit the details of a part (model or instance).
For an instance you can edit the Part instance name and the part instance description
:param name: optional name of the part to edit
:param description: optional description of the part
:param description: (optional) description of the part
:param kwargs: (optional)
:return: None
:raises: APIError
Expand All @@ -361,6 +362,8 @@ def edit(self, name=None, description=None):
if description:
assert isinstance(description, str), "description should be provided as a string"
update_dict.update({'description': description})
if kwargs:
update_dict.update(**kwargs)
r = self._client._request('PUT', self._client._build_url('part', part_id=self.id), json=update_dict)

if r.status_code != requests.codes.ok: # pragma: no cover
Expand Down Expand Up @@ -393,7 +396,7 @@ def _repr_html_(self):

return ''.join(html)

def update(self, name=None, update_dict=None, bulk=True):
def update(self, name=None, update_dict=None, bulk=True, **kwargs):
"""
Edit part name and property values in one go.
Expand Down Expand Up @@ -423,15 +426,15 @@ def update(self, name=None, update_dict=None, bulk=True):
if name:
assert isinstance(name, str), "Name of the part should be provided as a string"
r = self._client._request('PUT', self._client._build_url('part', part_id=self.id),
data=dict(name=name, properties=json.dumps(request_body)),
data=dict(name=name, properties=json.dumps(request_body), **kwargs),
params=dict(select_action=action))
if r.status_code != requests.codes.ok: # pragma: no cover
raise APIError('{}: {}'.format(str(r), r.content))
else:
for property_name, property_value in update_dict.items():
self.property(property_name).value = property_value

def add_with_properties(self, model, name=None, update_dict=None, bulk=True):
def add_with_properties(self, model, name=None, update_dict=None, bulk=True, **kwargs):
"""
Add a part and update its properties in one go.
Expand Down Expand Up @@ -463,7 +466,8 @@ def add_with_properties(self, model, name=None, update_dict=None, bulk=True):
name=name,
model=model.id,
parent=self.id,
properties=json.dumps(properties_update_dict)
properties=json.dumps(properties_update_dict),
**kwargs
),
params=dict(select_action=action))

Expand Down

0 comments on commit 00418a4

Please sign in to comment.